diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-07-27 16:03:50 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-07-27 16:03:50 +0300 |
commit | 636ea40e182fca92e89facbcb52445fcefef9506 (patch) | |
tree | c555ba8f65dd8c468c0539b32836ad65f67e731b /app | |
parent | 31044d41a63dd1b8f57df12b864210d84361c219 (diff) | |
parent | a79094b29205929ab78d89e10e768787f7aff7d6 (diff) |
Merge branch '41416-making-instance-wide-data-tools-more-accessible' into 'master'
Resolve "Making instance-wide data tools more accessible"
Closes #41416 and #48507
See merge request gitlab-org/gitlab-ce!20679
Diffstat (limited to 'app')
20 files changed, 74 insertions, 19 deletions
diff --git a/app/controllers/admin/conversational_development_index_controller.rb b/app/controllers/admin/conversational_development_index_controller.rb deleted file mode 100644 index 921169d3e2b..00000000000 --- a/app/controllers/admin/conversational_development_index_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::ConversationalDevelopmentIndexController < Admin::ApplicationController - def show - @metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present - end -end diff --git a/app/controllers/instance_statistics/application_controller.rb b/app/controllers/instance_statistics/application_controller.rb new file mode 100644 index 00000000000..162e311f175 --- /dev/null +++ b/app/controllers/instance_statistics/application_controller.rb @@ -0,0 +1,8 @@ +class InstanceStatistics::ApplicationController < ApplicationController + before_action :authorize_read_instance_statistics! + layout 'instance_statistics' + + def authorize_read_instance_statistics! + render_404 unless can?(current_user, :read_instance_statistics) + end +end diff --git a/app/controllers/admin/cohorts_controller.rb b/app/controllers/instance_statistics/cohorts_controller.rb index 10d9d1b5345..7eba0a5ecdd 100644 --- a/app/controllers/admin/cohorts_controller.rb +++ b/app/controllers/instance_statistics/cohorts_controller.rb @@ -1,4 +1,6 @@ -class Admin::CohortsController < Admin::ApplicationController +# frozen_string_literal: true + +class InstanceStatistics::CohortsController < InstanceStatistics::ApplicationController def index if Gitlab::CurrentSettings.usage_ping_enabled cohorts_results = Rails.cache.fetch('cohorts', expires_in: 1.day) do diff --git a/app/controllers/instance_statistics/conversational_development_index_controller.rb b/app/controllers/instance_statistics/conversational_development_index_controller.rb new file mode 100644 index 00000000000..023ce917e13 --- /dev/null +++ b/app/controllers/instance_statistics/conversational_development_index_controller.rb @@ -0,0 +1,5 @@ +class InstanceStatistics::ConversationalDevelopmentIndexController < InstanceStatistics::ApplicationController + def index + @metric = ConversationalDevelopmentIndex::Metric.order(:created_at).last&.present + end +end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 358b896702b..9e2346177a4 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -247,6 +247,7 @@ module ApplicationSettingsHelper :unique_ips_limit_per_user, :unique_ips_limit_time_window, :usage_ping_enabled, + :instance_statistics_visibility_private, :user_default_external, :user_oauth_applications, :version_check_enabled, diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index f770b219422..01a59039cff 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -290,6 +290,7 @@ class ApplicationSetting < ActiveRecord::Base user_default_external: false, polling_interval_multiplier: 1, usage_ping_enabled: Settings.gitlab['usage_ping_enabled'], + instance_statistics_visibility_private: false, gitaly_timeout_fast: 10, gitaly_timeout_medium: 30, gitaly_timeout_default: 55, diff --git a/app/policies/global_policy.rb b/app/policies/global_policy.rb index 6e3827736b2..16c58730878 100644 --- a/app/policies/global_policy.rb +++ b/app/policies/global_policy.rb @@ -19,6 +19,11 @@ class GlobalPolicy < BasePolicy @user&.required_terms_not_accepted? end + condition(:private_instance_statistics, score: 0) { Gitlab::CurrentSettings.instance_statistics_visibility_private? } + + rule { admin | (~private_instance_statistics & ~anonymous) } + .enable :read_instance_statistics + rule { anonymous }.policy do prevent :log_in prevent :receive_notifications diff --git a/app/views/admin/application_settings/_usage.html.haml b/app/views/admin/application_settings/_usage.html.haml index 49a3ee33a85..860e7765168 100644 --- a/app/views/admin/application_settings/_usage.html.haml +++ b/app/views/admin/application_settings/_usage.html.haml @@ -23,13 +23,16 @@ periodically collect usage information. = link_to 'Learn more', help_page_path("user/admin_area/settings/usage_statistics", anchor: "usage-ping") about what information is shared with GitLab Inc. Visit - = link_to 'Cohorts', admin_cohorts_path(anchor: 'usage-ping') + = link_to 'Cohorts', instance_statistics_cohorts_path(anchor: 'usage-ping') to see the JSON payload sent. - else The usage ping is disabled, and cannot be configured through this form. For more information, see the documentation on = succeed '.' do = link_to 'deactivating the usage ping', help_page_path('user/admin_area/settings/usage_statistics', anchor: 'deactivate-the-usage-ping') + .form-group + = f.label :instance_statistics_visibility_private, 'Instance Statistics visibility' + = f.select :instance_statistics_visibility_private, options_for_select({'All users' => false, 'Only admins' => true}, Gitlab::CurrentSettings.instance_statistics_visibility_private?), {}, class: 'form-control' = f.submit 'Save changes', class: "btn btn-success" diff --git a/app/views/admin/cohorts/_cohorts_table.html.haml b/app/views/instance_statistics/cohorts/_cohorts_table.html.haml index 701a4e62b39..701a4e62b39 100644 --- a/app/views/admin/cohorts/_cohorts_table.html.haml +++ b/app/views/instance_statistics/cohorts/_cohorts_table.html.haml diff --git a/app/views/admin/cohorts/_usage_ping.html.haml b/app/views/instance_statistics/cohorts/_usage_ping.html.haml index 3dda386fcf7..3dda386fcf7 100644 --- a/app/views/admin/cohorts/_usage_ping.html.haml +++ b/app/views/instance_statistics/cohorts/_usage_ping.html.haml diff --git a/app/views/admin/cohorts/index.html.haml b/app/views/instance_statistics/cohorts/index.html.haml index 5e9a8c083af..5e9a8c083af 100644 --- a/app/views/admin/cohorts/index.html.haml +++ b/app/views/instance_statistics/cohorts/index.html.haml diff --git a/app/views/admin/conversational_development_index/_callout.html.haml b/app/views/instance_statistics/conversational_development_index/_callout.html.haml index 33a4dab1e00..33a4dab1e00 100644 --- a/app/views/admin/conversational_development_index/_callout.html.haml +++ b/app/views/instance_statistics/conversational_development_index/_callout.html.haml diff --git a/app/views/admin/conversational_development_index/_card.html.haml b/app/views/instance_statistics/conversational_development_index/_card.html.haml index 57eda06630b..57eda06630b 100644 --- a/app/views/admin/conversational_development_index/_card.html.haml +++ b/app/views/instance_statistics/conversational_development_index/_card.html.haml diff --git a/app/views/admin/conversational_development_index/_disabled.html.haml b/app/views/instance_statistics/conversational_development_index/_disabled.html.haml index 0a741b50960..0a741b50960 100644 --- a/app/views/admin/conversational_development_index/_disabled.html.haml +++ b/app/views/instance_statistics/conversational_development_index/_disabled.html.haml diff --git a/app/views/admin/conversational_development_index/_no_data.html.haml b/app/views/instance_statistics/conversational_development_index/_no_data.html.haml index d69c46194b4..d69c46194b4 100644 --- a/app/views/admin/conversational_development_index/_no_data.html.haml +++ b/app/views/instance_statistics/conversational_development_index/_no_data.html.haml diff --git a/app/views/admin/conversational_development_index/show.html.haml b/app/views/instance_statistics/conversational_development_index/index.html.haml index e3d1aa31dc2..e3d1aa31dc2 100644 --- a/app/views/admin/conversational_development_index/show.html.haml +++ b/app/views/instance_statistics/conversational_development_index/index.html.haml diff --git a/app/views/layouts/instance_statistics.html.haml b/app/views/layouts/instance_statistics.html.haml new file mode 100644 index 00000000000..ec3e01600e5 --- /dev/null +++ b/app/views/layouts/instance_statistics.html.haml @@ -0,0 +1,6 @@ +- page_title "Instance Statistics" +- header_title "Instance Statistics", instance_statistics_root_path +- nav "instance_statistics" +- @left_sidebar = true + += render template: "layouts/application" diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index a71a4b13a7e..0bab2cf3d2a 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -64,11 +64,15 @@ = link_to '#', class: 'dashboard-shortcuts-web-ide', title: _('Web IDE') do = _('Web IDE') - - if current_user.admin? || Gitlab::Sherlock.enabled? + - if Gitlab::Sherlock.enabled? || can?(current_user, :read_instance_statistics) %li.line-separator.d-none.d-sm-block + - if can?(current_user, :read_instance_statistics) + = nav_link(controller: [:conversational_development_index, :cohorts]) do + = link_to instance_statistics_root_path, title: 'Instance Statistics', aria: { label: 'Instance statistics' }, data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do + = sprite_icon('chart', size: 18) - if current_user.admin? = nav_link(controller: 'admin/dashboard') do - = link_to admin_root_path, class: 'admin-icon qa-admin-area-link', title: _('Admin area'), aria: { label: _("Admin area") }, data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do + = link_to admin_root_path, class: 'admin-icon qa-admin-area-link', title: _('Admin area'), aria: { label: "Admin area" }, data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do = sprite_icon('admin', size: 18) - if Gitlab::Sherlock.enabled? %li diff --git a/app/views/layouts/nav/sidebar/_admin.html.haml b/app/views/layouts/nav/sidebar/_admin.html.haml index 0047efa363d..ff25b040913 100644 --- a/app/views/layouts/nav/sidebar/_admin.html.haml +++ b/app/views/layouts/nav/sidebar/_admin.html.haml @@ -7,14 +7,14 @@ .sidebar-context-title = _('Admin Area') %ul.sidebar-top-level-items - = nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers cohorts conversational_development_index), html_options: {class: 'home'}) do + = nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers), html_options: {class: 'home'}) do = link_to admin_root_path, class: 'shortcuts-tree' do .nav-icon-container = sprite_icon('overview') %span.nav-item-name = _('Overview') %ul.sidebar-sub-level-items - = nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers cohorts conversational_development_index), html_options: { class: "fly-out-top-item" } ) do + = nav_link(controller: %w(dashboard admin projects users groups jobs runners gitaly_servers), html_options: { class: "fly-out-top-item" } ) do = link_to admin_root_path do %strong.fly-out-top-item-name = _('Overview') @@ -47,14 +47,6 @@ = link_to admin_gitaly_servers_path, title: 'Gitaly Servers' do %span = _('Gitaly Servers') - = nav_link path: 'cohorts#index' do - = link_to admin_cohorts_path, title: _('Cohorts') do - %span - = _('Cohorts') - = nav_link(controller: :conversational_development_index) do - = link_to admin_conversational_development_index_path, title: _('ConvDev Index') do - %span - = _('ConvDev Index') = nav_link(controller: %w(system_info background_jobs logs health_check requests_profiles)) do = link_to admin_system_info_path do diff --git a/app/views/layouts/nav/sidebar/_instance_statistics.html.haml b/app/views/layouts/nav/sidebar/_instance_statistics.html.haml new file mode 100644 index 00000000000..cb64c97f7b4 --- /dev/null +++ b/app/views/layouts/nav/sidebar/_instance_statistics.html.haml @@ -0,0 +1,33 @@ +.nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } + .nav-sidebar-inner-scroll + .context-header + = link_to instance_statistics_root_path, title: 'Instance Statistics' do + .avatar-container.s40.settings-avatar + = sprite_icon('chart', size: 24) + .sidebar-context-title Instance Statistics + %ul.sidebar-top-level-items + = nav_link(controller: :conversational_development_index) do + = link_to instance_statistics_conversational_development_index_index_path do + .nav-icon-container + = sprite_icon('comment') + %span.nav-item-name + = _('ConvDev Index') + %ul.sidebar-sub-level-items.is-fly-out-only + = nav_link(controller: :conversational_development_index, html_options: { class: "fly-out-top-item" } ) do + = link_to instance_statistics_conversational_development_index_index_path do + %strong.fly-out-top-item-name + = _('ConvDev Index') + + = nav_link(controller: :cohorts) do + = link_to instance_statistics_cohorts_path do + .nav-icon-container + = sprite_icon('users') + %span.nav-item-name + = _('Cohorts') + %ul.sidebar-sub-level-items.is-fly-out-only + = nav_link(controller: :cohorts, html_options: { class: "fly-out-top-item" } ) do + = link_to instance_statistics_cohorts_path do + %strong.fly-out-top-item-name + = _('Cohorts') + + = render 'shared/sidebar_toggle_button' |