Skip to content

Disable project and group sharing when setting a User Cap

Etienne Baqué requested to merge 332601-usercap-disable-group-sharing into master

What does this MR do?

Relates to #332601 (closed)

The purpose of this MR is to disable both project sharing and group sharing with other groups whenever a User Cap is set for this group (or this group's root ancestor).

To do so, this MR adds a few hooks to NamespaceSetting in order to:

  • set NamespaceSetting#prevent_sharing_groups_outside_hierarchy to the related (root) group before save
  • update NamespaceSetting#prevent_sharing_groups_outside_hierarchy to the namespace's descendants after save
  • update Namespace#share_with_group_lock to related namespace (which then will trigger that same update on its descendants)

Considerations and possible follow-up

After updating the user cap to a number, share_with_group_lock and prevent_sharing_groups_outside_hierarchy are set to true. But this is not the case when reverting: setting the user cap back to nil won't set share_with_group_lock and prevent_sharing_groups_outside_hierarchy back to false. This is because these settings may have already been checked before setting the user cap at all.

This means that when removing the user cap, we may need to create a message to warn the user that sharing projects and groups will still be disabled afterwards.

Screenshots or Screencasts (strongly suggested)

The screenshot below shows a group with two children group. When updating the user cap for this group (via its namespace_settings), it sets the Namespace#share_with_group_lock and NamespaceSetting#prevent_sharing_groups_outside_hierarchy flag to true for this group as well as its descendants

08-09-2021: tests carried out after latest new commit.

  1. Before update:

Screenshot_from_2021-08-09_14-07-55

  1. new_user_signups_cap update:

Screenshot_from_2021-08-09_14-09-00

  1. After update:

Screenshot_from_2021-08-09_14-11-25

Previous set of tests

  1. Before update:

Screenshot_from_2021-08-03_14-40-16

  1. new_user_signups_cap update. After the user cap is updated, two other UPDATE queries are triggered: one for Namespace records, one for NamespaceSetting records:

Screenshot_from_2021-08-03_14-42-30

  1. After update:

Screenshot_from_2021-08-03_14-45-20

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #332601 (closed)

Edited by Etienne Baqué

Merge request reports