We should not allow a custom role (MemberRole) to be deleted until it is not associated with any users/memberships.(require all users associated with a custom role to be disassociated from custom role before it can be deleted)
In an ideal world, we could give some kind of error that would say:
"Guest+1 cannot be deleted because [User X] is assigned."
Then give them a choice:
Assign a different role to User X
Ok/Acknowledge
This issue originally began as a follow-up to an MR discussion about a database constraint that was believed to delete custom roles if any of the membership records for that custom role is deleted. That was tested out and seems not to be the case. But the opposite is true: deleting a custom role removes all memberships associated with that custom role. To avoid any unintended member removals, we should add this validation/warning step.
Because custom roles are currently only destroy-able via the API, the above suggestion on assign/ok is not going to work. For now, the validation should just prevent the deletion and advice the Owner to remove all custom role users before deleting the custom role.
This is a good question - do we necessarily need to delete a user who doesn't have a role? Can we make them inactive instead?
I think customers would not like any automatic movement of users into roles (with exception of SAML group links), due to security reasons, so I'd like to think of another solution.
@hsutor@ifarkas Here is a scenario to help us think through this case:
User A is part of Group B as a Guest+1 user (can read code)
Guest+1 role is deleted from Group B (owner of Group B no longer wants this custom role)
Options for how to handle this scenario:
User A becomes a regular Guest on Group B
User A is removed from Group B
We do not allow Guest+1 role to be deleted until Guest A is no long a Guest+1 user (require all users associated with a custom role to be disassociated from custom role before it can be deleted)
@jessieay@ifarkas Thanks for the example, makes it much easier for me to understand
I kind of like this option:
We do not allow Guest+1 role to be deleted until Guest A is no long a Guest+1 user (require all users associated with a custom role to be disassociated from custom role before it can be deleted)
In an ideal world, we could give some kind of error that would say:
"Guest+1 cannot be deleted because [User X] is assigned."
Then give them a choice:
Assign a different role to User X
Ok/Acknowledge
The list of users may may be very long, however, I supposed in an API response we can return all of the users who have the custom role, but I'm not sure how we'd display this in the UI
For MVC, we can just let them not delete it because it's associated to a user. And then we need a way for an admin/group owner to see all users assigned to a certain role.
Now that we've changed the direction here, I think that we actually need to tackle this issue first: #387769 (closed)
Right now, the only way to change the permissions of user with a custom role is the delete the custom role, which deletes their membership from the group.
If we remove the ability to delete custom roles that are associated with users right now, they will effectively become undeletable because there is no way to de-associate a user.
Jessie Youngchanged title from Fix foreign key cascading delete on Member to MemberRole to Validate that a custom role is not associated with any users before allowing deletion
changed title from Fix foreign key cascading delete on Member to MemberRole to Validate that a custom role is not associated with any users before allowing deletion
Jessie Youngchanged title from Validate that a custom role is not associated with any users before allowing deletion to Validate/warn that a custom role is not associated with any users before allowing deletion
changed title from Validate that a custom role is not associated with any users before allowing deletion to Validate/warn that a custom role is not associated with any users before allowing deletion
Jessie Youngchanged the descriptionCompare with previous version
changed the description
Jessie Youngchanged title from Validate/warn that a custom role is not associated with any users before allowing deletion to Validate that a custom role is not associated with any users before allowing deletion
changed title from Validate/warn that a custom role is not associated with any users before allowing deletion to Validate that a custom role is not associated with any users before allowing deletion