Class: NotePolicy

Inherits:
BasePolicy show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/policies/note_policy.rb

Instance Attribute Summary

Attributes inherited from DeclarativePolicy::Base

#subject, #user

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods inherited from DeclarativePolicy::Base

ability_map, #allowed?, #banned?, #cache, #cached?, #can?, #condition, condition, conditions, configuration_for, #debug, delegate, #delegated_policies, delegations, desc, #disallowed?, enable_when, global_actions, #initialize, #inspect, last_options, last_options!, overrides, own_ability_map, own_conditions, own_delegations, own_global_actions, #policy_for, prevent_all_when, prevent_when, #repr, rule, #runner, with_options, with_scope, with_score

Constructor Details

This class inherits a constructor from DeclarativePolicy::Base

Instance Method Details

#access_levelObject


72
73
74
75
76
77
# File 'app/policies/note_policy.rb', line 72

def access_level
  return -1 if @user.nil?
  return -1 unless parent_namespace

  lookup_access_level!
end

#lookup_access_level!Object


79
80
81
82
83
84
85
86
87
# File 'app/policies/note_policy.rb', line 79

def lookup_access_level!
  return ::Gitlab::Access::REPORTER if alert_bot?

  if parent_namespace.is_a?(Project)
    parent_namespace.team.max_member_access(@user.id)
  else
    parent_namespace.max_member_access_for_user(@user)
  end
end

#parent_namespaceObject


63
64
65
66
67
68
69
70
# File 'app/policies/note_policy.rb', line 63

def parent_namespace
  strong_memoize(:parent_namespace) do
    next if @subject.is_a?(PersonalSnippet)
    next @subject.noteable.group if @subject.noteable&.is_a?(Epic)

    @subject.project
  end
end