FIX: tag notification preferences were being cleared when other preferences were changed
This commit is contained in:
parent
ec6bbe2af0
commit
73c1d3e7fe
|
@ -283,6 +283,12 @@ const User = RestModel.extend({
|
|||
}
|
||||
});
|
||||
|
||||
['muted_tags', 'tracked_tags', 'watched_tags', 'watching_first_post_tags'].forEach(prop => {
|
||||
if (fields === undefined || fields.includes(prop)) {
|
||||
data[prop] = this.get(prop) ? this.get(prop).join(',') : '';
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: We can remove this when migrated fully to rest model.
|
||||
this.set('isSaving', true);
|
||||
return ajax(userPath(`${this.get('username_lower')}.json`), {
|
||||
|
|
|
@ -1064,7 +1064,7 @@ class UsersController < ApplicationController
|
|||
|
||||
permitted.concat UserUpdater::OPTION_ATTR
|
||||
permitted.concat UserUpdater::CATEGORY_IDS.keys.map { |k| { k => [] } }
|
||||
permitted.concat UserUpdater::TAG_NAMES.keys.map { |k| { k => [] } }
|
||||
permitted.concat UserUpdater::TAG_NAMES.keys
|
||||
|
||||
result = params
|
||||
.permit(permitted)
|
||||
|
|
|
@ -73,7 +73,9 @@ class UserUpdater
|
|||
end
|
||||
|
||||
TAG_NAMES.each do |attribute, level|
|
||||
TagUser.batch_set(user, level, attributes[attribute])
|
||||
if attributes.has_key?(attribute)
|
||||
TagUser.batch_set(user, level, attributes[attribute]&.split(',') || [])
|
||||
end
|
||||
end
|
||||
|
||||
save_options = false
|
||||
|
|
|
@ -1541,12 +1541,14 @@ describe UsersController do
|
|||
it 'allows the update' do
|
||||
user2 = Fabricate(:user)
|
||||
user3 = Fabricate(:user)
|
||||
tags = [Fabricate(:tag), Fabricate(:tag)]
|
||||
|
||||
put :update, params: {
|
||||
username: user.username,
|
||||
name: 'Jim Tom',
|
||||
custom_fields: { test: :it },
|
||||
muted_usernames: "#{user2.username},#{user3.username}"
|
||||
muted_usernames: "#{user2.username},#{user3.username}",
|
||||
watched_tags: "#{tags[0].name},#{tags[1].name}"
|
||||
}, format: :json
|
||||
|
||||
expect(response).to be_success
|
||||
|
@ -1556,6 +1558,10 @@ describe UsersController do
|
|||
expect(user.name).to eq 'Jim Tom'
|
||||
expect(user.custom_fields['test']).to eq 'it'
|
||||
expect(user.muted_users.pluck(:username).sort).to eq [user2.username, user3.username].sort
|
||||
expect(TagUser.where(
|
||||
user: user,
|
||||
notification_level: TagUser.notification_levels[:watching]
|
||||
).pluck(:tag_id)).to contain_exactly(tags[0].id, tags[1].id)
|
||||
|
||||
theme = Theme.create(name: "test", user_selectable: true, user_id: -1)
|
||||
|
||||
|
|
|
@ -27,6 +27,10 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
describe '#update' do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:tag) { Fabricate(:tag) }
|
||||
let(:tag2) { Fabricate(:tag) }
|
||||
|
||||
it 'saves user' do
|
||||
user = Fabricate(:user, name: 'Billy Bob')
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
@ -37,18 +41,21 @@ describe UserUpdater do
|
|||
end
|
||||
|
||||
it 'can update categories and tags' do
|
||||
category = Fabricate(:category)
|
||||
tag = Fabricate(:tag)
|
||||
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
updater.update(watched_tags: [tag.name], muted_category_ids: [category.id])
|
||||
updater.update(watched_tags: "#{tag.name},#{tag2.name}", muted_category_ids: [category.id])
|
||||
|
||||
expect(TagUser.where(
|
||||
user_id: user.id,
|
||||
tag_id: tag.id,
|
||||
notification_level: TagUser.notification_levels[:watching]
|
||||
).count).to eq(1)
|
||||
).exists?).to eq(true)
|
||||
|
||||
expect(TagUser.where(
|
||||
user_id: user.id,
|
||||
tag_id: tag2.id,
|
||||
notification_level: TagUser.notification_levels[:watching]
|
||||
).exists?).to eq(true)
|
||||
|
||||
expect(CategoryUser.where(
|
||||
user_id: user.id,
|
||||
|
@ -58,6 +65,18 @@ describe UserUpdater do
|
|||
|
||||
end
|
||||
|
||||
it "doesn't remove notification prefs when updating something else" do
|
||||
user = Fabricate(:user)
|
||||
TagUser.create!(user: user, tag: tag, notification_level: TagUser.notification_levels[:watching])
|
||||
CategoryUser.create!(user: user, category: category, notification_level: CategoryUser.notification_levels[:muted])
|
||||
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
updater.update(name: "Steve Dave")
|
||||
|
||||
expect(TagUser.where(user: user).count).to eq(1)
|
||||
expect(CategoryUser.where(user: user).count).to eq(1)
|
||||
end
|
||||
|
||||
it 'updates various fields' do
|
||||
user = Fabricate(:user)
|
||||
updater = UserUpdater.new(acting_user, user)
|
||||
|
|
Loading…
Reference in New Issue