diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-17 21:09:44 +0300 |
commit | 2c156e3c7bbade01c36eee18327f1ced6eebea79 (patch) | |
tree | 115fa8dbf6bc05037378b380311d31acb805f54c /app/models/event.rb | |
parent | 8e129497b2565b8c595ef4f806d9a9595ca654e5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/event.rb')
-rw-r--r-- | app/models/event.rb | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/app/models/event.rb b/app/models/event.rb index 606c4d8302f..18682bd694c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -135,29 +135,11 @@ class Event < ApplicationRecord super(presenter_class: ::EventPresenter) end - # rubocop:disable Metrics/CyclomaticComplexity - # rubocop:disable Metrics/PerceivedComplexity def visible_to_user?(user = nil) - if push_action? || commit_note? - Ability.allowed?(user, :download_code, project) - elsif membership_changed? - Ability.allowed?(user, :read_project, project) - elsif created_project_action? - Ability.allowed?(user, :read_project, project) - elsif issue? || issue_note? - Ability.allowed?(user, :read_issue, note? ? note_target : target) - elsif merge_request? || merge_request_note? - Ability.allowed?(user, :read_merge_request, note? ? note_target : target) - elsif personal_snippet_note? || project_snippet_note? - Ability.allowed?(user, :read_snippet, note_target) - elsif milestone? - Ability.allowed?(user, :read_milestone, project) - else - false # No other event types are visible - end + return false unless capability.present? + + Ability.allowed?(user, capability, permission_object) end - # rubocop:enable Metrics/PerceivedComplexity - # rubocop:enable Metrics/CyclomaticComplexity def resource_parent project || group @@ -364,8 +346,38 @@ class Event < ApplicationRecord Event._to_partial_path end + protected + + def capability + @capability ||= begin + if push_action? || commit_note? + :download_code + elsif membership_changed? || created_project_action? + :read_project + elsif issue? || issue_note? + :read_issue + elsif merge_request? || merge_request_note? + :read_merge_request + elsif personal_snippet_note? || project_snippet_note? + :read_snippet + elsif milestone? + :read_milestone + end + end + end + private + def permission_object + if note? + note_target + elsif target_id.present? + target + else + project + end + end + def push_action_name if new_ref? "pushed new" |