2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 16:52:09 +00:00
|
|
|
module Gitlab
|
2019-04-30 09:37:07 +00:00
|
|
|
class GlRepository
|
|
|
|
include Singleton
|
|
|
|
|
2019-03-18 16:51:11 +00:00
|
|
|
PROJECT = RepoType.new(
|
|
|
|
name: :project,
|
2020-06-09 21:08:21 +00:00
|
|
|
access_checker_class: Gitlab::GitAccessProject,
|
2020-03-05 00:07:49 +00:00
|
|
|
repository_resolver: -> (project) { project&.repository }
|
2019-03-18 16:51:11 +00:00
|
|
|
).freeze
|
|
|
|
WIKI = RepoType.new(
|
|
|
|
name: :wiki,
|
|
|
|
access_checker_class: Gitlab::GitAccessWiki,
|
2020-05-28 09:08:05 +00:00
|
|
|
repository_resolver: -> (container) { container&.wiki&.repository },
|
|
|
|
project_resolver: -> (container) { container.is_a?(Project) ? container : nil },
|
2020-01-27 15:08:51 +00:00
|
|
|
suffix: :wiki
|
2019-03-18 16:51:11 +00:00
|
|
|
).freeze
|
2020-02-13 15:08:52 +00:00
|
|
|
SNIPPET = RepoType.new(
|
|
|
|
name: :snippet,
|
|
|
|
access_checker_class: Gitlab::GitAccessSnippet,
|
2020-03-05 00:07:49 +00:00
|
|
|
repository_resolver: -> (snippet) { snippet&.repository },
|
2020-05-28 09:08:05 +00:00
|
|
|
container_class: Snippet,
|
2020-03-05 00:07:49 +00:00
|
|
|
project_resolver: -> (snippet) { snippet&.project },
|
|
|
|
guest_read_ability: :read_snippet
|
2020-02-13 15:08:52 +00:00
|
|
|
).freeze
|
2020-05-04 06:10:10 +00:00
|
|
|
DESIGN = ::Gitlab::GlRepository::RepoType.new(
|
|
|
|
name: :design,
|
|
|
|
access_checker_class: ::Gitlab::GitAccessDesign,
|
|
|
|
repository_resolver: -> (project) { ::DesignManagement::Repository.new(project) },
|
|
|
|
suffix: :design
|
|
|
|
).freeze
|
2019-03-18 16:51:11 +00:00
|
|
|
|
|
|
|
TYPES = {
|
|
|
|
PROJECT.name.to_s => PROJECT,
|
2020-02-13 15:08:52 +00:00
|
|
|
WIKI.name.to_s => WIKI,
|
2020-05-04 06:10:10 +00:00
|
|
|
SNIPPET.name.to_s => SNIPPET,
|
|
|
|
DESIGN.name.to_s => DESIGN
|
2019-03-18 16:51:11 +00:00
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def self.types
|
2019-04-30 09:37:07 +00:00
|
|
|
instance.types
|
2017-05-03 21:07:54 +00:00
|
|
|
end
|
|
|
|
|
2017-04-28 16:52:09 +00:00
|
|
|
def self.parse(gl_repository)
|
2020-05-28 09:08:05 +00:00
|
|
|
result = ::Gitlab::GlRepository::Identifier.new(gl_repository)
|
2019-03-18 16:51:11 +00:00
|
|
|
|
2020-05-28 09:08:05 +00:00
|
|
|
repo_type = result.repo_type
|
|
|
|
container = result.fetch_container!
|
2017-04-28 16:52:09 +00:00
|
|
|
|
2020-05-28 09:08:05 +00:00
|
|
|
[container, repo_type.project_for(container), repo_type]
|
2017-04-28 16:52:09 +00:00
|
|
|
end
|
2019-04-05 10:51:42 +00:00
|
|
|
|
|
|
|
def self.default_type
|
|
|
|
PROJECT
|
|
|
|
end
|
2019-04-30 09:37:07 +00:00
|
|
|
|
|
|
|
def types
|
|
|
|
TYPES
|
|
|
|
end
|
|
|
|
|
|
|
|
private_class_method :instance
|
2017-04-28 16:52:09 +00:00
|
|
|
end
|
|
|
|
end
|