debian-mirror-gitlab/lib/gitlab/user_access_snippet.rb

64 lines
1.2 KiB
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
module Gitlab
class UserAccessSnippet < UserAccess
extend ::Gitlab::Cache::RequestCache
# TODO: apply override check https://gitlab.com/gitlab-org/gitlab/issues/205677
request_cache_key do
[user&.id, snippet&.id]
end
attr_reader :snippet
def initialize(user, snippet: nil)
@user = user
@snippet = snippet
@project = snippet&.project
end
2020-05-24 23:13:21 +05:30
def allowed?
return true if snippet_migration?
super
end
2020-04-08 14:13:33 +05:30
def can_do_action?(action)
2020-05-24 23:13:21 +05:30
return true if snippet_migration?
2020-04-08 14:13:33 +05:30
return false unless can_access_git?
permission_cache[action] =
permission_cache.fetch(action) do
Ability.allowed?(user, action, snippet)
end
end
def can_create_tag?(ref)
false
end
def can_delete_branch?(ref)
false
end
def can_push_to_branch?(ref)
2020-05-24 23:13:21 +05:30
return true if snippet_migration?
2020-04-08 14:13:33 +05:30
super
2020-05-24 23:13:21 +05:30
2020-04-08 14:13:33 +05:30
return false unless snippet
return false unless can_do_action?(:update_snippet)
true
end
def can_merge_to_branch?(ref)
false
end
2020-05-24 23:13:21 +05:30
def snippet_migration?
user&.migration_bot? && snippet
end
2020-04-08 14:13:33 +05:30
end
end