FIX: Don't allow NULL values for `notification_level` in `category_users` (#15407)

This commit is contained in:
Osama Sayegh 2021-12-29 01:19:39 +03:00 committed by GitHub
parent 91a816e788
commit 8e6988163f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 16 deletions

View File

@ -243,7 +243,7 @@ end
# id :integer not null, primary key
# category_id :integer not null
# user_id :integer not null
# notification_level :integer
# notification_level :integer not null
# last_seen_at :datetime
#
# Indexes

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class NotNullNotificationLevelInCategoryUsers < ActiveRecord::Migration[6.1]
def change
up_only do
execute("DELETE FROM category_users WHERE notification_level IS NULL")
end
change_column_null :category_users, :notification_level, false
end
end

View File

@ -331,7 +331,7 @@ describe Jobs::ExportUserArchive do
.category_users
.where(category_id: category_id)
.first_or_initialize
.update!(last_seen_at: reset_at)
.update!(last_seen_at: reset_at, notification_level: NotificationLevels.all[:regular])
end
# Set Watching First Post on announcements, Tracking on subcategory, Muted on deleted, nothing on subsubcategory
@ -355,7 +355,7 @@ describe Jobs::ExportUserArchive do
expect(data[1][:category_id]).to eq(subsubcategory.id.to_s)
expect(data[1][:category_names]).to eq("#{category.name}|#{subcategory.name}|#{subsubcategory.name}")
expect(data[1][:notification_level]).to eq('') # empty string, not 'normal'
expect(data[1][:notification_level]).to eq('regular')
expect(DateTime.parse(data[1][:dismiss_new_timestamp])).to eq(reset_at)
expect(data[2][:category_id]).to eq(announcements.id.to_s)

View File

@ -50,7 +50,11 @@ describe TopicList do
describe '#load_topics' do
it 'loads additional data for serialization' do
category_user = CategoryUser.create!(user: user, category: topic.category)
category_user = CategoryUser.create!(
user: user,
category: topic.category,
notification_level: NotificationLevels.all[:regular]
)
topic = topic_list.load_topics.first

View File

@ -354,18 +354,6 @@ describe TopicTrackingState do
expect(report.length).to eq(1)
end
it "correctly handles category_users with null notification level" do
post
report = TopicTrackingState.report(user)
expect(report.length).to eq(1)
CategoryUser.create!(user_id: user.id, category_id: post.topic.category_id)
report = TopicTrackingState.report(user)
expect(report.length).to eq(1)
end
it "works when categories are default muted" do
SiteSetting.mute_all_categories_by_default = true