FIX: log only 1 'show email' record

This commit is contained in:
Régis Hanol 2014-12-29 11:50:36 +01:00
parent b48f04e772
commit bfbc49ef6f
2 changed files with 7 additions and 15 deletions

View File

@ -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={})

View File

@ -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