Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 18:09:24 +0300
commitf8d15ca65390475e356b06dedc51e10ccd179f86 (patch)
treeef916d4e8e11c9e00d809e5cdcf63814e86d6e89 /lib/gitlab/user_access_snippet.rb
parent3ab4feda4dce9c9f0672375ae27c2f7c2ba6f4ad (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/user_access_snippet.rb')
-rw-r--r--lib/gitlab/user_access_snippet.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/gitlab/user_access_snippet.rb b/lib/gitlab/user_access_snippet.rb
new file mode 100644
index 00000000000..bfed86c4df4
--- /dev/null
+++ b/lib/gitlab/user_access_snippet.rb
@@ -0,0 +1,49 @@
+# 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
+
+ def can_do_action?(action)
+ 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)
+ super
+ return false unless snippet
+ return false unless can_do_action?(:update_snippet)
+
+ true
+ end
+
+ def can_merge_to_branch?(ref)
+ false
+ end
+ end
+end