diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb index 0c9e6c115..fc6bfdf10 100644 --- a/app/services/staff_action_logger.rb +++ b/app/services/staff_action_logger.rb @@ -143,20 +143,12 @@ class StaffActionLogger })) end - def log_show_emails(users) + def log_show_emails(users, opts={}) return if users.blank? - - values = [] - - users.each do |user| - values << "(#{@admin.id}, #{UserHistory.actions[:check_email]}, #{user.id}, current_timestamp, current_timestamp)" - end - - # bulk insert - UserHistory.exec_sql <<-SQL - INSERT INTO user_histories (acting_user_id, action, target_user_id, created_at, updated_at) - VALUES #{values.join(",")} - SQL + UserHistory.create(params(opts).merge({ + action: UserHistory.actions[:check_email], + details: users.map { |u| "[#{u.id}] #{u.username}"}.join("\n") + })) end def log_impersonate(user, opts={}) diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 954bd8031..31271da27 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -33,13 +33,13 @@ describe Admin::UsersController do end end - it "logs an enty for all email shown" do + it "logs only 1 enty" do UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 0 xhr :get, :index, show_emails: "true" data = ::JSON.parse(response.body) - UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == data.length + UserHistory.where(action: UserHistory.actions[:check_email], acting_user_id: @user.id).count.should == 1 end end