Commit 41aa6fe0 authored by Robert Speicher's avatar Robert Speicher

Merge branch '20621-avoid-lame-conflicts-in-ability-allowed-ee' into 'master'

Move abilities by subject class to a dedicated method (EE)

## What does this MR do?

Twin of gitlab-org/gitlab-ce!5668.

It moves the `case` that returns abilities depending on the subject class to a dedicated method.

This should avoid lame conflicts when CE to EE since the EE version assign the result of the `case` to a variable.

## What are the relevant issue numbers?

Closes gitlab-org/gitlab-ce#20621.

See merge request !622
parents 2f2a3b06 bce5f8f1
......@@ -6,30 +6,33 @@ class Ability
return [] unless user.is_a?(User)
return [] if user.blocked?
abilities =
case subject
when CommitStatus then commit_status_abilities(user, subject)
when Project then project_abilities(user, subject)
when Issue then issue_abilities(user, subject)
when Note then note_abilities(user, subject)
when ProjectSnippet then project_snippet_abilities(user, subject)
when PersonalSnippet then personal_snippet_abilities(user, subject)
when MergeRequest then merge_request_abilities(user, subject)
when Group then group_abilities(user, subject)
when Namespace then namespace_abilities(user, subject)
when GroupMember then group_member_abilities(user, subject)
when ProjectMember then project_member_abilities(user, subject)
when User then user_abilities
when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project)
when Ci::Runner then runner_abilities(user, subject)
else []
end.concat(global_abilities(user))
abilities = abilities_by_subject_class(user: user, subject: subject)
abilities -= license_blocked_abilities if License.block_changes?
abilities
end
def abilities_by_subject_class(user:, subject:)
case subject
when CommitStatus then commit_status_abilities(user, subject)
when Project then project_abilities(user, subject)
when Issue then issue_abilities(user, subject)
when Note then note_abilities(user, subject)
when ProjectSnippet then project_snippet_abilities(user, subject)
when PersonalSnippet then personal_snippet_abilities(user, subject)
when MergeRequest then merge_request_abilities(user, subject)
when Group then group_abilities(user, subject)
when Namespace then namespace_abilities(user, subject)
when GroupMember then group_member_abilities(user, subject)
when ProjectMember then project_member_abilities(user, subject)
when User then user_abilities
when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project)
when Ci::Runner then runner_abilities(user, subject)
else []
end.concat(global_abilities(user))
end
def license_blocked_abilities
[
:create_issue,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment