Enforce read-only state for groups and projects pending deletion
What does this MR do and why?
A group marked for deletion, and everything under it, still accepts writes, and that work is lost when the group is deleted. This MR makes a group read-only once it is scheduled for deletion. The same applies to its subgroups and projects.
Related to #457722 (closed). It doesn't close the issue, because group name, path and settings changes are not blocked yet (see Not in this MR).
Changes
- Policies:
GroupPolicyandProjectPolicynow prevent thegroup:archivedandproject:archivedpermissions when the resource or any ancestor group is scheduled for deletion (scheduled_for_deletion_in_hierarchy_chain?). - Permission lists: added the delete actions that were previously allowed while pending deletion (the
archived & ~group_scheduled_for_deletionexception and its EE counterpart are removed), pluscreate_group_link,rename_project,admin_group_member,admin_project_memberandinvite_project_members. - Member removal still works: it now uses
destroy_project_member(maintainer) anddestroy_group_member(owner) instead ofadmin_*_member, so it isn't blocked. SAML and LDAP locks still apply. - Docs: the group and project deletion pages say that a resource pending deletion is read-only.
Also affects archived resources: archived and pending-deletion resources share one permission list, so archived groups and projects can no longer be shared or get new members, and archived projects can no longer be renamed. This matches #481743 (closed). The group that owns archiving should review it.
Not in this MR
- Group name, path and settings: only
admin_groupcovers them, and it also controls restore, unarchive and export, so it isn't blocked. Follow-up: #627530 - Project rename in the UI:
rename_projectis only checked by the REST API. Follow-up: #628246 destroy_wiki: added to the list, but nothing checks it. Follow-up: #628245- Request and system spec coverage for the remaining permissions. Follow-up: #628244
- Deleting or restoring a child of a pending-deletion group: #549074 (closed)
Database
The wider ancestor check adds one group_deletion_schedules lookup per namespace chain. It's cached per request. For lists, NamespaceSetting.with_ancestors_inherited_settings now also returns self_or_ancestors_deletion_scheduled, so preloaded callers make no extra query. Both queries use only index scans, and no new index is needed.
| Query | Cold | Warm | Plan |
|---|---|---|---|
| Ancestor lookup, 9-level chain | 16.2 ms | 0.26 ms | https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/65450/commands/170246 |
| Preload, 100 groups (new column adds 51 ms cold, 0.6 ms warm) | 456 ms | 3.95 ms | https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/65450/commands/170247 |
| Preload, 100 groups, master | 3.35 ms | https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/65450/commands/170248 |
Query budget changes
Single-resource endpoints make one extra query:
POST /projects/:id/members: 110 → 119POST /namespaces/:id/-/work_itemswith a parent: new limit of 108Groups::IssuesController#bulk_update: 432 → 433- Board issue move mutation: 189 → 191, and 111 → 113 for the nil-epic case
These go away with gitlab-org#21607, which stores namespace state on the record.
Testing notes
- Specs schedule deletion with
Groups::MarkForDeletionService, not the:deletion_scheduledtrait. The trait doesn't create thegroup_deletion_schedulesrow that ancestor lookups read, so descendants wouldn't see the parent as scheduled. - The
allows destroy actionscase in thegroup archiving abilitiesshared example never asserted anything. It is replaced with a realprevents destroy actionscheck. - Request specs cover the endpoints for
rename_project,create_group_linkand adding members.
Screenshots or screen recordings
N/A. Backend policy changes only.
How to set up and validate locally
group = Group.find_by_full_path('your-group')
user = group.owners.first
::Groups::MarkForDeletionService.new(group, user).execute
Ability.allowed?(user, :destroy_issue, group) # => false
Ability.allowed?(user, :admin_group_member, group) # => false
Ability.allowed?(user, :invite_group_members, group.children.first) # => false
Ability.allowed?(user, :create_issue, group.projects.first) # => false
Ability.allowed?(user, :read_group, group) # => true
Ability.allowed?(user, :remove_group, group) # => true
Ability.allowed?(user, :admin_group, group) # => true (restore, export)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.