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