FIX: properly omit inactive and silenced users from directory
This commit is contained in:
parent
fb9fadf42c
commit
1abc276451
|
@ -44,7 +44,7 @@ class DirectoryItem < ActiveRecord::Base
|
|||
# Delete records that belonged to users who have been deleted
|
||||
exec_sql "DELETE FROM directory_items
|
||||
USING directory_items di
|
||||
LEFT JOIN users u ON u.id = user_id
|
||||
LEFT JOIN users u ON (u.id = user_id AND u.active AND u.silenced_till IS NULL AND u.id > 0)
|
||||
WHERE di.id = directory_items.id AND
|
||||
u.id IS NULL AND
|
||||
di.period_type = :period_type", period_type: period_types[period_type]
|
||||
|
@ -63,7 +63,7 @@ class DirectoryItem < ActiveRecord::Base
|
|||
0
|
||||
FROM users u
|
||||
LEFT JOIN directory_items di ON di.user_id = u.id AND di.period_type = :period_type
|
||||
WHERE di.id IS NULL AND u.id > 0
|
||||
WHERE di.id IS NULL AND u.id > 0 AND u.silenced_till IS NULL and u.active
|
||||
", period_type: period_types[period_type]
|
||||
|
||||
# Calculate new values and update records
|
||||
|
|
|
@ -18,6 +18,35 @@ describe DirectoryItem do
|
|||
end
|
||||
end
|
||||
|
||||
context 'inactive and silenced users' do
|
||||
it 'removes silenced users correctly' do
|
||||
post = create_post
|
||||
DirectoryItem.refresh_period!(:daily)
|
||||
|
||||
count = DirectoryItem.where(user_id: post.user_id).count
|
||||
expect(count).to eq(1)
|
||||
|
||||
post.user.update_columns(active: false)
|
||||
DirectoryItem.refresh_period!(:daily)
|
||||
|
||||
count = DirectoryItem.where(user_id: post.user_id).count
|
||||
expect(count).to eq(0)
|
||||
|
||||
post.user.update_columns(active: true)
|
||||
DirectoryItem.refresh_period!(:daily)
|
||||
|
||||
count = DirectoryItem.where(user_id: post.user_id).count
|
||||
expect(count).to eq(1)
|
||||
|
||||
post.user.update_columns(silenced_till: 1.year.from_now)
|
||||
DirectoryItem.refresh_period!(:daily)
|
||||
|
||||
count = DirectoryItem.where(user_id: post.user_id).count
|
||||
expect(count).to eq(0)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context 'refresh' do
|
||||
before do
|
||||
UserActionCreator.enable
|
||||
|
|
Loading…
Reference in New Issue