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 @@
class Admin::PushRulesController < Admin::ApplicationController
before_action :check_push_rules_available!
before_action :push_rule
before_action :set_application_setting
respond_to :html
......@@ -46,4 +47,8 @@ class Admin::PushRulesController < Admin::ApplicationController
@push_rule ||= PushRule.find_or_initialize_by(is_sample: true)
end
# rubocop: enable CodeReuse/ActiveRecord
def set_application_setting
@application_setting = ApplicationSetting.current_without_cache
end
end
......@@ -50,6 +50,10 @@ module EE
attrs << :updating_name_disabled_for_users
end
if License.feature_available?(:merge_request_approvers_rules)
attrs += EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes
end
attrs
end
......
......@@ -87,12 +87,18 @@ module EE
end
def self.possible_licensed_attributes
repository_mirror_attributes + %i[
repository_mirror_attributes + merge_request_appovers_rules_attributes +
%i[
email_additional_text
file_template_project_id
default_project_deletion_protection
deletion_adjourned_period
updating_name_disabled_for_users
]
end
def self.merge_request_appovers_rules_attributes
%i[
disable_overriding_approvers_per_merge_request
prevent_merge_requests_author_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"
%h3.page-title
Pre-defined push rules.
%p.light
Rules that define what git pushes are accepted for a project. All newly created projects will use this settings.
- breadcrumb_title _("Push Rules")
- page_title _("Push Rules")
- @content_class = "limit-container-width" unless fluid_layout
%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|
- 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
= render 'merge_request_approvals'
......@@ -217,6 +217,9 @@ module EE
expose(*EE::ApplicationSettingsHelper.repository_mirror_attributes, if: ->(_instance, _options) do
::License.feature_available?(:repository_mirrors)
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 :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) }
......
......@@ -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 :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 :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
......
......@@ -35,6 +35,10 @@ module EE
attrs = attrs.except(:updating_name_disabled_for_users)
end
unless License.feature_available?(:merge_request_approvers_rules)
attrs = attrs.except(*EE::ApplicationSettingsHelper.merge_request_appovers_rules_attributes)
end
attrs
end
end
......
......@@ -133,6 +133,19 @@ describe Admin::ApplicationSettingsController do
it_behaves_like 'settings for licensed features'
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
put :update, params: { application_setting: { repository_size_limit: '100' } }
......
......@@ -163,4 +163,17 @@ describe API::Settings, 'EE Settings' do
it_behaves_like 'settings for licensed features'
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
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