Commit 3ae76f25 authored by Nick Thomas's avatar Nick Thomas

Merge branch '323629-add-admin-users-oncall-schedule-data-to-helper' into 'master'

Add OncallScheduleEntity to users in Admin helper

See merge request gitlab-org/gitlab!59093
parents 421e6c4c e6841e80
...@@ -13,7 +13,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -13,7 +13,7 @@ class Admin::UsersController < Admin::ApplicationController
def index def index
@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?
@users = @users.includes(:authorized_projects) # rubocop: disable CodeReuse/ActiveRecord @users = users_with_included_associations(@users)
@users = @users.sort_by_attribute(@sort = params[:sort]) @users = @users.sort_by_attribute(@sort = params[:sort])
@users = @users.page(params[:page]) @users = @users.page(params[:page])
...@@ -228,6 +228,10 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -228,6 +228,10 @@ class Admin::UsersController < Admin::ApplicationController
protected protected
def users_with_included_associations(users)
users.includes(:authorized_projects) # rubocop: disable CodeReuse/ActiveRecord
end
def admin_making_changes_for_another_user? def admin_making_changes_for_another_user?
user != current_user user != current_user
end end
......
...@@ -30,3 +30,5 @@ module Admin ...@@ -30,3 +30,5 @@ module Admin
end end
end end
end end
Admin::UserEntity.prepend_if_ee('EE::Admin::UserEntity')
...@@ -19,6 +19,11 @@ module EE ...@@ -19,6 +19,11 @@ module EE
private private
override :users_with_included_associations
def users_with_included_associations(users)
super.includes(:oncall_schedules) # rubocop: disable CodeReuse/ActiveRecord
end
override :log_impersonation_event override :log_impersonation_event
def log_impersonation_event def log_impersonation_event
super super
......
# frozen_string_literal: true
module EE
module Admin
module UserEntity
extend ActiveSupport::Concern
prepended do
expose :oncall_schedules, with: ::IncidentManagement::OncallScheduleEntity
def oncall_schedules
object.oncall_schedules.uniq
end
end
end
end
end
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Admin::UserEntity do
let_it_be(:user) { build_stubbed(:user) }
let(:request) { double('request') }
let(:entity) do
described_class.new(user, request: request)
end
describe '#as_json' do
subject { entity.as_json&.keys }
it 'exposes correct attributes' do
is_expected.to include(:oncall_schedules)
end
end
end
...@@ -14,7 +14,7 @@ RSpec.describe Admin::UserEntity do ...@@ -14,7 +14,7 @@ RSpec.describe Admin::UserEntity do
subject { entity.as_json&.keys } subject { entity.as_json&.keys }
it 'exposes correct attributes' do it 'exposes correct attributes' do
is_expected.to contain_exactly( is_expected.to include(
:id, :id,
:name, :name,
:created_at, :created_at,
......
...@@ -9,7 +9,7 @@ RSpec.describe Admin::UserSerializer do ...@@ -9,7 +9,7 @@ RSpec.describe Admin::UserSerializer do
context 'when there is a single object provided' do context 'when there is a single object provided' do
it 'contains important elements for the admin user table' do it 'contains important elements for the admin user table' do
is_expected.to contain_exactly( is_expected.to include(
:id, :id,
:name, :name,
:created_at, :created_at,
......
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