Commit 455dc74e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'disable-project-export' into 'master'

Add option to disable project export on instance

See merge request !13211
parents 5ab158f5 649d042d
...@@ -7,6 +7,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -7,6 +7,7 @@ class ProjectsController < Projects::ApplicationController
before_action :repository, except: [:index, :new, :create] before_action :repository, except: [:index, :new, :create]
before_action :assign_ref_vars, only: [:show], if: :repo_exists? before_action :assign_ref_vars, only: [:show], if: :repo_exists?
before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?] before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?]
before_action :project_export_enabled, only: [:export, :download_export, :remove_export, :generate_new_export]
# Authorize # Authorize
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export] before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export]
...@@ -390,4 +391,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -390,4 +391,8 @@ class ProjectsController < Projects::ApplicationController
url_for(params) url_for(params)
end end
def project_export_enabled
render_404 unless current_application_settings.project_export_enabled?
end
end end
...@@ -146,6 +146,7 @@ module ApplicationSettingsHelper ...@@ -146,6 +146,7 @@ module ApplicationSettingsHelper
:plantuml_enabled, :plantuml_enabled,
:plantuml_url, :plantuml_url,
:polling_interval_multiplier, :polling_interval_multiplier,
:project_export_enabled,
:prometheus_metrics_enabled, :prometheus_metrics_enabled,
:recaptcha_enabled, :recaptcha_enabled,
:recaptcha_private_key, :recaptcha_private_key,
......
...@@ -241,6 +241,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -241,6 +241,7 @@ class ApplicationSetting < ActiveRecord::Base
performance_bar_allowed_group_id: nil, performance_bar_allowed_group_id: nil,
plantuml_enabled: false, plantuml_enabled: false,
plantuml_url: nil, plantuml_url: nil,
project_export_enabled: true,
recaptcha_enabled: false, recaptcha_enabled: false,
repository_checks_enabled: true, repository_checks_enabled: true,
repository_storages: ['default'], repository_storages: ['default'],
......
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
= select(:application_setting, :enabled_git_access_protocol, [['Both SSH and HTTP(S)', nil], ['Only SSH', 'ssh'], ['Only HTTP(S)', 'http']], {}, class: 'form-control') = select(:application_setting, :enabled_git_access_protocol, [['Both SSH and HTTP(S)', nil], ['Only SSH', 'ssh'], ['Only HTTP(S)', 'http']], {}, class: 'form-control')
%span.help-block#clone-protocol-help %span.help-block#clone-protocol-help
Allow only the selected protocols to be used for Git access. Allow only the selected protocols to be used for Git access.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :project_export_enabled do
= f.check_box :project_export_enabled
Project export enabled
%fieldset %fieldset
%legend Account and Limit Settings %legend Account and Limit Settings
......
- return unless current_application_settings.project_export_enabled?
- project = local_assigns.fetch(:project)
- expanded = Rails.env.test?
%section.settings
.settings-header
%h4
Export project
%button.btn.js-settings-toggle
= expanded ? 'Collapse' : 'Expand'
%p
Export this project with all its related data in order to move your project to a new GitLab instance. Once the export is finished, you can import the file from the "New Project" page.
.settings-content.no-animate{ class: ('expanded' if expanded) }
.bs-callout.bs-callout-info
%p.append-bottom-0
%p
The following items will be exported:
%ul
%li Project and wiki repositories
%li Project uploads
%li Project configuration including web hooks and services
%li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities
%p
The following items will NOT be exported:
%ul
%li Job traces and artifacts
%li LFS objects
%li Container registry images
%li CI variables
%li Any encrypted tokens
%p
Once the exported file is ready, you will receive a notification email with a download link.
- if project.export_project_path
= link_to 'Download export', download_export_project_path(project),
rel: 'nofollow', download: '', method: :get, class: "btn btn-default"
= link_to 'Generate new export', generate_new_export_project_path(project),
method: :post, class: "btn btn-default"
- else
= link_to 'Export project', export_project_path(project),
method: :post, class: "btn btn-default"
...@@ -161,42 +161,7 @@ ...@@ -161,42 +161,7 @@
= render 'merge_request_settings', form: f = render 'merge_request_settings', form: f
= f.submit 'Save changes', class: "btn btn-save" = f.submit 'Save changes', class: "btn btn-save"
%section.settings = render 'export', project: @project
.settings-header
%h4
Export project
%button.btn.js-settings-toggle
= expanded ? 'Collapse' : 'Expand'
%p
Export this project with all its related data in order to move your project to a new GitLab instance. Once the export is finished, you can import the file from the "New Project" page.
.settings-content.no-animate{ class: ('expanded' if expanded) }
.bs-callout.bs-callout-info
%p.append-bottom-0
%p
The following items will be exported:
%ul
%li Project and wiki repositories
%li Project uploads
%li Project configuration including web hooks and services
%li Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities
%p
The following items will NOT be exported:
%ul
%li Job traces and artifacts
%li LFS objects
%li Container registry images
%li CI variables
%li Any encrypted tokens
%p
Once the exported file is ready, you will receive a notification email with a download link.
- if @project.export_project_path
= link_to 'Download export', download_export_project_path(@project),
rel: 'nofollow', download: '', method: :get, class: "btn btn-default"
= link_to 'Generate new export', generate_new_export_project_path(@project),
method: :post, class: "btn btn-default"
- else
= link_to 'Export project', export_project_path(@project),
method: :post, class: "btn btn-default"
%section.settings.advanced-settings %section.settings.advanced-settings
.settings-header .settings-header
......
---
title: Add option to disable project export on instance
merge_request: 13211
author: Robin Bobbitt
class AddProjectExportEnabledToApplicationSettings < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
DOWNTIME = false
def up
add_column_with_default(:application_settings, :project_export_enabled, :boolean, default: true)
end
def down
remove_column(:application_settings, :project_export_enabled)
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170809142252) do ActiveRecord::Schema.define(version: 20170809161910) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170809142252) do ...@@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170809142252) do
t.string "help_page_support_url" t.string "help_page_support_url"
t.integer "performance_bar_allowed_group_id" t.integer "performance_bar_allowed_group_id"
t.boolean "password_authentication_enabled" t.boolean "password_authentication_enabled"
t.boolean "project_export_enabled", default: true, null: false
end end
create_table "audit_events", force: :cascade do |t| create_table "audit_events", force: :cascade do |t|
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
> application settings (`/admin/application_settings`) under 'Import sources'. > application settings (`/admin/application_settings`) under 'Import sources'.
> Ask your administrator if you don't see the **GitLab export** button when > Ask your administrator if you don't see the **GitLab export** button when
> creating a new project. > creating a new project.
> - Starting with GitLab 10.0, administrators can disable the project export option
> on the GitLab instance in application settings (`/admin/application_settings`)
> under 'Visibility and Access Controls'.
> - You can find some useful raketasks if you are an administrator in the > - You can find some useful raketasks if you are an administrator in the
> [import_export](../../../administration/raketasks/project_import_export.md) > [import_export](../../../administration/raketasks/project_import_export.md)
> raketask. > raketask.
......
...@@ -29,6 +29,7 @@ module API ...@@ -29,6 +29,7 @@ module API
desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com' desc: 'Enabled sources for code import during project creation. OmniAuth must be configured for GitHub, Bitbucket, and GitLab.com'
optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources' optional :disabled_oauth_sign_in_sources, type: Array[String], desc: 'Disable certain OAuth sign-in sources'
optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.' optional :enabled_git_access_protocol, type: String, values: %w[ssh http nil], desc: 'Allow only the selected protocols to be used for Git access.'
optional :project_export_enabled, type: Boolean, desc: 'Enable project export'
optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled' optional :gravatar_enabled, type: Boolean, desc: 'Flag indicating if the Gravatar service is enabled'
optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects' optional :default_projects_limit, type: Integer, desc: 'The maximum number of personal projects'
optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB' optional :max_attachment_size, type: Integer, desc: 'Maximum attachment size in MB'
......
...@@ -578,6 +578,118 @@ describe ProjectsController do ...@@ -578,6 +578,118 @@ describe ProjectsController do
end end
end end
describe '#export' do
before do
sign_in(user)
project.add_master(user)
end
context 'when project export is enabled' do
it 'returns 302' do
get :export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(302)
end
end
context 'when project export is disabled' do
before do
stub_application_setting(project_export_enabled?: false)
end
it 'returns 404' do
get :export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(404)
end
end
end
describe '#download_export' do
before do
sign_in(user)
project.add_master(user)
end
context 'when project export is enabled' do
it 'returns 302' do
get :download_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(302)
end
end
context 'when project export is disabled' do
before do
stub_application_setting(project_export_enabled?: false)
end
it 'returns 404' do
get :download_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(404)
end
end
end
describe '#remove_export' do
before do
sign_in(user)
project.add_master(user)
end
context 'when project export is enabled' do
it 'returns 302' do
post :remove_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(302)
end
end
context 'when project export is disabled' do
before do
stub_application_setting(project_export_enabled?: false)
end
it 'returns 404' do
post :remove_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(404)
end
end
end
describe '#generate_new_export' do
before do
sign_in(user)
project.add_master(user)
end
context 'when project export is enabled' do
it 'returns 302' do
post :generate_new_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(302)
end
end
context 'when project export is disabled' do
before do
stub_application_setting(project_export_enabled?: false)
end
it 'returns 404' do
post :generate_new_export, namespace_id: project.namespace, id: project
expect(response).to have_http_status(404)
end
end
end
def project_moved_message(redirect_route, project) def project_moved_message(redirect_route, project)
"Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path." "Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path."
end end
......
...@@ -35,6 +35,7 @@ feature 'Admin updates settings' do ...@@ -35,6 +35,7 @@ feature 'Admin updates settings' do
fill_in 'Help page text', with: 'Example text' fill_in 'Help page text', with: 'Example text'
check 'Hide marketing-related entries from help' check 'Hide marketing-related entries from help'
fill_in 'Support page URL', with: 'http://example.com/help' fill_in 'Support page URL', with: 'http://example.com/help'
uncheck 'Project export enabled'
click_button 'Save' click_button 'Save'
expect(current_application_settings.gravatar_enabled).to be_falsey expect(current_application_settings.gravatar_enabled).to be_falsey
...@@ -42,6 +43,7 @@ feature 'Admin updates settings' do ...@@ -42,6 +43,7 @@ feature 'Admin updates settings' do
expect(current_application_settings.help_page_text).to eq "Example text" expect(current_application_settings.help_page_text).to eq "Example text"
expect(current_application_settings.help_page_hide_commercial_content).to be_truthy expect(current_application_settings.help_page_hide_commercial_content).to be_truthy
expect(current_application_settings.help_page_support_url).to eq "http://example.com/help" expect(current_application_settings.help_page_support_url).to eq "http://example.com/help"
expect(current_application_settings.project_export_enabled).to be_falsey
expect(page).to have_content "Application settings saved successfully" expect(page).to have_content "Application settings saved successfully"
end end
......
...@@ -43,7 +43,9 @@ describe API::Settings, 'Settings' do ...@@ -43,7 +43,9 @@ describe API::Settings, 'Settings' do
default_artifacts_expire_in: '2 days', default_artifacts_expire_in: '2 days',
help_page_text: 'custom help text', help_page_text: 'custom help text',
help_page_hide_commercial_content: true, help_page_hide_commercial_content: true,
help_page_support_url: 'http://example.com/help' help_page_support_url: 'http://example.com/help',
project_export_enabled: false
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response['default_projects_limit']).to eq(3) expect(json_response['default_projects_limit']).to eq(3)
expect(json_response['password_authentication_enabled']).to be_falsey expect(json_response['password_authentication_enabled']).to be_falsey
...@@ -58,6 +60,7 @@ describe API::Settings, 'Settings' do ...@@ -58,6 +60,7 @@ describe API::Settings, 'Settings' do
expect(json_response['help_page_text']).to eq('custom help text') expect(json_response['help_page_text']).to eq('custom help text')
expect(json_response['help_page_hide_commercial_content']).to be_truthy expect(json_response['help_page_hide_commercial_content']).to be_truthy
expect(json_response['help_page_support_url']).to eq('http://example.com/help') expect(json_response['help_page_support_url']).to eq('http://example.com/help')
expect(json_response['project_export_enabled']).to be_falsey
end end
end end
......
...@@ -11,14 +11,26 @@ describe 'projects/edit' do ...@@ -11,14 +11,26 @@ describe 'projects/edit' do
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
allow(view).to receive_messages(current_user: user, can?: true) allow(view).to receive_messages(current_user: user, can?: true)
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end end
context 'LFS enabled setting' do context 'LFS enabled setting' do
it 'displays the correct elements' do it 'displays the correct elements' do
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
render render
expect(rendered).to have_select('project_lfs_enabled') expect(rendered).to have_select('project_lfs_enabled')
expect(rendered).to have_content('Git Large File Storage') expect(rendered).to have_content('Git Large File Storage')
end end
end end
context 'project export disabled' do
it 'does not display the project export option' do
stub_application_setting(project_export_enabled?: false)
render
expect(rendered).not_to have_content('Export project')
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