Commit 049fcae4 authored by Chad Woolley's avatar Chad Woolley Committed by Markus Koller

Redirect deprecated SSE to Web IDE

- Redirect Static Site Editor (SSE) to Web IDE
- Deletes SSE feature spec
- Removal of remaining SSE code will be performed
  in a subsequent MR.

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/80347
parent 71a5063e
......@@ -3,6 +3,7 @@
class Projects::StaticSiteEditorController < Projects::ApplicationController
include ExtractsPath
include CreatesCommit
include BlobHelper
layout 'fullscreen'
......@@ -24,28 +25,7 @@ class Projects::StaticSiteEditorController < Projects::ApplicationController
end
def show
service_response = ::StaticSiteEditor::ConfigService.new(
container: project,
current_user: current_user,
params: {
ref: @ref,
path: @path,
return_url: params[:return_url]
}
).execute
if service_response.success?
Gitlab::UsageDataCounters::StaticSiteEditorCounter.increment_views_count
@data = serialize_necessary_payload_values_to_json(service_response.payload)
else
# TODO: For now, if the service returns any error, the user is redirected
# to the root project page with the error message displayed as an alert.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/213285#note_414808004
# for discussion of plans to handle this via a page owned by the Static Site Editor.
flash[:alert] = service_response.message
redirect_to project_path(project)
end
redirect_to ide_edit_path(project, @ref, @path)
end
private
......
......@@ -76,12 +76,11 @@ RSpec.describe Projects::StaticSiteEditorController do
get :show, params: default_params
end
it 'increases the views counter' do
expect(Gitlab::UsageDataCounters::StaticSiteEditorCounter).to have_received(:increment_views_count)
end
it 'redirects to the Web IDE' do
get :show, params: default_params
it 'renders the edit page' do
expect(response).to render_template(:show)
expected_path_regex = %r[-/ide/project/#{project.full_path}/edit/master/-/README.md]
expect(response).to redirect_to(expected_path_regex)
end
it 'assigns ref and path variables' do
......@@ -96,62 +95,6 @@ RSpec.describe Projects::StaticSiteEditorController do
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when invalid config file' do
let(:service_response) { ServiceResponse.error(message: 'invalid') }
it 'redirects to project page and flashes error message' do
expect(response).to redirect_to(project_path(project))
expect(controller).to set_flash[:alert].to('invalid')
end
end
context 'with a service response payload containing multiple data types' do
let(:data) do
{
a_string: 'string',
an_array: [
{
foo: 'bar'
}
],
an_integer: 123,
a_hash: {
a_deeper_hash: {
foo: 'bar'
}
},
a_boolean: true,
a_nil: nil
}
end
let(:assigns_data) { assigns(:data) }
it 'leaves data values which are strings as strings' do
expect(assigns_data[:a_string]).to eq('string')
end
it 'leaves data values which are integers as integers' do
expect(assigns_data[:an_integer]).to eq(123)
end
it 'serializes data values which are booleans to JSON' do
expect(assigns_data[:a_boolean]).to eq('true')
end
it 'serializes data values which are arrays to JSON' do
expect(assigns_data[:an_array]).to eq('[{"foo":"bar"}]')
end
it 'serializes data values which are hashes to JSON' do
expect(assigns_data[:a_hash]).to eq('{"a_deeper_hash":{"foo":"bar"}}')
end
it 'serializes data values which are nil to an empty string' do
expect(assigns_data[:a_nil]).to eq('')
end
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Static Site Editor' do
include ContentSecurityPolicyHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let(:sse_path) { project_show_sse_path(project, 'master/README.md') }
before_all do
project.add_developer(user)
end
before do
sign_in(user)
end
context "when no config file is present" do
before do
visit sse_path
end
it 'renders SSE page with all generated config values and default config file values' do
node = page.find('#static-site-editor')
# assert generated config values are present
expect(node['data-base-url']).to eq("/#{project.full_path}/-/sse/master%2FREADME.md")
expect(node['data-branch']).to eq('master')
expect(node['data-commit-id']).to match(/\A[0-9a-f]{40}\z/)
expect(node['data-is-supported-content']).to eq('true')
expect(node['data-merge-requests-illustration-path'])
.to match(%r{/assets/illustrations/merge_requests-.*\.svg})
expect(node['data-namespace']).to eq(project.namespace.full_path)
expect(node['data-project']).to eq(project.path)
expect(node['data-project-id']).to eq(project.id.to_s)
# assert default config file values are present
expect(node['data-image-upload-path']).to eq('source/images')
expect(node['data-mounts']).to eq('[{"source":"source","target":""}]')
expect(node['data-static-site-generator']).to eq('middleman')
end
end
context "when a config file is present" do
let(:config_file_yml) do
<<~YAML
image_upload_path: custom-image-upload-path
mounts:
- source: source1
target: ""
- source: source2
target: target2
static_site_generator: middleman
YAML
end
before do
allow_next_instance_of(Repository) do |repository|
allow(repository).to receive(:blob_data_at).and_return(config_file_yml)
end
visit sse_path
end
it 'renders Static Site Editor page values read from config file' do
node = page.find('#static-site-editor')
# assert user-specified config file values are present
expected_mounts = '[{"source":"source1","target":""},{"source":"source2","target":"target2"}]'
expect(node['data-image-upload-path']).to eq('custom-image-upload-path')
expect(node['data-mounts']).to eq(expected_mounts)
expect(node['data-static-site-generator']).to eq('middleman')
end
end
describe 'Static Site Editor Content Security Policy' do
subject { response_headers['Content-Security-Policy'] }
context 'when no global CSP config exists' do
before do
setup_csp_for_controller(Projects::StaticSiteEditorController)
end
it 'does not add CSP directives' do
visit sse_path
is_expected.to be_blank
end
end
context 'when a global CSP config exists' do
let_it_be(:cdn_url) { 'https://some-cdn.test' }
let_it_be(:youtube_url) { 'https://www.youtube.com' }
before do
csp = ActionDispatch::ContentSecurityPolicy.new do |p|
p.frame_src :self, cdn_url
end
setup_existing_csp_for_controller(Projects::StaticSiteEditorController, csp)
end
it 'appends youtube to the CSP frame-src policy' do
visit sse_path
is_expected.to eql("frame-src 'self' #{cdn_url} #{youtube_url}")
end
end
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