Commit 18a1e9a7 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '7048_add_preference_ui_for_group_overview_be' into 'master'

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

See merge request gitlab-org/gitlab-ee!9332
parents 930d7b14 116a6647
...@@ -33,12 +33,12 @@ class Profiles::PreferencesController < Profiles::ApplicationController ...@@ -33,12 +33,12 @@ class Profiles::PreferencesController < Profiles::ApplicationController
end end
def preferences_params def preferences_params
params.require(:user).permit( params.require(:user).permit(preferences_param_names)
:color_scheme_id, end
:layout,
:dashboard, def preferences_param_names
:project_view, [:color_scheme_id, :layout, :dashboard, :project_view, :theme_id]
:theme_id
)
end end
end end
Profiles::PreferencesController.prepend(::EE::Profiles::PreferencesController)
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
%span %span
= _('Activity') = _('Activity')
= render_if_exists 'groups/sidebar/security_dashboard' = render_if_exists 'groups/sidebar/security_dashboard' # EE-specific
- if group_sidebar_link?(:contribution_analytics) - if group_sidebar_link?(:contribution_analytics)
= nav_link(path: 'analytics#show') do = nav_link(path: 'analytics#show') do
......
...@@ -51,6 +51,9 @@ ...@@ -51,6 +51,9 @@
= f.label :dashboard, class: 'label-bold' do = f.label :dashboard, class: 'label-bold' do
Default dashboard Default dashboard
= f.select :dashboard, dashboard_choices, {}, class: 'form-control' = f.select :dashboard, dashboard_choices, {}, class: 'form-control'
= render_if_exists 'profiles/preferences/group_overview_selector', f: f # EE-specific
.form-group .form-group
= f.label :project_view, class: 'label-bold' do = f.label :project_view, class: 'label-bold' do
Project overview content Project overview content
......
...@@ -3106,6 +3106,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do ...@@ -3106,6 +3106,7 @@ ActiveRecord::Schema.define(version: 20190131122559) do
t.integer "roadmap_layout", limit: 2 t.integer "roadmap_layout", limit: 2
t.boolean "include_private_contributions" t.boolean "include_private_contributions"
t.string "commit_email" t.string "commit_email"
t.integer "group_view"
t.index ["accepted_term_id"], name: "index_users_on_accepted_term_id", using: :btree 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 ["admin"], name: "index_users_on_admin", using: :btree
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, 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 ...@@ -10,5 +10,17 @@ module EE
super super
end 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
end end
...@@ -12,6 +12,7 @@ module EE ...@@ -12,6 +12,7 @@ module EE
include AuditorUserHelper include AuditorUserHelper
DEFAULT_ROADMAP_LAYOUT = 'months'.freeze DEFAULT_ROADMAP_LAYOUT = 'months'.freeze
DEFAULT_GROUP_VIEW = 'details'.freeze
prepended do prepended do
EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM = 1 EMAIL_OPT_IN_SOURCE_ID_GITLAB_COM = 1
...@@ -61,6 +62,10 @@ module EE ...@@ -61,6 +62,10 @@ module EE
accepts_nested_attributes_for :namespace accepts_nested_attributes_for :namespace
enum roadmap_layout: { weeks: 1, months: 4, quarters: 12 } 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 end
class_methods do class_methods do
...@@ -154,6 +159,10 @@ module EE ...@@ -154,6 +159,10 @@ module EE
super || DEFAULT_ROADMAP_LAYOUT super || DEFAULT_ROADMAP_LAYOUT
end end
def group_view
super || DEFAULT_GROUP_VIEW
end
override :several_namespaces? override :several_namespaces?
def several_namespaces? def several_namespaces?
union_sql = ::Gitlab::SQL::Union.new( 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 @@ ...@@ -3,13 +3,13 @@
require 'spec_helper' require 'spec_helper'
describe PreferencesHelper do describe PreferencesHelper do
describe '#dashboard_choices' do
let(:user) { build(:user) }
before do before do
allow(helper).to receive(:current_user).and_return(user) allow(helper).to receive(:current_user).and_return(user)
end end
let(:user) { build(:user) }
describe '#dashboard_choices' do
context 'when allowed to read operations dashboard' do context 'when allowed to read operations dashboard' do
before do before do
allow(helper).to receive(:can?).with(user, :read_operations_dashboard) { true } allow(helper).to receive(:can?).with(user, :read_operations_dashboard) { true }
...@@ -30,4 +30,20 @@ describe PreferencesHelper do ...@@ -30,4 +30,20 @@ describe PreferencesHelper do
end end
end 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 end
require 'spec_helper' require 'spec_helper'
describe EE::User do 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 describe 'associations' do
subject { build(:user) } subject { build(:user) }
......
...@@ -1768,6 +1768,9 @@ msgstr "" ...@@ -1768,6 +1768,9 @@ msgstr ""
msgid "Choose the top-level group for your repository imports." msgid "Choose the top-level group for your repository imports."
msgstr "" 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." msgid "Choose which groups you wish to synchronize to this secondary node."
msgstr "" msgstr ""
...@@ -3191,6 +3194,9 @@ msgstr "" ...@@ -3191,6 +3194,9 @@ msgstr ""
msgid "Details" msgid "Details"
msgstr "" msgstr ""
msgid "Details (default)"
msgstr ""
msgid "Detect host keys" msgid "Detect host keys"
msgstr "" msgstr ""
...@@ -4709,6 +4715,9 @@ msgstr "" ...@@ -4709,6 +4715,9 @@ msgstr ""
msgid "Group name" msgid "Group name"
msgstr "" msgstr ""
msgid "Group overview content"
msgstr ""
msgid "Group:" msgid "Group:"
msgstr "" msgstr ""
...@@ -8268,6 +8277,9 @@ 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." 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 "" msgstr ""
msgid "Security dashboard"
msgstr ""
msgid "SecurityDashboard| The security dashboard displays the latest security report. Use it to find and fix vulnerabilities." msgid "SecurityDashboard| The security dashboard displays the latest security report. Use it to find and fix vulnerabilities."
msgstr "" 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