Skip to content
Snippets Groups Projects
Commit ea6fc714 authored by Filipa Lacerda's avatar Filipa Lacerda
Browse files

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!20874
parents 47244ad5 29dd1c14
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Showing
with 232 additions and 27 deletions
Loading
Loading
@@ -71,6 +71,8 @@ Rails.application.routes.draw do
 
get 'ide' => 'ide#index'
get 'ide/*vueroute' => 'ide#index', format: false
draw :instance_statistics
end
 
# Koding route
Loading
Loading
Loading
Loading
@@ -76,8 +76,6 @@ namespace :admin do
resource :system_info, controller: 'system_info', only: [:show]
resources :requests_profiles, only: [:index, :show], param: :name, constraints: { name: /.+\.html/ }
 
get 'conversational_development_index' => 'conversational_development_index#show'
resources :projects, only: [:index]
 
scope(path: 'projects/*namespace_id',
Loading
Loading
@@ -123,8 +121,6 @@ namespace :admin do
end
end
 
resources :cohorts, only: :index
resources :jobs, only: :index do
collection do
post :cancel_all
Loading
Loading
# frozen_string_literal: true
namespace :instance_statistics do
root to: redirect('/-/instance_statistics/conversational_development_index')
resources :cohorts, only: :index
resources :conversational_development_index, only: :index
end
# frozen_string_literal: true
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
Loading
Loading
@@ -168,6 +168,7 @@ ActiveRecord::Schema.define(version: 20180726172057) do
t.boolean "enforce_terms", default: false
t.boolean "mirror_available", default: true, null: false
t.boolean "hide_third_party_offers", default: false, null: false
t.boolean "instance_statistics_visibility_private", default: false, null: false
end
 
create_table "audit_events", force: :cascade do |t|
Loading
Loading
Loading
Loading
@@ -55,7 +55,8 @@ Example response:
"ed25519_key_restriction": 0,
"enforce_terms": true,
"terms": "Hello world!",
"performance_bar_allowed_group_id": 42
"performance_bar_allowed_group_id": 42,
"instance_statistics_visibility_private": false
}
```
 
Loading
Loading
@@ -159,6 +160,7 @@ PUT /application/settings
| `version_check_enabled` | boolean | no | Let GitLab inform you when an update is available. |
| `enforce_terms` | boolean | no | Enforce application ToS to all users |
| `terms` | text | yes (if `enforce_terms` is true) | Markdown content for the ToS |
| `instance_statistics_visibility_private` | boolean | no | When set to `true` Instance statistics will only be available to admins |
 
```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/application/settings?signup_enabled=false&default_project_visibility=internal
Loading
Loading
@@ -203,6 +205,7 @@ Example response:
"ed25519_key_restriction": 0,
"enforce_terms": true,
"terms": "Hello world!",
"performance_bar_allowed_group_id": 42
"performance_bar_allowed_group_id": 42,
"instance_statistics_visibility_private": false
}
```
Loading
Loading
@@ -127,9 +127,7 @@ module API
optional :signup_enabled, type: Boolean, desc: 'Flag indicating if sign up is enabled'
optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
optional :usage_ping_enabled, type: Boolean, desc: 'Every week GitLab will report license usage back to GitLab, Inc.'
optional :user_default_external, type: Boolean, desc: 'Newly registered users will by default be external'
optional :user_oauth_applications, type: Boolean, desc: 'Allow users to register any application to use GitLab as an OAuth provider'
optional :version_check_enabled, type: Boolean, desc: 'Let GitLab inform you when an update is available.'
optional :instance_statistics_visibility_private, type: Boolean, desc: 'When set to `true` Instance statistics will only be available to admins'
 
ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
optional :"#{type}_key_restriction",
Loading
Loading
Loading
Loading
@@ -396,6 +396,9 @@ msgstr ""
msgid "All features are enabled for blank projects, from templates, or when importing, but you can disable them afterward in the project settings."
msgstr ""
 
msgid "All users"
msgstr ""
msgid "Allow commits from members who can merge to the target branch."
msgstr ""
 
Loading
Loading
@@ -2991,6 +2994,12 @@ msgstr ""
msgid "Install Runner on Kubernetes"
msgstr ""
 
msgid "Instance Statistics"
msgstr ""
msgid "Instance Statistics visibility"
msgstr ""
msgid "Instance does not support multiple Kubernetes clusters"
msgstr ""
 
Loading
Loading
@@ -3712,6 +3721,9 @@ msgstr ""
msgid "Online IDE integration settings."
msgstr ""
 
msgid "Only admins"
msgstr ""
msgid "Only comments from the following commit are shown below"
msgstr ""
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe InstanceStatistics::CohortsController do
it_behaves_like 'instance statistics availability'
end
# frozen_string_literal: true
require 'spec_helper'
describe InstanceStatistics::ConversationalDevelopmentIndexController do
it_behaves_like 'instance statistics availability'
end
Loading
Loading
@@ -7,32 +7,38 @@ RSpec.describe 'Dashboard Active Tab', :js do
 
shared_examples 'page has active tab' do |title|
it "#{title} tab" do
subject
expect(page).to have_selector('.navbar-sub-nav li.active', count: 1)
expect(find('.navbar-sub-nav li.active')).to have_content(title)
end
end
 
context 'on dashboard projects' do
before do
visit dashboard_projects_path
it_behaves_like 'page has active tab', 'Projects' do
subject { visit dashboard_projects_path }
end
it_behaves_like 'page has active tab', 'Projects'
end
 
context 'on dashboard groups' do
before do
visit dashboard_groups_path
it_behaves_like 'page has active tab', 'Groups' do
subject { visit dashboard_groups_path }
end
it_behaves_like 'page has active tab', 'Groups'
end
 
context 'on activity projects' do
before do
visit activity_dashboard_path
it_behaves_like 'page has active tab', 'Activity' do
subject { visit activity_dashboard_path }
end
end
 
it_behaves_like 'page has active tab', 'Activity'
context 'on instance statistics' do
subject { visit instance_statistics_root_path }
it 'shows Instance Statistics` as active' do
subject
expect(find('.navbar-sub-nav li.active')).to have_link('Instance Statistics')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Showing instance statistics' do
before do
sign_in user if user
end
# Using a path that is publicly accessible
subject { visit explore_projects_path }
context 'for unauthenticated users' do
let(:user) { nil }
it 'does not show the instance statistics link' do
subject
expect(page).not_to have_link('Instance Statistics')
end
end
context 'for regular users' do
let(:user) { create(:user) }
context 'when instance statistics are publicly available' do
before do
stub_application_setting(instance_statistics_visibility_private: false)
end
it 'shows the instance statistics link' do
subject
expect(page).to have_link('Instance Statistics')
end
end
context 'when instance statistics are not publicly available' do
before do
stub_application_setting(instance_statistics_visibility_private: true)
end
it 'shows the instance statistics link' do
subject
expect(page).not_to have_link('Instance Statistics')
end
end
end
context 'for admins' do
let(:user) { create(:admin) }
it 'shows the instance statistics link' do
subject
expect(page).to have_link('Instance Statistics')
end
end
end
require 'rails_helper'
 
