feat: more role backend and admin/writer roles additions and adjustments

This commit is contained in:
Florian Sylvain committed 2026-10-26 18:15:26 +01:00
1 parent 8c6c6456da
commit de142f6c5f
131 files changed
+2663 -435

No files matched your search

@@ -3,34 +3,33 @@ package useCases
import (
"RenewCMS/internal/domain/apikey"
"RenewCMS/internal/domain/audit"
"RenewCMS/internal/domain/user"
"RenewCMS/internal/domain/role"
"context"
"time"
)
type RevokeAPIKeyUseCase struct {
apiKeyRepository apikey.Repository
userRepository user.Repository
now func() time.Time
recorder audit.Recorder
}
func NewRevokeAPIKeyUseCase(apiKeyRepository apikey.Repository, userRepository user.Repository, now func() time.Time, recorder audit.Recorder) *RevokeAPIKeyUseCase {
return &RevokeAPIKeyUseCase{apiKeyRepository, userRepository, now, recorder}
func NewRevokeAPIKeyUseCase(apiKeyRepository apikey.Repository, now func() time.Time, recorder audit.Recorder) *RevokeAPIKeyUseCase {
return &RevokeAPIKeyUseCase{apiKeyRepository, now, recorder}
}
func (r *RevokeAPIKeyUseCase) RevokeAPIKey(ctx context.Context, requesterId uint32, keyId uint32) error {
func (r *RevokeAPIKeyUseCase) RevokeAPIKey(ctx context.Context, requesterId uint32, keyId uint32, grants role.GrantSet) error {
scope := grants.Scope(role.KeyAPIKeysRevoke)
if scope == role.ScopeNone {
return role.MissingPermissionError{Key: role.KeyAPIKeysRevoke}
}
key, err := r.apiKeyRepository.Get(keyId)
if err != nil {
return err
}
requester, err := r.userRepository.Get(requesterId)
if err != nil {
return err
}
if requester.Role != user.RoleOwner && key.UserID != requester.ID {
if scope != role.ScopeAll && key.UserID != requesterId {
return apikey.ErrAPIKeyNotFound
}