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

+13 -10
View File
@@ -3,6 +3,7 @@ package test
import (
"RenewCMS/api"
"RenewCMS/internal/domain/apikey"
"RenewCMS/internal/domain/role"
"RenewCMS/internal/domain/user"
"RenewCMS/internal/infrastructure/useCases"
"net/http"
@@ -86,13 +87,15 @@ func TestAPIKeysCreatorNameHttp(t *testing.T) {
}
})
t.Run("API: an admin's list is unchanged", func(t *testing.T) {
t.Run("API: an own-scope caller's list is unchanged", func(t *testing.T) {
env := newAPIKeyEnv(t)
env.nameUsers()
env.issueKey(apiKeyDevId, "a")
env.issueKey(apiKeyDevId, "b")
env.customRoleUser(6, role.Grant{Key: "apikeys.view", Scope: role.ScopeOwn})
env.issueKey(6, "a")
env.issueKey(6, "b")
env.issueKey(apiKeyDevId, "other")
rec := env.withCookie(t, http.MethodGet, "/v1/api-key", "", apiKeyDevId)
rec := env.withCookie(t, http.MethodGet, "/v1/api-key", "", 6)
assertAPIKeyStatus(t, rec, http.StatusOK)
list := apiKeyDecodeList(t, rec)
@@ -174,10 +177,10 @@ func TestListAPIKeysCreatorName(t *testing.T) {
return repo
}
t.Run("Use case: ListAPIKeys returns the creator name only to an owner", func(t *testing.T) {
t.Run("Use case: ListAPIKeys returns the creator name only with all scope", func(t *testing.T) {
uc := useCases.NewListAPIKeysUseCase(seed(), users(), apiKeyUnitClock)
ownerEntries, err := uc.ListAPIKeys(1)
ownerEntries, err := uc.ListAPIKeys(1, apiKeyAllScope)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -189,12 +192,12 @@ func TestListAPIKeysCreatorName(t *testing.T) {
t.Errorf("unexpected creator names %v", names)
}
adminEntries, err := uc.ListAPIKeys(2)
ownScopeEntries, err := uc.ListAPIKeys(2, apiKeyOwnScope)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(adminEntries) != 1 || adminEntries[0].CreatorName != "" {
t.Errorf("expected one entry with an empty creator name, got %+v", adminEntries)
if len(ownScopeEntries) != 1 || ownScopeEntries[0].CreatorName != "" {
t.Errorf("expected one entry with an empty creator name, got %+v", ownScopeEntries)
}
})
}
@@ -218,7 +221,7 @@ func TestListAPIKeysTieKeepsRepositoryOrder(t *testing.T) {
}}
uc := useCases.NewListAPIKeysUseCase(repo, apiKeyUnitUsers(), apiKeyUnitClock)
entries, err := uc.ListAPIKeys(1)
entries, err := uc.ListAPIKeys(1, apiKeyAllScope)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}