Commit c243c99f authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Add `base_url` to Static Site Editor payload

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/213282

Base_url is required for the Vue router.
parent 55432f0f
-# TODO: Remove after base URL is included in the model !30735
- data = @config.payload.merge({ base_url: namespace_project_show_sse_path })
#static-site-editor{ data: data }
#static-site-editor{ data: @config.payload }
......@@ -22,7 +22,8 @@ module Gitlab
project: project.path,
namespace: project.namespace.path,
return_url: return_url,
is_supported_content: supported_content?.to_s
is_supported_content: supported_content?.to_s,
base_url: Gitlab::Routing.url_helpers.project_show_sse_path(project, full_path)
}
end
......@@ -47,6 +48,10 @@ module Gitlab
def file_exists?
commit_id.present? && repository.blob_at(commit_id, file_path).present?
end
def full_path
"#{ref}/#{file_path}"
end
end
end
end
......@@ -5,9 +5,10 @@ require 'spec_helper'
describe Gitlab::StaticSiteEditor::Config do
subject(:config) { described_class.new(repository, ref, file_path, return_url) }
let(:project) { create(:project, :public, :repository, name: 'project', namespace: namespace) }
let(:namespace) { create(:namespace, name: 'namespace') }
let(:repository) { project.repository }
let_it_be(:namespace) { create(:namespace, name: 'namespace') }
let_it_be(:project) { create(:project, :public, :repository, name: 'project', namespace: namespace) }
let_it_be(:repository) { project.repository }
let(:ref) { 'master' }
let(:file_path) { 'README.md' }
let(:return_url) { 'http://example.com' }
......@@ -24,10 +25,17 @@ describe Gitlab::StaticSiteEditor::Config do
project: 'project',
project_id: project.id,
return_url: 'http://example.com',
is_supported_content: 'true'
is_supported_content: 'true',
base_url: '/namespace/project/-/sse/master%2FREADME.md'
)
end
context 'when file path is nested' do
let(:file_path) { 'lib/README.md' }
it { is_expected.to include(base_url: '/namespace/project/-/sse/master%2Flib%2FREADME.md') }
end
context 'when branch is not master' do
let(:ref) { 'my-branch' }
......@@ -53,7 +61,7 @@ describe Gitlab::StaticSiteEditor::Config do
end
context 'when repository is empty' do
let(:project) { create(:project_empty_repo) }
let(:repository) { create(:project_empty_repo).repository }
it { is_expected.to include(is_supported_content: 'false') }
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