mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
FIX: do not log personal message view if there exists a similar log in previous hour
This commit is contained in:
parent
12706c4b29
commit
f862122978
@ -496,7 +496,10 @@ class TopicView
|
||||
raise Discourse::InvalidAccess.new("can't see #{@topic}", @topic) unless @guardian.can_see?(@topic)
|
||||
# log personal message views
|
||||
if SiteSetting.log_personal_messages_views && @topic.present? && @topic.private_message? && @topic.all_allowed_users.where(id: @user.id).blank?
|
||||
StaffActionLogger.new(@user).log_check_personal_message(@topic)
|
||||
last_pm_log = UserHistory.where(acting_user_id: @user.id, action: UserHistory.actions[:check_personal_message], topic_id: @topic.id).last
|
||||
unless last_pm_log.present? && last_pm_log.created_at > 1.hour.ago
|
||||
StaffActionLogger.new(@user).log_check_personal_message(@topic)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -143,6 +143,16 @@ describe TopicView do
|
||||
expect { TopicView.new(private_message.id, Fabricate(:user)) }.to raise_error(Discourse::InvalidAccess)
|
||||
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(0)
|
||||
end
|
||||
|
||||
it "does not log personal message view if there exists a similar log in previous hour" do
|
||||
2.times { TopicView.new(private_message.id, evil_trout) }
|
||||
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(1)
|
||||
|
||||
freeze_time (2.hours.from_now)
|
||||
|
||||
TopicView.new(private_message.id, evil_trout)
|
||||
expect(UserHistory.where(action: UserHistory.actions[:check_personal_message]).count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it "provides an absolute url" do
|
||||
|
Loading…
Reference in New Issue
Block a user