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-13 18:08:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 18:08:52 +0300
commit0ab47b994caa80c5587f33dc818626b66cfdafe2 (patch)
tree5ef3976d2f84e3368903a67ba2dbd87a74b9a43c /lib/gitlab/git_access_snippet.rb
parent1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/git_access_snippet.rb')
-rw-r--r--lib/gitlab/git_access_snippet.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gitlab/git_access_snippet.rb b/lib/gitlab/git_access_snippet.rb
new file mode 100644
index 00000000000..d99b9c3fe89
--- /dev/null
+++ b/lib/gitlab/git_access_snippet.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module Gitlab
+ class GitAccessSnippet < GitAccess
+ ERROR_MESSAGES = {
+ snippet_not_found: 'The snippet you were looking for could not be found.',
+ repository_not_found: 'The snippet repository you were looking for could not be found.'
+ }.freeze
+
+ attr_reader :snippet
+
+ def initialize(actor, snippet, protocol, **kwargs)
+ @snippet = snippet
+
+ super(actor, project, protocol, **kwargs)
+ end
+
+ def check(cmd, _changes)
+ unless Feature.enabled?(:version_snippets, user)
+ raise NotFoundError, ERROR_MESSAGES[:snippet_not_found]
+ end
+
+ check_snippet_accessibility!
+
+ success_result(cmd)
+ end
+
+ def project
+ snippet&.project
+ end
+
+ private
+
+ def repository
+ snippet&.repository
+ end
+
+ def check_snippet_accessibility!
+ if snippet.blank?
+ raise NotFoundError, ERROR_MESSAGES[:snippet_not_found]
+ end
+
+ unless repository&.exists?
+ raise NotFoundError, ERROR_MESSAGES[:repository_not_found]
+ end
+ end
+ end
+end