Merge pull request from GHSA-569c-22ff-pj3x

This commit is contained in:
Roman Rizzi 2020-01-16 15:17:16 -03:00 committed by GitHub
parent fe588cc7f8
commit 0c4ac2a7bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View File

@ -509,7 +509,7 @@ class PostAlerter
def notify_users(users, type, post, opts = {}) def notify_users(users, type, post, opts = {})
users = [users] unless users.is_a?(Array) users = [users] unless users.is_a?(Array)
users = users.reject { |u| u.staged? } if post.topic&.private_message? users.reject!(&:staged?) if post.topic&.private_message?
warn_if_not_sidekiq warn_if_not_sidekiq

View File

@ -152,7 +152,9 @@ module TopicGuardian
return authenticated? && topic.all_allowed_users.where(id: @user.id).exists? return authenticated? && topic.all_allowed_users.where(id: @user.id).exists?
end end
can_see_category?(topic.category) category = topic.category
can_see_category?(category) &&
(!category.read_restricted || !is_staged? || topic.user == user)
end end
def can_get_access_to_topic?(topic) def can_get_access_to_topic?(topic)

View File

@ -257,6 +257,28 @@ describe PostAlerter do
end end
expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user], linking_post]) expect(events).to include(event_name: :before_create_notifications_for_users, params: [[user], linking_post])
end end
it "doesn't notify the linked user if the user is staged and the category is restricted" do
staged_user = Fabricate(:staged)
group = Fabricate(:group)
group_member = Fabricate(:user)
group.add(group_member)
private_category = Fabricate(
:private_category, group: group,
email_in: 'test@test.com', email_in_allow_strangers: true
)
staged_user_post = create_post(user: staged_user, category: private_category)
linking = create_post(
user: group_member,
category: private_category,
raw: "my magic topic\n##{Discourse.base_url}#{staged_user_post.url}")
staged_user.reload
expect(staged_user.notifications.where(notification_type: Notification.types[:linked]).count).to eq(0)
end
end end
context '@group mentions' do context '@group mentions' do