Commit e6fb06fb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move admin cohorts to separate controller

Separate cohorts logic from users controller. But keep cohorts as a tab
under admin/users page.
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>

Changelog: changed
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent b6d04632
# frozen_string_literal: true # frozen_string_literal: true
class Admin::CohortsController < Admin::ApplicationController class Admin::CohortsController < Admin::ApplicationController
include Analytics::UniqueVisitsHelper
feature_category :devops_reports feature_category :devops_reports
# Backwards compatibility. Remove it and routing in 14.0
# @see https://gitlab.com/gitlab-org/gitlab/-/issues/299303
def index def index
redirect_to cohorts_admin_users_path @cohorts = load_cohorts
track_cohorts_visit
end
private
def load_cohorts
cohorts_results = Rails.cache.fetch('cohorts', expires_in: 1.day) do
CohortsService.new.execute
end
CohortsSerializer.new.represent(cohorts_results)
end
def track_cohorts_visit
if request.format.html? && request.headers['DNT'] != '1'
track_visit('i_analytics_cohorts')
end
end end
end end
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
class Admin::UsersController < Admin::ApplicationController class Admin::UsersController < Admin::ApplicationController
include RoutableActions include RoutableActions
include Analytics::UniqueVisitsHelper
before_action :user, except: [:index, :cohorts, :new, :create] before_action :user, except: [:index, :new, :create]
before_action :check_impersonation_availability, only: :impersonate before_action :check_impersonation_availability, only: :impersonate
before_action :ensure_destroy_prerequisites_met, only: [:destroy] before_action :ensure_destroy_prerequisites_met, only: [:destroy]
before_action :check_ban_user_feature_flag, only: [:ban] before_action :check_ban_user_feature_flag, only: [:ban]
...@@ -14,7 +13,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -14,7 +13,7 @@ class Admin::UsersController < Admin::ApplicationController
PAGINATION_WITH_COUNT_LIMIT = 1000 PAGINATION_WITH_COUNT_LIMIT = 1000
def index def index
return redirect_to cohorts_admin_users_path if params[:tab] == 'cohorts' return redirect_to admin_cohorts_path if params[:tab] == 'cohorts'
@users = User.filter_items(params[:filter]).order_name_asc @users = User.filter_items(params[:filter]).order_name_asc
@users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present? @users = @users.search_with_secondary_emails(params[:search_query]) if params[:search_query].present?
...@@ -24,11 +23,6 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -24,11 +23,6 @@ class Admin::UsersController < Admin::ApplicationController
@users = @users.without_count if paginate_without_count? @users = @users.without_count if paginate_without_count?
end end
def cohorts
@cohorts = load_cohorts
track_cohorts_visit
end
def show def show
end end
...@@ -376,20 +370,6 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -376,20 +370,6 @@ class Admin::UsersController < Admin::ApplicationController
def log_impersonation_event def log_impersonation_event
Gitlab::AppLogger.info(_("User %{current_user_username} has started impersonating %{username}") % { current_user_username: current_user.username, username: user.username }) Gitlab::AppLogger.info(_("User %{current_user_username} has started impersonating %{username}") % { current_user_username: current_user.username, username: user.username })
end end
def load_cohorts
cohorts_results = Rails.cache.fetch('cohorts', expires_in: 1.day) do
CohortsService.new.execute
end
CohortsSerializer.new.represent(cohorts_results)
end
def track_cohorts_visit
if request.format.html? && request.headers['DNT'] != '1'
track_visit('i_analytics_cohorts')
end
end
end end
Admin::UsersController.prepend_mod_with('Admin::UsersController') Admin::UsersController.prepend_mod_with('Admin::UsersController')
- page_title _("Users") - page_title _("Users")
= render 'tabs' = render 'admin/users/tabs'
.tab-content .tab-content
.tab-pane.active .tab-pane.active
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
%a.nav-link{ href: admin_users_path, class: active_when(current_page?(admin_users_path)), role: 'tab' } %a.nav-link{ href: admin_users_path, class: active_when(current_page?(admin_users_path)), role: 'tab' }
= s_('AdminUsers|Users') = s_('AdminUsers|Users')
%li.nav-item{ role: 'presentation' } %li.nav-item{ role: 'presentation' }
%a.nav-link{ href: cohorts_admin_users_path, class: active_when(current_page?(cohorts_admin_users_path)), role: 'tab' } %a.nav-link{ href: admin_cohorts_path, class: active_when(current_page?(admin_cohorts_path)), role: 'tab' }
= s_('AdminUsers|Cohorts') = s_('AdminUsers|Cohorts')
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
%span.sidebar-context-title %span.sidebar-context-title
= _('Admin Area') = _('Admin Area')
%ul.sidebar-top-level-items{ data: { qa_selector: 'admin_sidebar_overview_submenu_content' } } %ul.sidebar-top-level-items{ data: { qa_selector: 'admin_sidebar_overview_submenu_content' } }
= nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers), html_options: {class: 'home'}) do = nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers cohorts), html_options: {class: 'home'}) do
= link_to admin_root_path, class: 'has-sub-items' do = link_to admin_root_path, class: 'has-sub-items' do
.nav-icon-container .nav-icon-container
= sprite_icon('overview') = sprite_icon('overview')
%span.nav-item-name %span.nav-item-name
= _('Overview') = _('Overview')
%ul.sidebar-sub-level-items %ul.sidebar-sub-level-items
= nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers), html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: %w(dashboard admin admin/projects users groups jobs runners gitaly_servers cohorts), html_options: { class: "fly-out-top-item" } ) do
= link_to admin_root_path do = link_to admin_root_path do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
= _('Overview') = _('Overview')
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
= link_to admin_projects_path, title: _('Projects') do = link_to admin_projects_path, title: _('Projects') do
%span %span
= _('Projects') = _('Projects')
= nav_link(controller: :users) do = nav_link(controller: %w(users cohorts)) do
= link_to admin_users_path, title: _('Users'), data: { qa_selector: 'users_overview_link' } do = link_to admin_users_path, title: _('Users'), data: { qa_selector: 'users_overview_link' } do
%span %span
= _('Users') = _('Users')
......
...@@ -10,12 +10,6 @@ namespace :admin do ...@@ -10,12 +10,6 @@ namespace :admin do
end end
end end
collection do
scope '/-/' do
get :cohorts
end
end
member do member do
get :projects get :projects
get :keys get :keys
......
...@@ -9,9 +9,9 @@ RSpec.describe Admin::CohortsController do ...@@ -9,9 +9,9 @@ RSpec.describe Admin::CohortsController do
sign_in(user) sign_in(user)
end end
it 'redirects to Overview->Users' do describe 'GET #index' do
get :index it_behaves_like 'tracking unique visits', :index do
let(:target_id) { 'i_analytics_cohorts' }
expect(response).to redirect_to(cohorts_admin_users_path) end
end end
end end
...@@ -54,12 +54,6 @@ RSpec.describe Admin::UsersController do ...@@ -54,12 +54,6 @@ RSpec.describe Admin::UsersController do
end end
end end
describe 'GET #cohorts' do
it_behaves_like 'tracking unique visits', :cohorts do
let(:target_id) { 'i_analytics_cohorts' }
end
end
describe 'GET :id' do describe 'GET :id' do
it 'finds a user case-insensitively' do it 'finds a user case-insensitively' do
user = create(:user, username: 'CaseSensitive') user = create(:user, username: 'CaseSensitive')
......
...@@ -15,7 +15,7 @@ RSpec.describe "Admin::Users" do ...@@ -15,7 +15,7 @@ RSpec.describe "Admin::Users" do
let(:active_tab_selector) { '.nav-link.active' } let(:active_tab_selector) { '.nav-link.active' }
it 'links to the Users tab' do it 'links to the Users tab' do
visit cohorts_admin_users_path visit admin_cohorts_path
within tabs_selector do within tabs_selector do
click_link 'Users' click_link 'Users'
...@@ -35,14 +35,14 @@ RSpec.describe "Admin::Users" do ...@@ -35,14 +35,14 @@ RSpec.describe "Admin::Users" do
expect(page).to have_selector active_tab_selector, text: 'Cohorts' expect(page).to have_selector active_tab_selector, text: 'Cohorts'
end end
expect(page).to have_current_path(cohorts_admin_users_path) expect(page).to have_current_path(admin_cohorts_path)
expect(page).to have_selector active_tab_selector, text: 'Cohorts' expect(page).to have_selector active_tab_selector, text: 'Cohorts'
end end
it 'redirects legacy route' do it 'redirects legacy route' do
visit admin_users_path(tab: 'cohorts') visit admin_users_path(tab: 'cohorts')
expect(page).to have_current_path(cohorts_admin_users_path) expect(page).to have_current_path(admin_cohorts_path)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment