2020-02-27 10:09:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class UserAccessSnippet < UserAccess
|
2020-07-21 14:09:45 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
2020-02-27 10:09:24 -05:00
|
|
|
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
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
alias_method :snippet, :container
|
2020-02-27 10:09:24 -05:00
|
|
|
|
|
|
|
def initialize(user, snippet: nil)
|
2020-07-21 14:09:45 -04:00
|
|
|
super(user, container: snippet)
|
2020-02-27 10:09:24 -05:00
|
|
|
@project = snippet&.project
|
|
|
|
end
|
|
|
|
|
2020-05-06 14:09:38 -04:00
|
|
|
def allowed?
|
|
|
|
return true if snippet_migration?
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2020-02-27 10:09:24 -05:00
|
|
|
def can_do_action?(action)
|
2020-05-06 14:09:38 -04:00
|
|
|
return true if snippet_migration?
|
2020-02-27 10:09:24 -05:00
|
|
|
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-06 14:09:38 -04:00
|
|
|
return true if snippet_migration?
|
2020-02-27 10:09:24 -05:00
|
|
|
return false unless snippet
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
can_do_action?(:update_snippet)
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def can_merge_to_branch?(ref)
|
|
|
|
false
|
|
|
|
end
|
2020-05-06 14:09:38 -04:00
|
|
|
|
|
|
|
def snippet_migration?
|
|
|
|
user&.migration_bot? && snippet
|
|
|
|
end
|
2020-07-21 14:09:45 -04:00
|
|
|
|
|
|
|
override :project
|
|
|
|
attr_reader :project
|
2020-02-27 10:09:24 -05:00
|
|
|
end
|
|
|
|
end
|