Skip to content

Super admin review toggle management view #35

@balebbae

Description

@balebbae

Summary

Continuation of PR #26 (Review Assignment Toggle). Currently, each super admin can only toggle their own review assignment on/off. This feature updates the existing endpoints so any super admin can see all super admins and toggle their review assignment status.

Why

Right now, if a super admin forgets to disable themselves or is unavailable, another super admin has no way to turn off their reviews — they'd need direct database access. This view gives super admins visibility into who is receiving reviews and the ability to manage each other's toggles.

Approach

Replace the existing endpoints in-place (project is early-stage, no backwards compatibility needed). No new routes required.

Backend

1. Store — Add two new methods

  • GetByRole(ctx, role) ([]User, error) on UsersStore — Simple SELECT ... FROM users WHERE role = $1. Needed so the GET handler can return email info for all super admins alongside toggle states.
  • GetAllReviewAssignmentToggles(ctx) ([]ReviewAssignmentEntry, error) on SettingsStore — Reads and returns the full JSON array from the settings table. Same query pattern as existing GetReviewAssignmentToggle but returns all entries instead of filtering to one.

2. Store interface + mock — Wire up the new methods

Add both methods to Storage interfaces in storage.go and corresponding mocks in mock_store.go.

3. Replace GET /v1/superadmin/settings/review-assignment-toggle

Currently returns { "enabled": bool } for the calling user only. Replace to:

  1. Call GetByRole(ctx, RoleSuperAdmin) to get all super admins
  2. Call GetAllReviewAssignmentToggles(ctx) to get the full toggle array
  3. Join them — super admins in the users table but missing from the toggle array default to enabled: true
  4. Return:
{
  "admins": [
    { "id": "uuid-1", "email": "alice@example.com", "enabled": true },
    { "id": "uuid-2", "email": "bob@example.com", "enabled": false }
  ]
}

4. Replace POST /v1/superadmin/settings/review-assignment-toggle

Currently accepts { "enabled": bool } and uses the caller's user ID from context. Replace to accept:

{ "user_id": "target-super-admin-id", "enabled": true }

Pass the provided user_id to the existing SetReviewAssignmentToggle(ctx, userID, enabled) store method (which already supports any ID — the restriction to "self only" was only in the handler).

Frontend

5. Update ReviewsPerAppTab.tsx

Replace the single self-toggle <Switch> card with a list of all super admins:

  • Fetch the updated GET response on mount
  • Render each super admin as a row with their email and a <Switch>
  • Toggling any switch calls the updated POST with that admin's user_id
  • Visually distinguish the current user (e.g., "(you)" label)
  • Show loading/toast states as before

What stays the same

  • Settings table schema and JSONB storage format — no migration needed
  • SetReviewAssignmentToggle store method — already accepts arbitrary superAdminID
  • User creation logic that auto-adds new super admins with enabled: true
  • Route paths stay at GET/POST /v1/superadmin/settings/review-assignment-toggle
  • Legacy format fallback parsing in the store

Relates to PR #26

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions