Membership models can be invalid when greater access level is inherited
Summary
- The root Group
Ahas a sub-groupB - User
Uhas a membership to both the root groupAand the sub-groupBas adeveloper - User
Ubecomesmaintainerin root groupA - User
Utherefore gets an inheritedmaintaineraccess level for sub-groupB. - The
MemberRecord from userUto the sub-groupBbecomes invalid.
The problem is that we can no longer modify the invalid memberships anywhere in the application. This hasn't been an issue so far because inherited membership access levels are not allowed to be modified in the UI
Steps to reproduce
- Add a user to the root group as
developer - Add the same user to a sub-group of the root group as
developer - Change membership type from the user in the root group to
maintainer - Query the memberships and validate
memberships = ::Member.in_hierarchy(Group.find(GROUP_ID)).with_user(User.find(USER_ID)) # get the membership from the sub-group (in this example it's `.first`) membership.first.validate! - See the error
ActiveRecord::RecordInvalid: Validation failed: Access level should be greater than or equal to Maintainer inherited membership from group testing-subscription-over-group
What is the current bug behavior?
Memberships can be invalid and can't be changed anymore when access level gets inherited.
What is the expected correct behavior?
Memberships are still valid, even when access level gets inherited.
Edited by Nicolas Dular