Draft: Add No one option to Roles allowed to create subgroups group setting
What does this MR do and why?
Group Owners can currently choose whether Owners or Maintainers (and Owners) are allowed to create subgroups in a group, but there is no way to block subgroup creation entirely. This MR adds a No one option to the Roles allowed to create subgroups setting (Settings > General > Permissions and group features, and the Admin area group edit page) and accepts the matching noone value for subgroup_creation_level in the Groups REST API.
When a group is set to No one:
- Nobody can create a subgroup in that group, including group Owners and instance administrators.
- Because the same
create_subgrouppermission guards those actions, nobody can transfer an existing group into it or import a group into it (direct transfer or file import) either. - The New subgroup button on the group page and the New subgroup entry in the + (new) menu are hidden for that group.
This mirrors the existing No one option of the Roles allowed to create projects setting (project_creation_level).
Technical details
lib/gitlab/access.rb: addNO_ONE_SUBGROUP_ACCESS = 2and theNo one/nooneentries insubgroup_creation_optionsandsubgroup_creation_string_options. Existing values0(Owner) and1(Maintainer) are unchanged.app/policies/group_policy.rb:create_subgroup_disabledreturnstrueforNO_ONE_SUBGROUP_ACCESS, which prevents:create_subgroupfor every user.- No changes needed in the group settings view, the Admin area group edit view, REST API param validation, the REST/GraphQL group entities, or direct transfer: they all read the option lists from
Gitlab::Accessdynamically. - No database migration:
namespaces.subgroup_creation_levelis already an integer column and no database review is needed. - Docs:
doc/api/groups.md,doc/user/group/subgroups/_index.md. - Specs:
spec/policies/group_policy_spec.rb,spec/requests/api/groups_spec.rb.
References
Closes #619168
Screenshots or screen recordings
| Before | After |
|---|---|
| Two radio options: Owners, Maintainers | Three radio options: No one, Owners, Maintainers |
How to set up and validate locally
-
Create a group and open Settings > General > Permissions and group features.
-
Under Roles allowed to create subgroups, select No one and select Save changes.
-
On the group overview page, confirm the New subgroup button is gone. Open
/groups/new?parent_id=<group id>and confirm you cannot create a subgroup, even as an Owner or administrator. -
From another group, go to Settings > General > Advanced > Transfer group and try to transfer it into this group. Confirm the transfer is rejected with a permissions error.
-
REST API:
curl --request PUT --header "PRIVATE-TOKEN: <token>" "http://gdk.test:3000/api/v4/groups/<group id>?subgroup_creation_level=noone"The response includes
"subgroup_creation_level": "noone", andPOST /api/v4/groupswithparent_id=<group id>now returns403 Forbidden. -
Switch the setting back to Owners or Maintainers and confirm subgroup creation works again.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.