2016-09-29 09:46:39 +05:30
|
|
|
class ProjectSnippetPolicy < BasePolicy
|
|
|
|
def rules
|
2017-08-17 22:00:37 +05:30
|
|
|
# We have to check both project feature visibility and a snippet visibility and take the stricter one
|
|
|
|
# This will be simplified - check https://gitlab.com/gitlab-org/gitlab-ce/issues/27573
|
|
|
|
return unless @subject.project.feature_available?(:snippets, @user)
|
|
|
|
return unless Ability.allowed?(@user, :read_project, @subject.project)
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
can! :read_project_snippet if @subject.public?
|
|
|
|
return unless @user
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if @user && (@subject.author == @user || @user.admin?)
|
2016-09-29 09:46:39 +05:30
|
|
|
can! :read_project_snippet
|
|
|
|
can! :update_project_snippet
|
|
|
|
can! :admin_project_snippet
|
|
|
|
end
|
|
|
|
|
|
|
|
if @subject.internal? && !@user.external?
|
|
|
|
can! :read_project_snippet
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if @subject.project.team.member?(@user)
|
2016-09-29 09:46:39 +05:30
|
|
|
can! :read_project_snippet
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|