FEATURE: whispers available for groups (#17170)

Before, whispers were only available for staff members.

Config has been changed to allow to configure privileged groups with access to whispers. Post migration was added to move from the old setting into the new one.

I considered having a boolean column `whisperer` on user model similar to `admin/moderator` for performance reason. Finally, I decided to keep looking for groups as queries are only done for current user and didn't notice any N+1 queries.
This commit is contained in:
Krzysztof Kotlarek
2022-06-30 10:18:12 +10:00
committed by GitHub
parent f44eb13236
commit 09932738e5
40 changed files with 275 additions and 56 deletions

View File

@ -4,8 +4,9 @@ require 'unread'
describe Unread do
let (:user) { Fabricate.build(:user, id: 1) }
let (:topic) do
let(:whisperers_group) { Fabricate(:group) }
let(:user) { Fabricate(:user, id: 1, groups: [whisperers_group]) }
let(:topic) do
Fabricate.build(:topic,
posts_count: 13,
highest_staff_post_number: 15,
@ -26,6 +27,7 @@ describe Unread do
describe 'staff counts' do
it 'should correctly return based on staff post number' do
SiteSetting.enable_whispers = true
user.admin = true
topic_user.last_read_post_number = 13
@ -46,11 +48,20 @@ describe Unread do
end
it 'returns the right unread posts for a staff user' do
SiteSetting.enable_whispers = true
SiteSetting.whispers_allowed_groups = ""
user.admin = true
topic_user.last_read_post_number = 10
expect(unread.unread_posts).to eq(5)
end
it 'returns the right unread posts for a whisperer user' do
SiteSetting.enable_whispers = true
SiteSetting.whispers_allowed_groups = "#{whisperers_group.id}"
topic_user.last_read_post_number = 10
expect(unread.unread_posts).to eq(5)
end
it 'should have 0 unread posts if the user has read more posts than exist (deleted)' do
topic_user.last_read_post_number = 14
expect(unread.unread_posts).to eq(0)