diff options
author | Gilbert Roulot <groulot@gitlab.com> | 2019-03-14 12:55:46 +0000 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2019-03-14 12:55:46 +0000 |
commit | 6ab102a2f832a15c7aae3e4fa74dde6ad08e15db (patch) | |
tree | cb25cf8c16a62e0c50980657fada9a961c1a9c0b | |
parent | b5bf179e6994566265cf91c32bcb264875b79249 (diff) | |
download | gitlab-ce-6ab102a2f832a15c7aae3e4fa74dde6ad08e15db.tar.gz |
Security Dashboard as default view for groups
Add a supporting code to separate groups#show
and groups#details which is required for the
proper implementation of the Group Overview
content and Security Dashboard option for it
-rw-r--r-- | app/assets/javascripts/pages/groups/details/index.js | 5 | ||||
-rw-r--r-- | app/assets/javascripts/pages/groups/shared/group_details.js | 31 | ||||
-rw-r--r-- | app/assets/javascripts/pages/groups/shared/group_tabs.js (renamed from app/assets/javascripts/pages/groups/show/group_tabs.js) | 0 | ||||
-rw-r--r-- | app/assets/javascripts/pages/groups/show/index.js | 27 | ||||
-rw-r--r-- | app/assets/javascripts/pages/users/user_tabs.js | 1 | ||||
-rw-r--r-- | app/controllers/groups_controller.rb | 36 | ||||
-rw-r--r-- | app/helpers/groups_helper.rb | 1 | ||||
-rw-r--r-- | app/views/layouts/nav/sidebar/_group.html.haml | 11 | ||||
-rw-r--r-- | config/routes/group.rb | 1 | ||||
-rw-r--r-- | locale/gitlab.pot | 3 | ||||
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 37 | ||||
-rw-r--r-- | spec/routing/group_routing_spec.rb | 4 |
12 files changed, 116 insertions, 41 deletions
diff --git a/app/assets/javascripts/pages/groups/details/index.js b/app/assets/javascripts/pages/groups/details/index.js new file mode 100644 index 00000000000..3bcaa0f0232 --- /dev/null +++ b/app/assets/javascripts/pages/groups/details/index.js @@ -0,0 +1,5 @@ +import initGroupDetails from '../shared/group_details'; + +document.addEventListener('DOMContentLoaded', () => { + initGroupDetails('details'); +}); diff --git a/app/assets/javascripts/pages/groups/shared/group_details.js b/app/assets/javascripts/pages/groups/shared/group_details.js new file mode 100644 index 00000000000..01ef3f1db2b --- /dev/null +++ b/app/assets/javascripts/pages/groups/shared/group_details.js @@ -0,0 +1,31 @@ +/* eslint-disable no-new */ + +import { getPagePath } from '~/lib/utils/common_utils'; +import { ACTIVE_TAB_SHARED, ACTIVE_TAB_ARCHIVED } from '~/groups/constants'; +import NewGroupChild from '~/groups/new_group_child'; +import notificationsDropdown from '~/notifications_dropdown'; +import NotificationsForm from '~/notifications_form'; +import ProjectsList from '~/projects_list'; +import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation'; +import GroupTabs from './group_tabs'; + +export default function initGroupDetails(actionName = 'show') { + const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup'); + const loadableActions = [ACTIVE_TAB_SHARED, ACTIVE_TAB_ARCHIVED]; + const paths = window.location.pathname.split('/'); + const subpath = paths[paths.length - 1]; + let action = loadableActions.includes(subpath) ? subpath : getPagePath(1); + if (actionName && action === actionName) { + action = 'show'; // 'show' resets GroupTabs to default action through base class + } + + new GroupTabs({ parentEl: '.groups-listing', action }); + new ShortcutsNavigation(); + new NotificationsForm(); + notificationsDropdown(); + new ProjectsList(); + + if (newGroupChildWrapper) { + new NewGroupChild(newGroupChildWrapper); + } +} diff --git a/app/assets/javascripts/pages/groups/show/group_tabs.js b/app/assets/javascripts/pages/groups/shared/group_tabs.js index c6fe61d2bd9..c6fe61d2bd9 100644 --- a/app/assets/javascripts/pages/groups/show/group_tabs.js +++ b/app/assets/javascripts/pages/groups/shared/group_tabs.js diff --git a/app/assets/javascripts/pages/groups/show/index.js b/app/assets/javascripts/pages/groups/show/index.js index 3a45fd70d02..af924e74f1f 100644 --- a/app/assets/javascripts/pages/groups/show/index.js +++ b/app/assets/javascripts/pages/groups/show/index.js @@ -1,28 +1,5 @@ -/* eslint-disable no-new */ - -import { getPagePath } from '~/lib/utils/common_utils'; -import { ACTIVE_TAB_SHARED, ACTIVE_TAB_ARCHIVED } from '~/groups/constants'; -import NewGroupChild from '~/groups/new_group_child'; -import notificationsDropdown from '~/notifications_dropdown'; -import NotificationsForm from '~/notifications_form'; -import ProjectsList from '~/projects_list'; -import ShortcutsNavigation from '~/behaviors/shortcuts/shortcuts_navigation'; -import GroupTabs from './group_tabs'; +import initGroupDetails from '../shared/group_details'; document.addEventListener('DOMContentLoaded', () => { - const newGroupChildWrapper = document.querySelector('.js-new-project-subgroup'); - const loadableActions = [ACTIVE_TAB_SHARED, ACTIVE_TAB_ARCHIVED]; - const paths = window.location.pathname.split('/'); - const subpath = paths[paths.length - 1]; - const action = loadableActions.includes(subpath) ? subpath : getPagePath(1); - - new GroupTabs({ parentEl: '.groups-listing', action }); - new ShortcutsNavigation(); - new NotificationsForm(); - notificationsDropdown(); - new ProjectsList(); - - if (newGroupChildWrapper) { - new NewGroupChild(newGroupChildWrapper); - } + initGroupDetails(); }); diff --git a/app/assets/javascripts/pages/users/user_tabs.js b/app/assets/javascripts/pages/users/user_tabs.js index 636308c5401..7f800d20835 100644 --- a/app/assets/javascripts/pages/users/user_tabs.js +++ b/app/assets/javascripts/pages/users/user_tabs.js @@ -91,6 +91,7 @@ export default class UserTabs { this.actions = Object.keys(this.loaded); this.bindEvents(); + // TODO: refactor to make this configurable via constructor params with a default value of 'show' if (this.action === 'show') { this.action = this.defaultAction; } diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 4e50106398a..0192b1c253e 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -58,11 +58,24 @@ class GroupsController < Groups::ApplicationController def show respond_to do |format| - format.html + format.html do + render_show_html + end format.atom do - load_events - render layout: 'xml.atom' + render_details_view_atom + end + end + end + + def details + respond_to do |format| + format.html do + render_details_html + end + + format.atom do + render_details_view_atom end end end @@ -119,6 +132,19 @@ class GroupsController < Groups::ApplicationController protected + def render_show_html + render 'groups/show' + end + + def render_details_html + render 'groups/show' + end + + def render_details_view_atom + load_events + render layout: 'xml.atom', template: 'groups/show' + end + # rubocop: disable CodeReuse/ActiveRecord def authorize_create_group! allowed = if params[:parent_id].present? @@ -178,8 +204,8 @@ class GroupsController < Groups::ApplicationController .includes(:namespace) @events = EventCollection - .new(@projects, offset: params[:offset].to_i, filter: event_filter) - .to_a + .new(@projects, offset: params[:offset].to_i, filter: event_filter) + .to_a Events::RenderService .new(current_user) diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 4a9ed123161..9d028dccad7 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -4,6 +4,7 @@ module GroupsHelper def group_overview_nav_link_paths %w[ groups#show + groups#details groups#activity groups#subgroups analytics#show diff --git a/app/views/layouts/nav/sidebar/_group.html.haml b/app/views/layouts/nav/sidebar/_group.html.haml index 21ea9f3b2f3..eefe86eb6b4 100644 --- a/app/views/layouts/nav/sidebar/_group.html.haml +++ b/app/views/layouts/nav/sidebar/_group.html.haml @@ -20,13 +20,14 @@ = _('Overview') %ul.sidebar-sub-level-items - = nav_link(path: ['groups#show', 'groups#activity', 'groups#subgroups'], html_options: { class: "fly-out-top-item" } ) do + = nav_link(path: ['groups#show', 'groups#details', 'groups#activity', 'groups#subgroups'], html_options: { class: "fly-out-top-item" } ) do = link_to group_path(@group) do %strong.fly-out-top-item-name = _('Overview') %li.divider.fly-out-top-item - = nav_link(path: ['groups#show', 'groups#subgroups'], html_options: { class: 'home' }) do - = link_to group_path(@group), title: _('Group details') do + + = nav_link(path: ['groups#show', 'groups#details', 'groups#subgroups'], html_options: { class: 'home' }) do + = link_to details_group_path(@group), title: _('Group details') do %span = _('Details') @@ -40,9 +41,9 @@ - if group_sidebar_link?(:contribution_analytics) = nav_link(path: 'analytics#show') do - = link_to group_analytics_path(@group), title: 'Contribution Analytics', data: {placement: 'right'} do + = link_to group_analytics_path(@group), title: _('Contribution Analytics'), data: { placement: 'right' } do %span - Contribution Analytics + = _('Contribution Analytics') = render_if_exists "layouts/nav/ee/epic_link", group: @group diff --git a/config/routes/group.rb b/config/routes/group.rb index f42c1ee6e7d..b300fcb757f 100644 --- a/config/routes/group.rb +++ b/config/routes/group.rb @@ -14,6 +14,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do get :issues, as: :issues_group get :merge_requests, as: :merge_requests_group get :projects, as: :projects_group + get :details, as: :details_group get :activity, as: :activity_group put :transfer, as: :transfer_group # TODO: Remove as part of refactor in https://gitlab.com/gitlab-org/gitlab-ce/issues/49693 diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 29cbf59cee2..d5ad3426c8c 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -2315,6 +2315,9 @@ msgstr "" msgid "Contribution" msgstr "" +msgid "Contribution Analytics" +msgstr "" + msgid "Contribution Charts" msgstr "" diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 21e5122c06b..b2e6df6060a 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -32,21 +32,46 @@ describe GroupsController do end end + shared_examples 'details view' do + it { is_expected.to render_template('groups/show') } + + context 'as atom' do + let!(:event) { create(:event, project: project) } + let(:format) { :atom } + + it { is_expected.to render_template('groups/show') } + + it 'assigns events for all the projects in the group' do + subject + expect(assigns(:events)).to contain_exactly(event) + end + end + end + describe 'GET #show' do before do sign_in(user) project end - context 'as atom' do - it 'assigns events for all the projects in the group' do - create(:event, project: project) + let(:format) { :html } - get :show, params: { id: group.to_param }, format: :atom + subject { get :show, params: { id: group.to_param }, format: format } - expect(assigns(:events)).not_to be_empty - end + it_behaves_like 'details view' + end + + describe 'GET #details' do + before do + sign_in(user) + project end + + let(:format) { :html } + + subject { get :details, params: { id: group.to_param }, format: format } + + it_behaves_like 'details view' end describe 'GET edit' do diff --git a/spec/routing/group_routing_spec.rb b/spec/routing/group_routing_spec.rb index 71788028cbf..53271550e8b 100644 --- a/spec/routing/group_routing_spec.rb +++ b/spec/routing/group_routing_spec.rb @@ -17,6 +17,10 @@ describe "Groups", "routing" do expect(get("/#{group_path}")).to route_to('groups#show', id: group_path) end + it "to #details" do + expect(get("/groups/#{group_path}/-/details")).to route_to('groups#details', id: group_path) + end + it "to #activity" do expect(get("/groups/#{group_path}/-/activity")).to route_to('groups#activity', id: group_path) end |