describe 'Admin cohorts page' do
describe 'Cohorts page' do
before do
sign_in(create(:admin))
end
Loading
Loading
@@ -8,7 +8,7 @@ describe 'Admin cohorts page' do
it 'See users count per month' do
2.times { create(:user) }
 
visit admin_cohorts_path
visit instance_statistics_cohorts_path
 
expect(page).to have_content("#{Time.now.strftime('%b %Y')} 3 0")
end
Loading
Loading
require 'spec_helper'
 
describe 'Admin Conversational Development Index' do
describe 'Conversational Development Index' do
before do
sign_in(create(:admin))
end
Loading
Loading
@@ -9,7 +9,7 @@ describe 'Admin Conversational Development Index' do
it 'shows empty state' do
stub_application_setting(usage_ping_enabled: false)
 
visit admin_conversational_development_index_path
visit instance_statistics_conversational_development_index_index_path
 
expect(page).to have_content('Usage ping is not enabled')
end
Loading
Loading
@@ -19,7 +19,7 @@ describe 'Admin Conversational Development Index' do
it 'shows empty state' do
stub_application_setting(usage_ping_enabled: true)
 
visit admin_conversational_development_index_path
visit instance_statistics_conversational_development_index_index_path
 
expect(page).to have_content('Data is still calculating')
end
Loading
Loading
@@ -30,7 +30,7 @@ describe 'Admin Conversational Development Index' do
stub_application_setting(usage_ping_enabled: true)
create(:conversational_development_index_metric)
 
