Update policy for v2 project level rules

Background

The legacy approval rules are represented with two different models:

Model Policy
ApprovalProjectRule ApprovalProjectRulePolicy
ApprovalMergeRequestRule ApprovalMergeRequestRulePolicy

The v2 approval rules are represented with just one model and still a work in progress:

  • MergeRequests::ApprovalRule
  • In order to unblock project level approval rules development we need to add a dedicated policy for the v2 approval rule model that will authorize edit_approval_rule based on the origin of the approval rule.

Proposal

Implement a MergeRequests::ApprovalRulePolicy such that it:

  • When an approval rule is for a project (origin is project)
    • enable read_approval_rule when the user can read_project on the project associated with the approval rule
    • enable edit_approval_rule when the user can admin_project on the project associated with the approval rule
  • When an approval rule is for a merge request ('originismerge_request`)
    • enable read_approval_rule when the user can read_merge_request on the merge request associated with the approval rule
    • enable edit_approval_rule when the user can update_merge_request on the merge request associated with the approval rule and the approval rule is user defined
Edited by 🤖 GitLab Bot 🤖