Complete dashboard refresh and repository checks
4 files changed,
+75
−67
internal/sheets/app.go+0 −17internal/sheets/grants.go+1 −50internal/sheets/session_guard.go+21 −0internal/sheets/visible_sheets.go+53 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/sheets/app.go b/internal/sheets/app.go| index 360a426..1d9e21a 100644 |
| --- a/internal/sheets/app.go |
| +++ b/internal/sheets/app.go |
| @@ -283,20 +283,3 @@ func (a *App) Router() http.Handler { |
| return r |
| } |
| -// requireSession is auth.RequireSession in production and a |
| -// pass-through when there is no auth to require one with. |
| -// |
| -// The pass-through is for tests only, and it is deliberate rather than |
| -// accidental: a nil-auth App has no sessions at all, so requiring one |
| -// would make every route below untestable without a mailer, an SMTP |
| -// refusal and a full magic-link round trip. Production cannot reach it |
| -// — main exits before New if sign-in is not configured. |
| -func (a *App) requireSession(next http.Handler) http.Handler { |
| - if a.home != nil { |
| - return a.homeRequire(next) |
| - } |
| - if a.auth == nil { |
| - return next |
| - } |
| - return a.auth.RequireSession(a.rejectDisabledHome(next)) |
| -} |
diff --git a/internal/sheets/grants.go b/internal/sheets/grants.go| index 8931a9b..abbb4e1 100644 |
| --- a/internal/sheets/grants.go |
| +++ b/internal/sheets/grants.go |
| @@ -1,14 +1,12 @@ |
| package sheets |
| import ( |
| - "context" |
| + "amadan.net/oficina/sheets/internal/sheets/store" |
| "errors" |
| "strings" |
| "gorm.io/gorm" |
| "gorm.io/gorm/clause" |
| - |
| - "amadan.net/oficina/sheets/internal/sheets/store" |
| ) |
| // errNoAccess is what every read answers when the viewer may not see a |
| @@ -107,53 +105,6 @@ func (a *App) sheetExists(id uint64) bool { |
| return n == 1 |
| } |
| -// visibleSheets returns the sheets a member may see. |
| -// |
| -// This is the hand-written grants join AGENTS.md requires, and the |
| -// reason it is hand-written rather than scope.Owned: scope.Owned is |
| -// single-column equality on user_id, our sheets are team-shared, and |
| -// applied here it would return only the sheets a person created — which |
| -// fails as a plausible short list rather than as an error. |
| -// |
| -// The query is deliberately one statement rather than "list all, then |
| -// filter in Go". A filter in Go reads every sheet on the instance into |
| -// memory before discarding most of them, which is both wasteful and the |
| -// shape where somebody later forgets the discard. |
| -func (a *App) visibleSheets(m Member) ([]store.Sheet, error) { |
| - return a.visibleSheetsLimited(context.Background(), m, 0) |
| -} |
| -func (a *App) visibleSheetsLimited(ctx context.Context, m Member, limit int) ([]store.Sheet, error) { |
| - if a.db == nil { |
| - return nil, errNoDB |
| - } |
| - // filling_since alongside deleted_at, everywhere the other is |
| - // checked: a sheet still being filled from an imported file is not |
| - // a thing anybody should see yet, and on this instance every team |
| - // member sees every sheet, so "not visible" has to mean not in this |
| - // query rather than not linked to. |
| - q := a.db.WithContext(ctx).Model(&store.Sheet{}). |
| - Where("sheets.deleted_at IS NULL AND sheets.filling_since IS NULL") |
| - |
| - switch TeamRole(m.TeamRole) { |
| - case TeamOwner, TeamMember: |
| - // The whole instance. One team, one set of sheets. |
| - default: |
| - // A guest sees exactly what they were granted. The join is an |
| - // inner join precisely so a guest with no grants gets an empty |
| - // list rather than everything. |
| - q = q.Joins("JOIN grants ON grants.sheet_id = sheets.id AND grants.member_id = ?", m.ID) |
| - } |
| - |
| - if limit > 0 { |
| - q = q.Limit(limit) |
| - } |
| - var rows []store.Sheet |
| - if err := q.Order("sheets.updated_at DESC, sheets.id DESC").Find(&rows).Error; err != nil { |
| - return nil, err |
| - } |
| - return rows, nil |
| -} |
| - |
| // grantsOn lists who can reach a sheet, for the share screen. |
| type sharedWith struct { |
| Member Member |
diff --git a/internal/sheets/session_guard.go b/internal/sheets/session_guard.go| new file mode 100644 |
| index 0000000..767f0d8 |
| --- /dev/null |
| +++ b/internal/sheets/session_guard.go |
| @@ -0,0 +1,21 @@ |
| +package sheets |
| + |
| +import "net/http" |
| + |
| +// requireSession is auth.RequireSession in production and a |
| +// pass-through when there is no auth to require one with. |
| +// |
| +// The pass-through is for tests only, and it is deliberate rather than |
| +// accidental: a nil-auth App has no sessions at all, so requiring one |
| +// would make every route below untestable without a mailer, an SMTP |
| +// refusal and a full magic-link round trip. Production cannot reach it |
| +// — main exits before New if sign-in is not configured. |
| +func (a *App) requireSession(next http.Handler) http.Handler { |
| + if a.home != nil { |
| + return a.homeRequire(next) |
| + } |
| + if a.auth == nil { |
| + return next |
| + } |
| + return a.auth.RequireSession(a.rejectDisabledHome(next)) |
| +} |
diff --git a/internal/sheets/visible_sheets.go b/internal/sheets/visible_sheets.go| new file mode 100644 |
| index 0000000..71793b9 |
| --- /dev/null |
| +++ b/internal/sheets/visible_sheets.go |
| @@ -0,0 +1,53 @@ |
| +package sheets |
| + |
| +import ( |
| + "amadan.net/oficina/sheets/internal/sheets/store" |
| + "context" |
| +) |
| + |
| +// visibleSheets returns the sheets a member may see. |
| +// |
| +// This is the hand-written grants join AGENTS.md requires, and the |
| +// reason it is hand-written rather than scope.Owned: scope.Owned is |
| +// single-column equality on user_id, our sheets are team-shared, and |
| +// applied here it would return only the sheets a person created — which |
| +// fails as a plausible short list rather than as an error. |
| +// |
| +// The query is deliberately one statement rather than "list all, then |
| +// filter in Go". A filter in Go reads every sheet on the instance into |
| +// memory before discarding most of them, which is both wasteful and the |
| +// shape where somebody later forgets the discard. |
| +func (a *App) visibleSheets(m Member) ([]store.Sheet, error) { |
| + return a.visibleSheetsLimited(context.Background(), m, 0) |
| +} |
| +func (a *App) visibleSheetsLimited(ctx context.Context, m Member, limit int) ([]store.Sheet, error) { |
| + if a.db == nil { |
| + return nil, errNoDB |
| + } |
| + // filling_since alongside deleted_at, everywhere the other is |
| + // checked: a sheet still being filled from an imported file is not |
| + // a thing anybody should see yet, and on this instance every team |
| + // member sees every sheet, so "not visible" has to mean not in this |
| + // query rather than not linked to. |
| + q := a.db.WithContext(ctx).Model(&store.Sheet{}). |
| + Where("sheets.deleted_at IS NULL AND sheets.filling_since IS NULL") |
| + |
| + switch TeamRole(m.TeamRole) { |
| + case TeamOwner, TeamMember: |
| + // The whole instance. One team, one set of sheets. |
| + default: |
| + // A guest sees exactly what they were granted. The join is an |
| + // inner join precisely so a guest with no grants gets an empty |
| + // list rather than everything. |
| + q = q.Joins("JOIN grants ON grants.sheet_id = sheets.id AND grants.member_id = ?", m.ID) |
| + } |
| + |
| + if limit > 0 { |
| + q = q.Limit(limit) |
| + } |
| + var rows []store.Sheet |
| + if err := q.Order("sheets.updated_at DESC, sheets.id DESC").Find(&rows).Error; err != nil { |
| + return nil, err |
| + } |
| + return rows, nil |
| +} |