mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 20:08:26 +00:00
FIX: Do not change tracked categories for staged users (#10076)
This commit is contained in:
parent
d13d5e2b99
commit
a1df68d4c4
@ -61,7 +61,7 @@ class Admin::SiteSettingsController < Admin::AdminController
|
|||||||
(new_category_ids - previous_category_ids).each do |category_id|
|
(new_category_ids - previous_category_ids).each do |category_id|
|
||||||
skip_user_ids = CategoryUser.where(category_id: category_id).pluck(:user_id)
|
skip_user_ids = CategoryUser.where(category_id: category_id).pluck(:user_id)
|
||||||
|
|
||||||
User.where.not(id: skip_user_ids).select(:id).find_in_batches do |users|
|
User.real.where(staged: false).where.not(id: skip_user_ids).select(:id).find_in_batches do |users|
|
||||||
category_users = []
|
category_users = []
|
||||||
users.each { |user| category_users << { category_id: category_id, user_id: user.id, notification_level: notification_level } }
|
users.each { |user| category_users << { category_id: category_id, user_id: user.id, notification_level: notification_level } }
|
||||||
CategoryUser.insert_all!(category_users)
|
CategoryUser.insert_all!(category_users)
|
||||||
@ -88,7 +88,7 @@ class Admin::SiteSettingsController < Admin::AdminController
|
|||||||
(new_tag_ids - previous_tag_ids).each do |tag_id|
|
(new_tag_ids - previous_tag_ids).each do |tag_id|
|
||||||
skip_user_ids = TagUser.where(tag_id: tag_id).pluck(:user_id)
|
skip_user_ids = TagUser.where(tag_id: tag_id).pluck(:user_id)
|
||||||
|
|
||||||
User.where.not(id: skip_user_ids).select(:id).find_in_batches do |users|
|
User.real.where(staged: false).where.not(id: skip_user_ids).select(:id).find_in_batches do |users|
|
||||||
tag_users = []
|
tag_users = []
|
||||||
users.each { |user| tag_users << { tag_id: tag_id, user_id: user.id, notification_level: notification_level, created_at: now, updated_at: now } }
|
users.each { |user| tag_users << { tag_id: tag_id, user_id: user.id, notification_level: notification_level, created_at: now, updated_at: now } }
|
||||||
TagUser.insert_all!(tag_users)
|
TagUser.insert_all!(tag_users)
|
||||||
@ -135,8 +135,10 @@ class Admin::SiteSettingsController < Admin::AdminController
|
|||||||
|
|
||||||
user_ids = CategoryUser.where(category_id: previous_category_ids - new_category_ids, notification_level: notification_level).distinct.pluck(:user_id)
|
user_ids = CategoryUser.where(category_id: previous_category_ids - new_category_ids, notification_level: notification_level).distinct.pluck(:user_id)
|
||||||
user_ids += User
|
user_ids += User
|
||||||
|
.real
|
||||||
.joins("CROSS JOIN categories c")
|
.joins("CROSS JOIN categories c")
|
||||||
.joins("LEFT JOIN category_users cu ON users.id = cu.user_id AND c.id = cu.category_id")
|
.joins("LEFT JOIN category_users cu ON users.id = cu.user_id AND c.id = cu.category_id")
|
||||||
|
.where(staged: false)
|
||||||
.where("c.id IN (?) AND cu.notification_level IS NULL", new_category_ids - previous_category_ids)
|
.where("c.id IN (?) AND cu.notification_level IS NULL", new_category_ids - previous_category_ids)
|
||||||
.distinct
|
.distinct
|
||||||
.pluck("users.id")
|
.pluck("users.id")
|
||||||
@ -159,8 +161,10 @@ class Admin::SiteSettingsController < Admin::AdminController
|
|||||||
|
|
||||||
user_ids = TagUser.where(tag_id: previous_tag_ids - new_tag_ids, notification_level: notification_level).distinct.pluck(:user_id)
|
user_ids = TagUser.where(tag_id: previous_tag_ids - new_tag_ids, notification_level: notification_level).distinct.pluck(:user_id)
|
||||||
user_ids += User
|
user_ids += User
|
||||||
|
.real
|
||||||
.joins("CROSS JOIN tags t")
|
.joins("CROSS JOIN tags t")
|
||||||
.joins("LEFT JOIN tag_users tu ON users.id = tu.user_id AND t.id = tu.tag_id")
|
.joins("LEFT JOIN tag_users tu ON users.id = tu.user_id AND t.id = tu.tag_id")
|
||||||
|
.where(staged: false)
|
||||||
.where("t.id IN (?) AND tu.notification_level IS NULL", new_tag_ids - previous_tag_ids)
|
.where("t.id IN (?) AND tu.notification_level IS NULL", new_tag_ids - previous_tag_ids)
|
||||||
.distinct
|
.distinct
|
||||||
.pluck("users.id")
|
.pluck("users.id")
|
||||||
|
@ -97,8 +97,9 @@ describe Admin::SiteSettingsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'default categories' do
|
describe 'default categories' do
|
||||||
let(:user1) { Fabricate(:user) }
|
fab!(:user1) { Fabricate(:user) }
|
||||||
let(:user2) { Fabricate(:user) }
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
fab!(:staged_user) { Fabricate(:staged) }
|
||||||
let(:watching) { NotificationLevels.all[:watching] }
|
let(:watching) { NotificationLevels.all[:watching] }
|
||||||
let(:tracking) { NotificationLevels.all[:tracking] }
|
let(:tracking) { NotificationLevels.all[:tracking] }
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ describe Admin::SiteSettingsController do
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(CategoryUser.where(category_id: category_ids.first, notification_level: watching).count).to eq(0)
|
expect(CategoryUser.where(category_id: category_ids.first, notification_level: watching).count).to eq(0)
|
||||||
expect(CategoryUser.where(category_id: category_ids.last, notification_level: watching).count).to eq(User.count - 1)
|
expect(CategoryUser.where(category_id: category_ids.last, notification_level: watching).count).to eq(User.real.where(staged: false).count - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not update existing users user preference' do
|
it 'should not update existing users user preference' do
|
||||||
@ -135,8 +136,9 @@ describe Admin::SiteSettingsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'default tags' do
|
describe 'default tags' do
|
||||||
let(:user1) { Fabricate(:user) }
|
fab!(:user1) { Fabricate(:user) }
|
||||||
let(:user2) { Fabricate(:user) }
|
fab!(:user2) { Fabricate(:user) }
|
||||||
|
fab!(:staged_user) { Fabricate(:staged) }
|
||||||
let(:watching) { NotificationLevels.all[:watching] }
|
let(:watching) { NotificationLevels.all[:watching] }
|
||||||
let(:tracking) { NotificationLevels.all[:tracking] }
|
let(:tracking) { NotificationLevels.all[:tracking] }
|
||||||
|
|
||||||
@ -158,7 +160,7 @@ describe Admin::SiteSettingsController do
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(TagUser.where(tag_id: tags.first.id, notification_level: watching).count).to eq(0)
|
expect(TagUser.where(tag_id: tags.first.id, notification_level: watching).count).to eq(0)
|
||||||
expect(TagUser.where(tag_id: tags.last.id, notification_level: watching).count).to eq(User.count - 1)
|
expect(TagUser.where(tag_id: tags.last.id, notification_level: watching).count).to eq(User.real.where(staged: false).count - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not update existing users user preference' do
|
it 'should not update existing users user preference' do
|
||||||
@ -173,7 +175,8 @@ describe Admin::SiteSettingsController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#user_count' do
|
describe '#user_count' do
|
||||||
let(:user) { Fabricate(:user) }
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
fab!(:staged_user) { Fabricate(:staged) }
|
||||||
let(:tracking) { NotificationLevels.all[:tracking] }
|
let(:tracking) { NotificationLevels.all[:tracking] }
|
||||||
|
|
||||||
it 'should return correct user count for default categories change' do
|
it 'should return correct user count for default categories change' do
|
||||||
@ -183,7 +186,7 @@ describe Admin::SiteSettingsController do
|
|||||||
default_categories_watching: category_id
|
default_categories_watching: category_id
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response.parsed_body["user_count"]).to eq(User.count)
|
expect(response.parsed_body["user_count"]).to eq(User.real.where(staged: false).count)
|
||||||
|
|
||||||
CategoryUser.create!(category_id: category_id, notification_level: tracking, user: user)
|
CategoryUser.create!(category_id: category_id, notification_level: tracking, user: user)
|
||||||
|
|
||||||
@ -191,7 +194,7 @@ describe Admin::SiteSettingsController do
|
|||||||
default_categories_watching: category_id
|
default_categories_watching: category_id
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response.parsed_body["user_count"]).to eq(User.count - 1)
|
expect(response.parsed_body["user_count"]).to eq(User.real.where(staged: false).count - 1)
|
||||||
|
|
||||||
SiteSetting.setting(:default_categories_watching, "")
|
SiteSetting.setting(:default_categories_watching, "")
|
||||||
end
|
end
|
||||||
@ -203,7 +206,7 @@ describe Admin::SiteSettingsController do
|
|||||||
default_tags_watching: tag.name
|
default_tags_watching: tag.name
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response.parsed_body["user_count"]).to eq(User.count)
|
expect(response.parsed_body["user_count"]).to eq(User.real.where(staged: false).count)
|
||||||
|
|
||||||
TagUser.create!(tag_id: tag.id, notification_level: tracking, user: user)
|
TagUser.create!(tag_id: tag.id, notification_level: tracking, user: user)
|
||||||
|
|
||||||
@ -211,7 +214,7 @@ describe Admin::SiteSettingsController do
|
|||||||
default_tags_watching: tag.name
|
default_tags_watching: tag.name
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response.parsed_body["user_count"]).to eq(User.count - 1)
|
expect(response.parsed_body["user_count"]).to eq(User.real.where(staged: false).count - 1)
|
||||||
|
|
||||||
SiteSetting.setting(:default_tags_watching, "")
|
SiteSetting.setting(:default_tags_watching, "")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user