mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: correctly mute likers
FEATURE: disallow all muting of staff
This commit is contained in:
parent
b4b505d45f
commit
cfa511e35d
@ -35,7 +35,8 @@ class PostAlertObserver < ActiveRecord::Observer
|
|||||||
Notification.types[:liked],
|
Notification.types[:liked],
|
||||||
post,
|
post,
|
||||||
display_username: post_action.user.username,
|
display_username: post_action.user.username,
|
||||||
post_action_id: post_action.id
|
post_action_id: post_action.id,
|
||||||
|
user_id: post_action.user_id
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,8 +86,13 @@ class PostAlerter
|
|||||||
# Make sure the user can see the post
|
# Make sure the user can see the post
|
||||||
return unless Guardian.new(user).can_see?(post)
|
return unless Guardian.new(user).can_see?(post)
|
||||||
|
|
||||||
|
notifier_id = opts[:user_id] || post.user_id
|
||||||
|
|
||||||
# apply muting here
|
# apply muting here
|
||||||
return if post.user_id && MutedUser.where(user_id: user.id, muted_user_id: post.user_id).exists?
|
return if notifier_id && MutedUser.where(user_id: user.id, muted_user_id: notifier_id)
|
||||||
|
.joins(:muted_user)
|
||||||
|
.where('NOT admin AND NOT moderator')
|
||||||
|
.exists?
|
||||||
|
|
||||||
# skip if muted on the topic
|
# skip if muted on the topic
|
||||||
return if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:muted]
|
return if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:muted]
|
||||||
|
@ -198,6 +198,28 @@ describe PostAction do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'when a user likes something' do
|
describe 'when a user likes something' do
|
||||||
|
|
||||||
|
it 'should generate notifications correctly' do
|
||||||
|
ActiveRecord::Base.observers.enable :all
|
||||||
|
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||||
|
Notification.count.should == 1
|
||||||
|
|
||||||
|
mutee = Fabricate(:user)
|
||||||
|
|
||||||
|
post = Fabricate(:post)
|
||||||
|
MutedUser.create!(user_id: post.user.id, muted_user_id: mutee.id)
|
||||||
|
PostAction.act(mutee, post, PostActionType.types[:like])
|
||||||
|
|
||||||
|
Notification.count.should == 1
|
||||||
|
|
||||||
|
# you can not mute admin, sorry
|
||||||
|
MutedUser.create!(user_id: post.user.id, muted_user_id: admin.id)
|
||||||
|
PostAction.act(admin, post, PostActionType.types[:like])
|
||||||
|
|
||||||
|
Notification.count.should == 2
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it 'should increase the `like_count` and `like_score` when a user likes something' do
|
it 'should increase the `like_count` and `like_score` when a user likes something' do
|
||||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||||
post.reload
|
post.reload
|
||||||
@ -265,7 +287,7 @@ describe PostAction do
|
|||||||
# A post with no flags has 0 for flag counts
|
# A post with no flags has 0 for flag counts
|
||||||
expect(PostAction.flag_counts_for(post.id)).to eq([0, 0])
|
expect(PostAction.flag_counts_for(post.id)).to eq([0, 0])
|
||||||
|
|
||||||
flag = PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
_flag = PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||||
expect(PostAction.flag_counts_for(post.id)).to eq([0, 1])
|
expect(PostAction.flag_counts_for(post.id)).to eq([0, 1])
|
||||||
|
|
||||||
# If staff takes action, it is ranked higher
|
# If staff takes action, it is ranked higher
|
||||||
@ -367,7 +389,7 @@ describe PostAction do
|
|||||||
|
|
||||||
it "can flag the topic instead of a post" do
|
it "can flag the topic instead of a post" do
|
||||||
post1 = create_post
|
post1 = create_post
|
||||||
post2 = create_post(topic: post1.topic)
|
_post2 = create_post(topic: post1.topic)
|
||||||
post_action = PostAction.act(Fabricate(:user), post1, PostActionType.types[:spam], { flag_topic: true })
|
post_action = PostAction.act(Fabricate(:user), post1, PostActionType.types[:spam], { flag_topic: true })
|
||||||
expect(post_action.targets_topic).to eq(true)
|
expect(post_action.targets_topic).to eq(true)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user