62 admin sponsor edit permission middleware#79
Open
5sansiva wants to merge 3 commits into
Open
Conversation
d5c175a to
ba2d5b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
AdminSponsorEditPermissionMiddlewareand corresponding super admin toggle to gate sponsor mutation routes for admin-role users, following the same pattern as the existingAdminScheduleEditPermissionMiddleware.Backend
cmd/api/middlewares.go): AddedAdminSponsorEditPermissionMiddleware— blocksPOST,PUT, andDELETEon/admin/sponsorsfor admin-role users when the toggle is disabled; super admins always bypass.cmd/api/api.go): Wired the middleware onto sponsor mutation routes (POST /,PUT /{sponsorID},DELETE /{sponsorID},PUT /{sponsorID}/logo);GET /(list) remains unprotected.cmd/api/settings.go): AddedGETandPOST /superadmin/settings/admin-sponsor-edit-togglehandlers with Swagger docs and request/response types (SetAdminSponsorEditTogglePayload,AdminSponsorEditToggleResponse).internal/store/settings.go,storage.go): AddedGetAdminSponsorEditEnabledandSetAdminSponsorEditEnabledwith theadmin_sponsor_edit_enabledsettings key; uses upsert on thesettingstable (same as schedule toggle).cmd/migrate/migrations/000015_seed_admin_sponsor_edit_enabled): Seedsadmin_sponsor_edit_enabled = trueas the default.internal/store/mock_store.go): Added mock implementations for both new store methods.Tests
cmd/api/settings_test.go):TestGetAdminSponsorEditToggleandTestSetAdminSponsorEditTogglecovering enabled/disabled toggle reads and writes.cmd/api/sponsors_test.go):TestSponsorMutationPermissioncovering admin blocked on create/update/delete/logo-upload when disabled, admin allowed when enabled, and super admin always allowed regardless of toggle state.