Skip to content

Membership models can be invalid when greater access level is inherited

Summary

  • The root Group A has a sub-group B
  • User U has a membership to both the root group A and the sub-group B as a developer
  • User U becomes maintainer in root group A
  • User U therefore gets an inherited maintainer access level for sub-group B.
  • The Member Record from user U to the sub-group B becomes 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

  1. Add a user to the root group as developer
  2. Add the same user to a sub-group of the root group as developer
  3. Change membership type from the user in the root group to maintainer
  4. 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!
  5. 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