Class: NotePolicy

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

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#access_levelObject


85
86
87
88
89
90
# File 'app/policies/note_policy.rb', line 85

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

  lookup_access_level!
end

#lookup_access_level!Object


92
93
94
95
96
97
98
99
100
# File 'app/policies/note_policy.rb', line 92

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


76
77
78
79
80
81
82
83
# File 'app/policies/note_policy.rb', line 76

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