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],
|
||||
post,
|
||||
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
|
||||
|
||||
|
|
|
@ -86,8 +86,13 @@ class PostAlerter
|
|||
# Make sure the user can see the post
|
||||
return unless Guardian.new(user).can_see?(post)
|
||||
|
||||
notifier_id = opts[:user_id] || post.user_id
|
||||
|
||||
# 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
|
||||
return if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:muted]
|
||||
|
|
|
@ -198,6 +198,28 @@ describe PostAction do
|
|||
end
|
||||
|
||||
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
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
|
@ -265,7 +287,7 @@ describe PostAction do
|
|||
# A post with no flags has 0 for flag counts
|
||||
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])
|
||||
|
||||
# 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
|
||||
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 })
|
||||
expect(post_action.targets_topic).to eq(true)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue