Commit bc508f91 authored by Markus Koller's avatar Markus Koller

Remove '@' from Snippet.full_path

We originally added this out of concern that the `snippets` component
in the path could clash with groups or projects named `snippets`, which
we allow for projects and child groups, and only forbid for toplevel
groups.

But we already use the path without '@' for SSH/HTTP clone URLs, and
also include the snippet ID, so this change should be unlikely to cause
problems in practice.

This also makes snippets more consistent with the other `HasRepository`
classes, and allows us to remove some special handling for snippets.
parent 0a13f744
......@@ -293,9 +293,7 @@ class Snippet < ApplicationRecord
@storage ||= Storage::Hashed.new(self, prefix: Storage::Hashed::SNIPPET_REPOSITORY_PATH_PREFIX)
end
# This is the full_path used to identify the
# the snippet repository. It will be used mostly
# for logging purposes.
# This is the full_path used to identify the the snippet repository.
override :full_path
def full_path
return unless persisted?
......@@ -303,7 +301,7 @@ class Snippet < ApplicationRecord
@full_path ||= begin
components = []
components << project.full_path if project_id?
components << '@snippets'
components << 'snippets'
components << self.id
components.join('/')
end
......
......@@ -20,23 +20,6 @@ module Geo
false
end
# Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed
# this method can be removed
def jwt_authentication_header
authorization = ::Gitlab::Geo::RepoSyncRequest.new(
scope: repository.full_path.sub('@snippets', 'snippets')
).authorization
{ "http.#{remote_url}.extraHeader" => "Authorization: #{authorization}" }
end
# Once https://gitlab.com/gitlab-org/gitlab/-/issues/213021 is fixed
# this method can be removed
def remote_url
url = Gitlab::Geo.primary_node.repository_url(repository)
url.sub('@snippets', 'snippets')
end
def repository
model_record.repository
end
......
......@@ -4,9 +4,6 @@ module Gitlab
module RepositoryUrlBuilder
class << self
def build(path, protocol: :ssh)
# TODO: See https://gitlab.com/gitlab-org/gitlab/-/issues/213021
path = path.sub('@snippets', 'snippets')
case protocol
when :ssh
ssh_url(path)
......
......@@ -20,9 +20,8 @@ RSpec.describe PersonalSnippet do
it_behaves_like 'model with repository' do
let_it_be(:container) { create(:personal_snippet, :repository) }
let(:stubbed_container) { build_stubbed(:personal_snippet) }
let(:expected_full_path) { "@snippets/#{container.id}" }
let(:expected_full_path) { "snippets/#{container.id}" }
let(:expected_web_url_path) { "-/snippets/#{container.id}" }
let(:expected_repo_url_path) { "snippets/#{container.id}" }
end
describe '#parent_user' do
......
......@@ -36,8 +36,7 @@ RSpec.describe ProjectSnippet do
it_behaves_like 'model with repository' do
let_it_be(:container) { create(:project_snippet, :repository) }
let(:stubbed_container) { build_stubbed(:project_snippet) }
let(:expected_full_path) { "#{container.project.full_path}/@snippets/#{container.id}" }
let(:expected_full_path) { "#{container.project.full_path}/snippets/#{container.id}" }
let(:expected_web_url_path) { "#{container.project.full_path}/-/snippets/#{container.id}" }
let(:expected_repo_url_path) { "#{container.project.full_path}/snippets/#{container.id}" }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment