2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
RSpec.describe 'Admin mode' do
|
2020-03-13 15:44:24 +05:30
|
|
|
include MobileHelpers
|
2021-09-04 01:27:46 +05:30
|
|
|
include Spec::Support::Helpers::Features::TopNavSpecHelpers
|
2020-03-13 15:44:24 +05:30
|
|
|
include StubENV
|
|
|
|
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
shared_examples 'combined_menu: feature flag examples' do
|
2020-03-13 15:44:24 +05:30
|
|
|
before do
|
2021-06-08 01:23:25 +05:30
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'application setting :admin_mode is enabled', :request_store do
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'when not in admin mode' do
|
|
|
|
it 'has no leave admin mode button' do
|
|
|
|
visit new_admin_session_path
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
page.within('.navbar-sub-nav') do
|
|
|
|
expect(page).not_to have_link(href: destroy_admin_session_path)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'can open pages not in admin scope' do
|
|
|
|
visit new_admin_session_path
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav_projects
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within_top_nav do
|
|
|
|
click_link('Your projects')
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(page).to have_current_path(dashboard_projects_path)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'is necessary to provide credentials again before opening pages in admin scope' do
|
|
|
|
visit general_admin_application_settings_path # admin logged out because not in admin_mode
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(page).to have_current_path(new_admin_session_path)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'can enter admin mode' do
|
|
|
|
visit new_admin_session_path
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
fill_in 'user_password', with: admin.password
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
click_button 'Enter Admin Mode'
|
|
|
|
|
|
|
|
expect(page).to have_current_path(admin_root_path)
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'on a read-only instance' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'can enter admin mode' do
|
|
|
|
visit new_admin_session_path
|
|
|
|
|
|
|
|
fill_in 'user_password', with: admin.password
|
|
|
|
|
|
|
|
click_button 'Enter Admin Mode'
|
|
|
|
|
|
|
|
expect(page).to have_current_path(admin_root_path)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'when in admin_mode' do
|
|
|
|
before do
|
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'contains link to leave admin mode' do
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within_top_nav do
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(page).to have_link(href: destroy_admin_session_path)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'can leave admin mode using main dashboard link', :js do
|
2021-09-04 01:27:46 +05:30
|
|
|
gitlab_disable_admin_mode
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within_top_nav do
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(page).to have_link(href: new_admin_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can leave admin mode using dropdown menu on smaller screens', :js do
|
2021-09-04 01:27:46 +05:30
|
|
|
skip('pending responsive development under :combined_menu feature flag') if Feature.enabled?(:combined_menu, default_enabled: :yaml)
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
resize_screen_xs
|
|
|
|
visit root_dashboard_path
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
find('.header-more').click unless Feature.enabled?(:combined_menu, default_enabled: :yaml)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
gitlab_disable_admin_mode
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
|
|
|
find('.header-more').click unless Feature.enabled?(:combined_menu, default_enabled: :yaml)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(page).to have_link(href: new_admin_session_path)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'can open pages not in admin scope' do
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav_projects
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within_top_nav do
|
|
|
|
click_link('Your projects')
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
expect(page).to have_current_path(dashboard_projects_path)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'nav bar' do
|
|
|
|
it 'shows admin dashboard links on bigger screen' do
|
|
|
|
visit root_dashboard_path
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
link_text = Feature.enabled?(:combined_menu, default_enabled: :yaml) ? 'Admin' : 'Admin Area'
|
|
|
|
expect(page).to have_link(text: link_text, href: admin_root_path, visible: true)
|
|
|
|
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'relocates admin dashboard links to dropdown list on smaller screen', :js do
|
2021-09-04 01:27:46 +05:30
|
|
|
skip('pending responsive development under :combined_menu feature flag') if Feature.enabled?(:combined_menu, default_enabled: :yaml)
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
resize_screen_xs
|
|
|
|
visit root_dashboard_path
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(page).not_to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
find('.header-more').click
|
|
|
|
|
|
|
|
page.within '.navbar' do
|
|
|
|
expect(page).to have_link(text: 'Admin Area', href: admin_root_path, visible: true)
|
|
|
|
expect(page).to have_link(text: 'Leave Admin Mode', href: destroy_admin_session_path, visible: true)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'on a read-only instance' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it 'can leave admin mode', :js do
|
2021-09-04 01:27:46 +05:30
|
|
|
gitlab_disable_admin_mode
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
within_top_nav do
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(page).to have_link(href: new_admin_session_path)
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
context 'application setting :admin_mode is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(admin_mode: false)
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows no admin mode buttons in navbar' do
|
|
|
|
visit admin_root_path
|
2021-09-04 01:27:46 +05:30
|
|
|
open_top_nav
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(page).not_to have_link(href: new_admin_session_path)
|
|
|
|
expect(page).not_to have_link(href: destroy_admin_session_path)
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
context 'with combined_menu feature flag on', :js do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:needs_rewrite_for_combined_menu_flag_on) { true }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
before do
|
2021-06-08 01:23:25 +05:30
|
|
|
stub_feature_flags(combined_menu: true)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
it_behaves_like 'combined_menu: feature flag examples'
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
context 'with combined_menu feature flag off' do
|
|
|
|
let(:needs_rewrite_for_combined_menu_flag_on) { false }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(combined_menu: false)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it_behaves_like 'combined_menu: feature flag examples'
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|