diff options
author | Luke Bennett <lukeeeebennettplus@gmail.com> | 2018-07-18 04:41:40 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-26 20:00:10 +0300 |
commit | 866429f7892842c2a29a902eace64efac781019b (patch) | |
tree | 86341514b5c87d2ec8fdc4e15fe3986ac3afd452 | |
parent | f8f2d0f9e18a76324d85ae319a3bb8585ed107d5 (diff) |
Add instance_statistics_visibility_private application setting and top nav icon
6 files changed, 33 insertions, 2 deletions
diff --git a/app/controllers/instance_statistics/application_controller.rb b/app/controllers/instance_statistics/application_controller.rb index fbdce7d0f0d..7c454e15a59 100644 --- a/app/controllers/instance_statistics/application_controller.rb +++ b/app/controllers/instance_statistics/application_controller.rb @@ -7,6 +7,6 @@ class InstanceStatistics::ApplicationController < ApplicationController end def authenticate_user! - render_404 unless current_user.admin? + render_404 if ApplicationSettingsHelper.hide_instance_statistics?(current_user) end end diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 358b896702b..b355008f087 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -15,6 +15,10 @@ module ApplicationSettingsHelper def allowed_protocols_present? Gitlab::CurrentSettings.enabled_git_access_protocol.present? end + + def hide_instance_statistics?(user = current_user) + Gitlab::CurrentSettings.instance_statistics_visibility_private? && !user.admin? + end def enabled_protocol case Gitlab::CurrentSettings.enabled_git_access_protocol @@ -247,6 +251,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/views/admin/application_settings/_usage.html.haml b/app/views/admin/application_settings/_usage.html.haml index 40b5c51ac88..860e7765168 100644 --- a/app/views/admin/application_settings/_usage.html.haml +++ b/app/views/admin/application_settings/_usage.html.haml @@ -30,6 +30,9 @@ 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/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml index a71a4b13a7e..356e52918d9 100644 --- a/app/views/layouts/nav/_dashboard.html.haml +++ b/app/views/layouts/nav/_dashboard.html.haml @@ -70,8 +70,12 @@ = 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 = sprite_icon('admin', size: 18) + - unless hide_instance_statistics? + = nav_link(controller: :instance_statistics) 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 Gitlab::Sherlock.enabled? %li = link_to sherlock_transactions_path, class: 'admin-icon', title: _('Sherlock Transactions'), data: {toggle: 'tooltip', placement: 'bottom', container: 'body'} do - = icon('tachometer fw') + = icon('tachometer fw')
\ No newline at end of file diff --git a/db/migrate/20180718005113_add_instance_statistics_visibility_to_application_setting.rb b/db/migrate/20180718005113_add_instance_statistics_visibility_to_application_setting.rb new file mode 100644 index 00000000000..9d5f4c15eb9 --- /dev/null +++ b/db/migrate/20180718005113_add_instance_statistics_visibility_to_application_setting.rb @@ -0,0 +1,18 @@ +class AddInstanceStatisticsVisibilityToApplicationSetting < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_column_with_default(:application_settings, :instance_statistics_visibility_private, + :boolean, + default: false, + allow_null: false) + end + + def down + remove_column(:application_settings, :instance_statistics_visibility_private) + end +end |