Commit 0c07b9d5 authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Add settings form

Add working forn

Add specs to the new settings

Add new settings to setting api
parent aac228bb
import initSettingsPanels from '~/settings_panels';
document.addEventListener('DOMContentLoaded', () => {
// Initialize expandable settings panels
initSettingsPanels();
});
This diff is collapsed.
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class Admin::PushRulesController < Admin::ApplicationController class Admin::PushRulesController < Admin::ApplicationController
before_action :check_push_rules_available! before_action :check_push_rules_available!
before_action :push_rule before_action :push_rule
before_action :set_application_setting
respond_to :html respond_to :html
...@@ -46,4 +47,8 @@ class Admin::PushRulesController < Admin::ApplicationController ...@@ -46,4 +47,8 @@ class Admin::PushRulesController < Admin::ApplicationController
@push_rule ||= PushRule.find_or_initialize_by(is_sample: true) @push_rule ||= PushRule.find_or_initialize_by(is_sample: true)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def set_application_setting
@application_setting = ApplicationSetting.current_without_cache
end
end end
...@@ -50,6 +50,10 @@ module EE ...@@ -50,6 +50,10 @@ module EE
attrs << :updating_name_disabled_for_users attrs << :updating_name_disabled_for_users
end end
if License.feature_available?(:merge_request_approvers_rules)
attrs += EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes
end
attrs attrs
end end
......
...@@ -87,12 +87,18 @@ module EE ...@@ -87,12 +87,18 @@ module EE
end end
def self.possible_licensed_attributes def self.possible_licensed_attributes
repository_mirror_attributes + %i[ repository_mirror_attributes + merge_request_appovers_rules_attributes +
%i[
email_additional_text email_additional_text
file_template_project_id file_template_project_id
default_project_deletion_protection default_project_deletion_protection
deletion_adjourned_period deletion_adjourned_period
updating_name_disabled_for_users updating_name_disabled_for_users
]
end
def self.merge_request_appovers_rules_attributes
%i[
disable_overriding_approvers_per_merge_request disable_overriding_approvers_per_merge_request
prevent_merge_requests_author_approval prevent_merge_requests_author_approval
prevent_merge_requests_committers_approval prevent_merge_requests_committers_approval
......
- return unless License.feature_available?(:merge_request_approvers_rules)
%section.settings.merge-request-approval-settings.no-animate#js-visibility-settings{ class: ('expanded' if expanded_by_default?) }
.settings-header
%h4
= _('Merge requests approvals')
%button.btn.js-settings-toggle{ type: 'button' }
= expanded_by_default? ? _('Collapse') : _('Expand')
%p
= _('Settings to prevent self-approval across all projects in the instance. Only an administrator can modify those settings.')
.settings-content
%hr.clearfix
= form_for @application_setting, url: general_admin_application_settings_path(anchor: 'merge-request-approval-settings'), html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting)
%fieldset
.form-group
.form-check
= f.check_box :prevent_merge_requests_author_approval, class: 'form-check-input'
= f.label :prevent_merge_requests_author_approval, class: 'form-check-label' do
= s_('Prevent approval of merge requests by merge request author')
.form-check
= f.check_box :prevent_merge_requests_committers_approval, class: 'form-check-input'
= f.label :prevent_merge_requests_committers_approval, class: 'form-check-label' do
= s_('Prevent approval of merge requests by merge request commiters')
.form-check
= f.check_box :disable_overriding_approvers_per_merge_request , class: 'form-check-input'
= f.label :disable_overriding_approvers_per_merge_request , class: 'form-check-label' do
= s_('Users cannot modify merge request approvers list')
= f.submit _('Save changes'), class: "btn btn-success"
= form_for @push_rule, url: admin_push_rule_path, method: :put, html: { class: 'fieldset-form' } do |f|
- if @push_rule.errors.any?
.alert.alert-danger
- @push_rule.errors.full_messages.each do |msg|
%p= msg
= render "shared/push_rules/form", f: f
- page_title "Push Rules" - breadcrumb_title _("Push Rules")
%h3.page-title - page_title _("Push Rules")
Pre-defined push rules. - @content_class = "limit-container-width" unless fluid_layout
%p.light
Rules that define what git pushes are accepted for a project. All newly created projects will use this settings.
%hr.clearfix %section.settings.no-animate#js-visibility-settings{ class: ('expanded' if expanded_by_default?) }
.settings-header
%h4
= _('Push Rules')
%button.btn.js-settings-toggle{ type: 'button' }
= expanded_by_default? ? _('Collapse') : _('Expand')
%p
= _('Rules that define what git pushes are accepted for a project. All newly created projects will use this settings.')
.settings-content
= render 'push_rules'
= form_for @push_rule, url: admin_push_rule_path, method: :put do |f| = render 'merge_request_approvals'
- if @push_rule.errors.any?
.alert.alert-danger
- @push_rule.errors.full_messages.each do |msg|
%p= msg
= render "shared/push_rules/form", f: f
...@@ -217,6 +217,9 @@ module EE ...@@ -217,6 +217,9 @@ module EE
expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: ->(_instance, _options) do expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: ->(_instance, _options) do
::License.feature_available?(:repository_mirrors) ::License.feature_available?(:repository_mirrors)
end) end)
expose(*EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes, if: ->(_instance, _options) do
::License.feature_available?(:merge_request_approvers_rules)
end)
expose :email_additional_text, if: ->(_instance, _opts) { ::License.feature_available?(:email_additional_text) } expose :email_additional_text, if: ->(_instance, _opts) { ::License.feature_available?(:email_additional_text) }
expose :file_template_project_id, if: ->(_instance, _opts) { ::License.feature_available?(:custom_file_templates) } expose :file_template_project_id, if: ->(_instance, _opts) { ::License.feature_available?(:custom_file_templates) }
expose :default_project_deletion_protection, if: ->(_instance, _opts) { ::License.feature_available?(:default_project_deletion_protection) } expose :default_project_deletion_protection, if: ->(_instance, _opts) { ::License.feature_available?(:default_project_deletion_protection) }
......
...@@ -38,6 +38,9 @@ module EE ...@@ -38,6 +38,9 @@ module EE
optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.' optional :repository_storages, type: Array[String], desc: 'A list of names of enabled storage paths, taken from `gitlab.yml`. New projects will be created in one of these stores, chosen at random.'
optional :usage_ping_enabled, type: Grape::API::Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.' optional :usage_ping_enabled, type: Grape::API::Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
optional :updating_name_disabled_for_users, type: Grape::API::Boolean, desc: 'Flag indicating if users are permitted to update their profile name' optional :updating_name_disabled_for_users, type: Grape::API::Boolean, desc: 'Flag indicating if users are permitted to update their profile name'
optional :disable_overriding_approvers_per_merge_request, type: Grape::API::Boolean, desc: 'Disable Users ability to overwrite approvers in merge requests.'
optional :prevent_merge_requests_author_approval, type: Grape::API::Boolean, desc: 'Disable Merge request author ability to approve request.'
optional :prevent_merge_requests_committers_approval, type: Grape::API::Boolean, desc: 'Disable Merge request commiter ability to approve request.'
end end
end end
......
...@@ -35,6 +35,10 @@ module EE ...@@ -35,6 +35,10 @@ module EE
attrs = attrs.except(:updating_name_disabled_for_users) attrs = attrs.except(:updating_name_disabled_for_users)
end end
unless License.feature_available?(:merge_request_approvers_rules)
attrs = attrs.except(*EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes)
end
attrs attrs
end end
end end
......
...@@ -133,6 +133,19 @@ describe Admin::ApplicationSettingsController do ...@@ -133,6 +133,19 @@ describe Admin::ApplicationSettingsController do
it_behaves_like 'settings for licensed features' it_behaves_like 'settings for licensed features'
end end
context 'merge request approvers rules' do
let(:settings) do
{
disable_overriding_approvers_per_merge_request: true,
prevent_merge_requests_author_approval: true,
prevent_merge_requests_committers_approval: true
}
end
let(:feature) { :merge_request_approvers_rules }
it_behaves_like 'settings for licensed features'
end
it 'updates repository_size_limit' do it 'updates repository_size_limit' do
put :update, params: { application_setting: { repository_size_limit: '100' } } put :update, params: { application_setting: { repository_size_limit: '100' } }
......
...@@ -163,4 +163,17 @@ describe API::Settings, 'EE Settings' do ...@@ -163,4 +163,17 @@ describe API::Settings, 'EE Settings' do
it_behaves_like 'settings for licensed features' it_behaves_like 'settings for licensed features'
end end
context 'merge request approvers rules' do
let(:settings) do
{
disable_overriding_approvers_per_merge_request: true,
prevent_merge_requests_author_approval: true,
prevent_merge_requests_committers_approval: true
}
end
let(:feature) { :merge_request_approvers_rules }
it_behaves_like 'settings for licensed features'
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