Commit 9c662234 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dz-disable-packages-per-project' into 'master'

Allow disable packages feature per project

See merge request gitlab-org/gitlab-ee!6977
parents 093cc906 b9e7b254
......@@ -37,6 +37,11 @@
required: false,
default: false,
},
packagesAvailable: {
type: Boolean,
required: false,
default: false,
},
visibilityHelpPath: {
type: String,
required: false,
......@@ -52,6 +57,11 @@
required: false,
default: '',
},
packagesHelpPath: {
type: String,
required: false,
default: '',
},
},
data() {
......@@ -66,6 +76,7 @@
snippetsAccessLevel: 20,
containerRegistryEnabled: true,
lfsEnabled: true,
packagesEnabled: true,
requestAccessEnabled: true,
highlightChangesClass: false,
};
......@@ -131,12 +142,14 @@
if (value === 0) {
this.containerRegistryEnabled = false;
this.lfsEnabled = false;
this.packagesEnabled = false;
}
} else if (oldValue === 0) {
this.mergeRequestsAccessLevel = value;
this.buildsAccessLevel = value;
this.containerRegistryEnabled = true;
this.lfsEnabled = true;
this.packagesEnabled = true;
}
},
......@@ -302,6 +315,18 @@
name="project[lfs_enabled]"
/>
</project-setting-row>
<project-setting-row
v-if="packagesAvailable"
:help-path="packagesHelpPath"
label="Packages"
help-text="Every project can have its own space to store its Maven packages"
>
<project-feature-toggle
v-model="packagesEnabled"
:disabled-input="!repositoryEnabled"
name="project[packages_enabled]"
/>
</project-setting-row>
</div>
<project-setting-row
label="Wiki"
......
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180816193530) do
ActiveRecord::Schema.define(version: 20180823132905) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -2229,6 +2229,7 @@ ActiveRecord::Schema.define(version: 20180816193530) do
t.boolean "mirror_overwrites_diverged_branches"
t.boolean "pages_https_only", default: true
t.string "external_webhook_token"
t.boolean "packages_enabled"
end
add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree
......
......@@ -22,6 +22,7 @@ module EE
external_authorization_classification_label
ci_cd_only
use_custom_template
packages_enabled
]
if allow_mirror_params?
......
......@@ -28,6 +28,21 @@ module EE
nav_tabs
end
override :project_permissions_settings
def project_permissions_settings(project)
super.merge(
packagesEnabled: !!project.packages_enabled
)
end
override :project_permissions_panel_data
def project_permissions_panel_data(project)
super.merge(
packagesAvailable: ::Gitlab.config.packages.enabled,
packagesHelpPath: help_page_path('user/project/maven_packages')
)
end
override :default_url_to_repo
def default_url_to_repo(project = @project)
case default_clone_protocol
......
......@@ -82,6 +82,8 @@ module EE
validates :import_url, presence: true
validates :mirror_user, presence: true
end
default_value_for :packages_enabled, true
end
module ClassMethods
......@@ -538,6 +540,15 @@ module EE
Feature.enabled?('protected_environments') && feature_available?(:protected_environments)
end
# Because we use default_value_for we need to be sure
# packages_enabled= method does exist even if we rollback migration.
# Otherwise many tests from spec/migrations will fail.
def packages_enabled=(value)
if has_attribute?(:packages_enabled)
write_attribute(:packages_enabled, value)
end
end
private
def set_override_pull_mirror_available
......
......@@ -23,6 +23,9 @@ module EE
with_scope :subject
condition(:deploy_board_disabled) { !@subject.feature_available?(:deploy_board) }
with_scope :subject
condition(:packages_disabled) { !@subject.packages_enabled }
with_scope :subject
condition(:classification_label_authorized, score: 32) do
EE::Gitlab::ExternalAuthorization.access_allowed?(
......@@ -110,6 +113,10 @@ module EE
rule { deploy_board_disabled & ~is_development }.prevent :read_deploy_board
rule { packages_disabled }.policy do
prevent(*create_read_update_admin_destroy(:package))
end
rule { can?(:maintainer_access) }.policy do
enable :push_code_to_protected_branches
enable :admin_path_locks
......
# frozen_string_literal: true
class AddPackagesEnabledToProject < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :projects, :packages_enabled, :boolean
end
end
require 'rails_helper'
describe 'Projects > Settings > Packages', :js do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
sign_in(user)
project.add_maintainer(user)
end
context 'Packages enabled in config' do
before do
allow(Gitlab.config.packages).to receive(:enabled).and_return(true)
end
it 'displays the packages toggle button' do
visit edit_project_path(project)
expect(page).to have_content('Packages')
expect(page).to have_selector('input[name="project[packages_enabled]"] + button', visible: true)
end
end
context 'Packages disabled in config' do
before do
allow(Gitlab.config.packages).to receive(:enabled).and_return(false)
end
it 'does not show up in UI' do
visit edit_project_path(project)
expect(page).not_to have_content('Packages')
end
end
end
......@@ -1757,4 +1757,10 @@ describe Project do
end
end
end
describe '#packages_enabled' do
subject { create(:project).packages_enabled }
it { is_expected.to be true }
end
end
......@@ -119,6 +119,7 @@ excluded_attributes:
- :mirror_overwrites_diverged_branches
- :description_html
- :repository_languages
- :packages_enabled
snippets:
- :expired_at
merge_request_diff:
......
......@@ -177,7 +177,7 @@ describe 'Edit Project Settings' do
click_button "Save changes"
end
expect(find(".sharing-permissions")).to have_selector(".project-feature-toggle.is-disabled", count: 2)
expect(find(".sharing-permissions")).to have_selector(".project-feature-toggle.is-disabled", count: 3)
end
it "shows empty features project homepage" do
......
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