fix: clear a stale organisation_role when a user's organisation changes in the admin

The members relation manager and the organisation field of the Users form
declare cabana ClearOnChange on organisation_role: adding or removing a
member, and a form save that moves a user to another organisation or to
none, clear the role unless the same save writes it. Needs a SummerCMS
release with ClearOnChange.
This commit is contained in:
Jakub Zych
2026-10-22 03:33:12 +02:00
parent c3712dc0d4
commit aa8396916e
5 changed files with 68 additions and 22 deletions

View File

@@ -364,7 +364,9 @@ const groupsField = "groups"
// AdminFieldRelations binds the organisation picker and the groups field.
// organisation_id is a protected column, so the contract opts in to writing
// it through this one field; the submitted id is still checked against the
// options. groups is the users_groups pivot: a save that carries the field
// options. A save that changes the organisation (to another one or to none)
// clears organisation_role (ClearOnChange) unless the same save writes it.
// groups is the users_groups pivot: a save that carries the field
// replaces the user's memberships, and AdminRelationLocks decides which of
// them the administrator may change.
func (usersAdminController) AdminFieldRelations() []cabana.FieldRelationContract {
@@ -376,6 +378,7 @@ func (usersAdminController) AdminFieldRelations() []cabana.FieldRelationContract
ForeignKey: "organisation_id",
LabelColumn: "name",
WritableForeignKey: true,
ClearOnChange: []string{"organisation_role"},
},
{
Field: groupsField,