feat(19.7-01): account contributions, prompted record actions and backend subject events
- pact.HasAccountContributions compiled at Activate; GET /account/contributions
and POST /account/contributions/{name}/actions/{action} behind interactiveOnly
(AccountContributionView, AccountContributionActionView, AccountActionResultView)
- RecordAction.prompt (RecordActionPrompt) for a pact.AdminRecordAction with a
Prompt; the record action route accepts payload only for such an action
(trimmed JSON string, non-empty, capped at max_length) and hands it to Run as
Value through CRUDService.RecordActionWithValue; a prompt without a label
fails boot
- fireSubjectChanged: pact.MCPSubjectChanged for revoked tokens, Administrators
saves that changed role, permissions or superuser, Roles saves that changed
grants, deactivation and deletion
- phrases backend::lang.form.action_prompt_required/_too_long (en, pl)
- smoke tests TestAccountContributionsSmoke and TestRecordActionPromptSmoke;
TestRecordActionPromptRun on Postgres; route inventories, CSRF walk and
OpenAPI conformance cases extended for the two routes
- regenerated admin/openapi/admin.json and admin/src/api/schema.d.ts; cabana
README, docs/backend/{admin-controllers,users-and-permissions}.md
This commit is contained in:
@@ -216,7 +216,7 @@ func (c usersAdmin) FormBeforeDelete(ctx context.Context, model any) error {
|
||||
// backend user is never hard-deleted, so tokens, linked_by references and
|
||||
// attachments keep valid foreign keys (D-10). Personal API tokens stop
|
||||
// because the guard refuses a deleted administrator.
|
||||
func (usersAdmin) FormAfterDelete(ctx context.Context, model any) error {
|
||||
func (c usersAdmin) FormAfterDelete(ctx context.Context, model any) error {
|
||||
user, err := asBackendUser(model)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -226,9 +226,13 @@ func (usersAdmin) FormAfterDelete(ctx context.Context, model any) error {
|
||||
return errors.New("cabana: administrators: a delete needs its transaction")
|
||||
}
|
||||
cutoff := revocationCutoff()
|
||||
return tx.Session(&gorm.Session{NewDB: true}).WithContext(ctx).Unscoped().
|
||||
if err := tx.Session(&gorm.Session{NewDB: true}).WithContext(ctx).Unscoped().
|
||||
Model(&BackendUser{}).Where("id = ?", user.ID).
|
||||
Update("tokens_valid_after", cutoff).Error
|
||||
Update("tokens_valid_after", cutoff).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
fireSubjectChanged(ctx, c.application(), pact.MCPSubjectDeleted, user.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// usersLifecycle is one lifecycle action of the Administrators screen,
|
||||
@@ -276,8 +280,14 @@ func (c usersAdmin) lifecycles() []usersLifecycle {
|
||||
if err := guardLastSuperuser(ctx, user); err != nil {
|
||||
return err
|
||||
}
|
||||
return db.Model(&BackendUser{}).Where("id = ?", user.ID).
|
||||
Updates(map[string]any{"is_activated": false, "tokens_valid_after": revocationCutoff()}).Error
|
||||
if err := db.Model(&BackendUser{}).Where("id = ?", user.ID).
|
||||
Updates(map[string]any{"is_activated": false, "tokens_valid_after": revocationCutoff()}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// A deactivated administrator can no longer act anywhere,
|
||||
// an MCP session included.
|
||||
fireSubjectChanged(ctx, c.application(), pact.MCPSubjectDeleted, user.ID)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -767,6 +777,8 @@ func (c usersAdmin) FormBeforeUpdate(ctx context.Context, model any) error {
|
||||
} else {
|
||||
user.priorRoleID = nil
|
||||
}
|
||||
user.priorPermissions = user.Permissions
|
||||
user.priorSuperuser = user.IsSuperuser
|
||||
user.priorLoaded = true
|
||||
if !self {
|
||||
if err := guardOutranked(ctx, c.registry(), principal, user); err != nil {
|
||||
@@ -812,19 +824,24 @@ func (c usersAdmin) FormBeforeUpdate(ctx context.Context, model any) error {
|
||||
|
||||
// FormAfterUpdate refuses a change of the editor's own role (D-08). The
|
||||
// submitted role is assigned after FormBeforeUpdate, so it is compared here,
|
||||
// with the row written: the refusal rolls the save back.
|
||||
// with the row written: the refusal rolls the save back. A save that changed
|
||||
// the administrator's role, own permissions or superuser flag then fires
|
||||
// pact.MCPSubjectChanged (permissions) for them.
|
||||
func (c usersAdmin) FormAfterUpdate(ctx context.Context, model any) error {
|
||||
user, err := asBackendUser(model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
principal, _ := bouncer.User(ctx)
|
||||
if !user.priorLoaded || principal == nil || principal.ID != user.ID {
|
||||
if !user.priorLoaded {
|
||||
return nil
|
||||
}
|
||||
if !sameRoleID(user.priorRoleID, user.RoleID) {
|
||||
principal, _ := bouncer.User(ctx)
|
||||
if principal != nil && principal.ID == user.ID && !sameRoleID(user.priorRoleID, user.RoleID) {
|
||||
return &ForbiddenError{Message: usersLang + "self_privileged", Details: map[string]any{usersRoleField: []string{usersLang + "self_privileged"}}}
|
||||
}
|
||||
if !sameRoleID(user.priorRoleID, user.RoleID) || user.priorPermissions != user.Permissions || user.priorSuperuser != user.IsSuperuser {
|
||||
fireSubjectChanged(ctx, c.application(), pact.MCPSubjectPermissions, user.ID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user