Commit 116a6647 authored by Victor Zagorodny's avatar Victor Zagorodny Committed by Grzegorz Bizon

Add UI for "Group Overview default" preference in User Settings

parent 930d7b14
......@@ -33,12 +33,12 @@ class Profiles::PreferencesController < Profiles::ApplicationController
end
def preferences_params
params.require(:user).permit(
:color_scheme_id,
:layout,
:dashboard,
:project_view,
:theme_id
)
params.require(:user).permit(preferences_param_names)
end
def preferences_param_names
[:color_scheme_id, :layout, :dashboard, :project_view, :theme_id]
end
end
Profiles::PreferencesController.prepend(::EE::Profiles::PreferencesController)
......@@ -36,7 +36,7 @@
%span
= _('Activity')
= render_if_exists 'groups/sidebar/security_dashboard'
= render_if_exists 'groups/sidebar/security_dashboard' # EE-specific
- if group_sidebar_link?(:contribution_analytics)
= nav_link(path: 'analytics#show') do
......
......@@ -51,6 +51,9 @@
= f.label :dashboard, class: 'label-bold' do
Default dashboard
= f.select :dashboard, dashboard_choices, {}, class: 'form-control'
= render_if_exists 'profiles/preferences/group_overview_selector', f: f # EE-specific
.form-group
= f.label :project_view, class: 'label-bold' do
Project overview content
......
......@@ -3106,6 +3106,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do
t.integer "roadmap_layout", limit: 2
t.boolean "include_private_contributions"
t.string "commit_email"
t.integer "group_view"
t.index ["accepted_term_id"], name: "index_users_on_accepted_term_id", using: :btree
t.index ["admin"], name: "index_users_on_admin", using: :btree
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
......
# frozen_string_literal: true
module EE::Profiles::PreferencesController
extend ::Gitlab::Utils::Override
override :preferences_param_names
def preferences_param_names
super + preferences_param_names_ee
end
def preferences_param_names_ee
License.feature_available?(:security_dashboard) ? %i[group_view] : []
end
end
......@@ -10,5 +10,17 @@ module EE
super
end
def group_view_choices
choices = [
[_('Details (default)'), :details]
]
if License.feature_available?(:security_dashboard)
choices << [_('Security dashboard'), :security_dashboard]
end
choices
end
end
end
......@@ -12,6 +12,7 @@ module EE
include AuditorUserHelper
DEFAULT_ROADMAP_LAYOUT = 'months'.freeze
DEFAULT_GROUP_VIEW = 'details'.freeze
prepended do
EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM = 1
......@@ -61,6 +62,10 @@ module EE
accepts_nested_attributes_for :namespace
enum roadmap_layout: { weeks: 1, months: 4, quarters: 12 }
# User's Group preference
# Note: When adding an option, it's value MUST equal to the last value + 1.
enum group_view: { details: 1, security_dashboard: 2 }, _prefix: true
end
class_methods do
......@@ -154,6 +159,10 @@ module EE
super || DEFAULT_ROADMAP_LAYOUT
end
def group_view
super || DEFAULT_GROUP_VIEW
end
override :several_namespaces?
def several_namespaces?
union_sql = ::Gitlab::SQL::Union.new(
......
.form-group
= f.label :group_view, class: 'label-bold' do
= _('Group overview content')
= f.select :group_view, group_view_choices, {}, class: 'form-control'
.form-text.text-muted
= _('Choose what content you want to see on a group’s overview page')
# frozen_string_literal: true
class AddGroupViewToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :group_view, :integer
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Profiles::PreferencesController do
let(:user) { create(:user) }
before do
sign_in(user)
end
describe 'PATCH update' do
subject { patch :update, params: { user: { group_view: group_view } }, format: :js }
let(:group_view) { 'security_dashboard' }
context 'when security dashboard feature enabled' do
before do
stub_licensed_features(security_dashboard: true)
end
context 'and valid group view choice is submitted' do
it "changes the user's preferences" do
expect { subject }.to change { user.reload.group_view_security_dashboard? }.from(false).to(true)
end
context 'and an invalid group view choice is submitted' do
let(:group_view) { 'foo' }
it 'sets the flash' do
subject
expect(flash[:alert]).to match(/Failed to save preferences/)
end
end
end
end
context 'when security dashboard feature is disabled' do
context 'when security dashboard feature enabled' do
it do
expect { subject }.not_to change { user.reload.group_view_security_dashboard? }
end
end
end
end
end
......@@ -3,13 +3,13 @@
require 'spec_helper'
describe PreferencesHelper do
describe '#dashboard_choices' do
let(:user) { build(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
before do
allow(helper).to receive(:current_user).and_return(user)
end
let(:user) { build(:user) }
describe '#dashboard_choices' do
context 'when allowed to read operations dashboard' do
before do
allow(helper).to receive(:can?).with(user, :read_operations_dashboard) { true }
......@@ -30,4 +30,20 @@ describe PreferencesHelper do
end
end
end
describe '#group_view_choices' do
subject { helper.group_view_choices }
context 'when security dashboard feature is enabled' do
before do
stub_licensed_features(security_dashboard: true)
end
it { is_expected.to include(['Security dashboard', :security_dashboard]) }
end
context 'when security dashboard feature is disabled' do
it { is_expected.not_to include(['Security dashboard', :security_dashboard]) }
end
end
end
require 'spec_helper'
describe EE::User do
describe 'user creation' do
describe 'with defaults' do
let(:user) { User.new }
it "applies defaults to user" do
expect(user.group_view).to eq('details')
end
end
end
describe 'associations' do
subject { build(:user) }
......
......@@ -1768,6 +1768,9 @@ msgstr ""
msgid "Choose the top-level group for your repository imports."
msgstr ""
msgid "Choose what content you want to see on a group’s overview page"
msgstr ""
msgid "Choose which groups you wish to synchronize to this secondary node."
msgstr ""
......@@ -3191,6 +3194,9 @@ msgstr ""
msgid "Details"
msgstr ""
msgid "Details (default)"
msgstr ""
msgid "Detect host keys"
msgstr ""
......@@ -4709,6 +4715,9 @@ msgstr ""
msgid "Group name"
msgstr ""
msgid "Group overview content"
msgstr ""
msgid "Group:"
msgstr ""
......@@ -8268,6 +8277,9 @@ msgstr ""
msgid "Security Reports|While it's rare to have no vulnerabilities for your group, it can happen. In any event, we ask that you please double check your settings to make sure you've set up your dashboard correctly."
msgstr ""
msgid "Security dashboard"
msgstr ""
msgid "SecurityDashboard| The security dashboard displays the latest security report. Use it to find and fix vulnerabilities."
msgstr ""
......
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