visit admin_conversational_development_index_path
visit instance_statistics_conversational_development_index_index_path
 
expect(page).to have_content(
'Issues created per active user 1.2 You 9.3 Lead 13.3%'
Loading
Loading
Loading
Loading
@@ -180,4 +180,38 @@ describe GlobalPolicy do
end
end
end
describe 'read instance statistics' do
context 'regular user' do
it { is_expected.to be_allowed(:read_instance_statistics) }
context 'when instance statistics are set to private' do
before do
stub_application_setting(instance_statistics_visibility_private: true)
end
it { is_expected.not_to be_allowed(:read_instance_statistics) }
end
end
context 'admin' do
let(:current_user) { create(:admin) }
it { is_expected.to be_allowed(:read_instance_statistics) }
context 'when instance statistics are set to private' do
before do
stub_application_setting(instance_statistics_visibility_private: true)
end
it { is_expected.to be_allowed(:read_instance_statistics) }
end
end
context 'anonymous' do
let(:current_user) { nil }
it { is_expected.not_to be_allowed(:read_instance_statistics) }
end
end
end
Loading
Loading
@@ -25,6 +25,7 @@ describe API::Settings, 'Settings' do
expect(json_response['ed25519_key_restriction']).to eq(0)
expect(json_response['circuitbreaker_failure_count_threshold']).not_to be_nil
expect(json_response['performance_bar_allowed_group_id']).to be_nil
expect(json_response['instance_statistics_visibility_private']).to be(false)
expect(json_response).not_to have_key('performance_bar_allowed_group_path')
expect(json_response).not_to have_key('performance_bar_enabled')
end
Loading
Loading
@@ -64,7 +65,8 @@ describe API::Settings, 'Settings' do
circuitbreaker_check_interval: 2,
enforce_terms: true,
terms: 'Hello world!',
performance_bar_allowed_group_path: group.full_path
performance_bar_allowed_group_path: group.full_path,
instance_statistics_visibility_private: true
 
expect(response).to have_gitlab_http_status(200)
expect(json_response['default_projects_limit']).to eq(3)
Loading
Loading
@@ -89,6 +91,7 @@ describe API::Settings, 'Settings' do
expect(json_response['enforce_terms']).to be(true)
expect(json_response['terms']).to eq('Hello world!')
expect(json_response['performance_bar_allowed_group_id']).to eq(group.id)
expect(json_response['instance_statistics_visibility_private']).to be(true)
end
end
 
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe 'Instance Statistics', 'routing' do
include RSpec::Rails::RequestExampleGroup
it "routes '/-/instance_statistics' to conversational development index" do
expect(get('/-/instance_statistics')).to redirect_to('/-/instance_statistics/conversational_development_index')
end
end
# frozen_string_literal: true
shared_examples 'instance statistics availability' do
let(:user) { create(:user) }
before do
sign_in(user)
end
describe 'GET #index' do
it 'is available when the feature is available publicly' do
get :index
expect(response).to have_gitlab_http_status(:success)
end
it 'renders a 404 when the feature is not available publicly' do
stub_application_setting(instance_statistics_visibility_private: true)
get :index
expect(response).to have_gitlab_http_status(:not_found)
end
context 'for admins' do
let(:user) { create(:admin) }
it 'allows access when the feature is not available publicly' do
stub_application_setting(instance_statistics_visibility_private: true)
get :index
expect(response).to have_gitlab_http_status(:success)
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment