# Conflicts: # account/Makefile # account/go.mod # docs/account-admin-settings.md # docs/account-svc-plus.md
2.1 KiB
2.1 KiB
Account Service Admin Settings API
This document summarizes the new /api/auth/admin/settings endpoints for managing the permission matrix used by the account service.
Endpoints
-
GET /api/auth/admin/settings- Requires the caller to present
X-User-RoleorX-Roleheaders with valueadminoroperator. - Returns the latest permission matrix and associated version. The handler responds with
503 Service Unavailablewhen the admin settings database has not been initialised.
- Requires the caller to present
-
POST /api/auth/admin/settings- Accepts a JSON payload containing a
versionandmatrix. The matrix is validated to ensure module keys are non-empty and roles are within the supported set (admin,operator,user). - Uses optimistic locking on the
versionfield. When the provided version does not match the stored version the handler responds with409 Conflictand includes the authoritative matrix.
- Accepts a JSON payload containing a
Storage Model
- The permission matrix is stored in the
admin_settingstable. GORM manages the model viainternal/model/admin_setting.goand a dedicated migration script (sql/20250305-admin-settings.sql). - Each cell records
module_key,role,enabled, and a monotonically increasingversionvalue. Updates occur inside a single transaction that replaces the existing matrix to guarantee consistency across modules and roles. - The service layer (
internal/service/admin_settings.go) caches the most recent matrix in-memory and invalidates the cache whenever a write occurs or fails due to a version conflict.
Test Coverage
Integration tests are provided in api/admin_settings_test.go:
TestAdminSettingsReadWriteexercises a full write followed by a read using the operator role.TestAdminSettingsUnauthorizedverifies that callers without an admin/operator role receive403 Forbiddenresponses for both GET and POST.TestAdminSettingsVersionConflictvalidates the optimistic locking path by replaying a stale version and asserting a409 Conflictresponse that echoes the authoritative version.
Run the suite with:
go test ./api -run AdminSettings