gitlab-org--gitlab-foss/app/policies/project_snippet_policy.rb
DJ Mountney ae6adf165c Merge branch '25934-project-snippet-vis' into 'security-9-2'
Fix visibility when referencing snippets

See merge request !2101
2017-06-08 09:56:39 -07:00

25 lines
826 B
Ruby

class ProjectSnippetPolicy < BasePolicy
def rules
# 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)
can! :read_project_snippet if @subject.public?
return unless @user
if @user && (@subject.author == @user || @user.admin?)
can! :read_project_snippet
can! :update_project_snippet
can! :admin_project_snippet
end
if @subject.internal? && !@user.external?
can! :read_project_snippet
end
if @subject.project.team.member?(@user)
can! :read_project_snippet
end
end
end