Skip to content

Refactor/56 addapplicationsenabledmiddleware#67

Merged
balebbae merged 28 commits intomainfrom
refactor/56-addapplicationsenabledmiddleware
Apr 9, 2026
Merged

Refactor/56 addapplicationsenabledmiddleware#67
balebbae merged 28 commits intomainfrom
refactor/56-addapplicationsenabledmiddleware

Conversation

@5sansiva
Copy link
Copy Markdown
Collaborator

Summary
Refactor: Move ApplicationsEnabled to Settings and wire up middleware

Store Layer
Moved GetApplicationsEnabled / SetApplicationsEnabled from the Application interface → Settings interface in storage.go (these are global toggles, not application CRUD)
Moved implementations from ApplicationsStore (applications.go) → SettingsStore (settings.go)
Moved mock stubs from MockApplicationStore → MockSettingsStore in mock_store.go

API Layer
Wired ApplicationsEnabledMiddleware onto hacker mutation routes (PATCH /me, POST /me/submit, POST /me/resume-upload-url, DELETE /me/resume)
Added unguarded GET /applications/enabled route so the frontend can check if submissions are open
Super admins bypass the middleware check; all other users receive 403 when applications are disabled
Updated getApplicationsEnabled / setApplicationsEnabled handlers to call app.store.Settings.* instead of app.store.Application.*

Tests
Added TestApplicationsEnabledMiddleware covering:
Returns 403 when applications are disabled
Passes through with 200 when applications are enabled
Uses .Once() on mock expectations to prevent cross-test pollution

Misc
Fixed Swagger tags: admin → admin/applications, superadmin → superadmin/applications

@5sansiva 5sansiva requested review from anishalle and balebbae March 26, 2026 18:46
Copy link
Copy Markdown
Collaborator

@anishalle anishalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Collaborator

@balebbae balebbae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more importing strconv 😭

Comment thread internal/store/settings.go Outdated
query := `
SELECT value
FROM settings
WHERE key = 'applications_enabled'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const and pass it in like the GetAdminScheduleEditEnabled look at line 29

Comment thread internal/store/settings.go Outdated
defer cancel()

query := `
UPDATE settings
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of update returning do insert ... on conflict do update. look at the other upsert patterns

return err
}

func (s *SettingsStore) GetApplicationsEnabled(ctx context.Context) (bool, error) {
Copy link
Copy Markdown
Collaborator

@balebbae balebbae Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont return bool when called should already show enabled. just return error look at the other set signature patterns

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment thread internal/store/settings.go Outdated
RETURNING value`

var value bool
err := s.db.QueryRowContext(ctx, query, strconv.FormatBool(enabled)).Scan(&value)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use strconv use json.Marshal like the other setters. So remove the import as well.

Comment thread cmd/api/settings.go Outdated
//
// @Summary Set applications enabled status
// @Description Sets whether the application portal is currently open for submissions. Requires SuperAdmin privileges.
// @Tags superadmin
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tags should be superadmin/settings

Comment thread cmd/api/settings.go Outdated
// @Security CookieAuth
// @Router /superadmin/settings/applications-enabled [put]
func (app *application) setApplicationsEnabled(w http.ResponseWriter, r *http.Request) {
enabled, err := strconv.ParseBool(r.URL.Query().Get("enabled"))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use JSON body like the other sets. no strconv :) remove that import. Look at line 365-369 for reference

Comment thread cmd/api/settings.go Outdated
return
}

//NOTE: Following existing design pattern of Get response and Set response structs
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this note

Comment thread cmd/api/api.go Outdated
r.Route("/applications", func(r chi.Router) {
r.Get("/", app.listApplicationsHandler)
r.Get("/stats", app.getApplicationStatsHandler)
r.Get("/enabled", app.getApplicationsEnabled)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this. this is a duplicate from line 170

@5sansiva 5sansiva requested a review from balebbae March 31, 2026 13:44
return err
}

func (s *SettingsStore) GetApplicationsEnabled(ctx context.Context) (bool, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one

@@ -0,0 +1,2 @@
INSERT INTO settings (key, value) VALUES ('applications_enabled', 'true'::jsonb)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats going on here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migration 16 is for review_assignment_setting on main. Don't edit existing migrations. just make a new one with task migrate-create {name of migration}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait I didn't touch any of the existing migrations

@anishalle anishalle self-requested a review March 31, 2026 18:21
balebbae added 6 commits April 9, 2026 13:11
Merge main into refactor/56-addapplicationsenabledmiddleware,
resolving conflicts in mock_store.go and regenerating docs.go.
@balebbae balebbae merged commit f6b7384 into main Apr 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants