A platform for community discussion. Free, open, simple.
FEATURE: Remove ignore feature SiteSetting and enable ignore by default (#7349)
Tarek Khalil442fb2facb91
diff --git a/app/assets/javascripts/discourse/templates/preferences/users.hbs b/app/assets/javascripts/discourse/templates/preferences/users.hbsindex 9899be221d1..7a89a353077 100644--- a/app/assets/javascripts/discourse/templates/preferences/users.hbs+++ b/app/assets/javascripts/discourse/templates/preferences/users.hbs@@ -6,16 +6,14 @@</div><div class="instructions">{{i18n 'user.muted_users_instructions'}}</div>- {{#if siteSettings.ignore_user_enabled}}- <div class="controls tracking-controls">- <label>{{d-icon "eye-slash" class="icon"}} {{i18n 'user.ignored_users'}}</label>- {{user-selector excludeCurrentUser=true- usernames=model.ignored_usernames- onChangeCallback=(action "ignoredUsernamesChanged")- class="user-selector"}}- </div>- <div class="instructions">{{i18n 'user.ignored_users_instructions'}}</div>- {{/if}}+ <div class="controls tracking-controls">+ <label>{{d-icon "eye-slash" class="icon"}} {{i18n 'user.ignored_users'}}</label>+ {{user-selector excludeCurrentUser=true+ usernames=model.ignored_usernames+ onChangeCallback=(action "ignoredUsernamesChanged")+ class="user-selector"}}+ </div>+ <div class="instructions">{{i18n 'user.ignored_users_instructions'}}</div></div>{{plugin-outlet name="user-preferences-notifications" args=(hash model=model save=(action "save"))}}diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 9dbf412bab7..482814f4d0d 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -993,7 +993,6 @@ class UsersController < ApplicationControllerenddef notification_level- raise Discourse::NotFound unless SiteSetting.ignore_user_enableduser = fetch_user_from_paramsif params[:notification_level] == "ignore"diff --git a/app/jobs/scheduled/ignored_users_summary.rb b/app/jobs/scheduled/ignored_users_summary.rbindex 137109113ae..b050d9b5f4c 100644--- a/app/jobs/scheduled/ignored_users_summary.rb+++ b/app/jobs/scheduled/ignored_users_summary.rb@@ -3,8 +3,6 @@ module Jobsevery 1.daydef execute(args)- return unless SiteSetting.ignore_user_enabled-params = {threshold: SiteSetting.ignored_users_count_message_threshold,gap_days: SiteSetting.ignored_users_message_gap_days,diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 585cc6fe9a6..0fcf19eea0b 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -1837,8 +1837,6 @@ en:log_personal_messages_views: "Log personal message views by Admin for other users/groups."- ignore_user_enabled: "[Beta] Allow ignoring users."-ignored_users_count_message_threshold: "Notify moderators if a particular user is ignored by this many other users."ignored_users_message_gap_days: "How long to wait before notifying moderators again about a user who has been ignored by many others."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 6b9a16cecc7..73ccd665c62 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -529,9 +529,6 @@ users:default: falseclient: truelog_personal_messages_views: false- ignore_user_enabled:- default: false- client: trueignored_users_count_message_threshold:default: 5client: truediff --git a/db/migrate/20190410102915_remove_ignore_user_enabled_site_setting.rb b/db/migrate/20190410102915_remove_ignore_user_enabled_site_setting.rbnew file mode 100644index 00000000000..126a7d15a8a--- /dev/null+++ b/db/migrate/20190410102915_remove_ignore_user_enabled_site_setting.rb@@ -0,0 +1,8 @@+class RemoveIgnoreUserEnabledSiteSetting < ActiveRecord::Migration[5.2]+ def up+ execute "DELETE FROM site_settings WHERE name = 'ignore_user_enabled'"+ end++ def down+ end+enddiff --git a/lib/guardian.rb b/lib/guardian.rbindex c5fe976c2f7..5207989df1a 100644--- a/lib/guardian.rb+++ b/lib/guardian.rb@@ -407,7 +407,7 @@ class Guardiandef can_ignore_users?return false if anonymous?- SiteSetting.ignore_user_enabled? && (@user.staff? || @user.trust_level >= TrustLevel.levels[:member])+ @user.staff? || @user.trust_level >= TrustLevel.levels[:member]enddef allow_themes?(theme_ids, include_preview: false)diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 5705ab3ff7c..66da453ba05 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -602,24 +602,21 @@ class TopicView@contains_gaps = false@filtered_posts = unfiltered_posts- if SiteSetting.ignore_user_enabled-- sql = <<~SQL- SELECT ignored_user_id- FROM ignored_users as ig- JOIN users as u ON u.id = ig.ignored_user_id- WHERE ig.user_id = :current_user_id- AND ig.ignored_user_id <> :current_user_id- AND NOT u.admin- AND NOT u.moderator- SQL+ sql = <<~SQL+ SELECT ignored_user_id+ FROM ignored_users as ig+ JOIN users as u ON u.id = ig.ignored_user_id+ WHERE ig.user_id = :current_user_id+ AND ig.ignored_user_id <> :current_user_id+ AND NOT u.admin+ AND NOT u.moderator+ SQL- ignored_user_ids = DB.query_single(sql, current_user_id: @user&.id)+ ignored_user_ids = DB.query_single(sql, current_user_id: @user&.id)- if ignored_user_ids.present?- @filtered_posts = @filtered_posts.where.not("user_id IN (?) AND id <> ?", ignored_user_ids, first_post_id)- @contains_gaps = true- end+ if ignored_user_ids.present?+ @filtered_posts = @filtered_posts.where.not("user_id IN (?) AND id <> ?", ignored_user_ids, first_post_id)+ @contains_gaps = trueend# Filtersdiff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rbindex 9fa878dd2b1..1fff9137a9e 100644--- a/spec/components/guardian_spec.rb+++ b/spec/components/guardian_spec.rb@@ -2676,9 +2676,6 @@ describe Guardian doenddescribe '#can_ignore_user?' do- before do- SiteSetting.ignore_user_enabled = true- endlet(:guardian) { Guardian.new(trust_level_2) }diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 8999f634361..11e1c2d29a0 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -39,64 +39,48 @@ describe TopicView dolet!(:post2) { Fabricate(:post, topic: topic, user: evil_trout) }let!(:post3) { Fabricate(:post, topic: topic, user: user) }- describe "when SiteSetting.ignore_user_enabled is false" do- it "does not filter out ignored user posts" do- SiteSetting.ignore_user_enabled = false-- tv = TopicView.new(topic.id, evil_trout)- expect(tv.filtered_post_ids).to eq([post.id, post2.id, post3.id])- end+ it "filters out ignored user posts" do+ tv = TopicView.new(topic.id, evil_trout)+ expect(tv.filtered_post_ids).to eq([post.id, post2.id])end- describe "when SiteSetting.ignore_user_enabled is true" do-- before do- SiteSetting.ignore_user_enabled = true- end+ describe "when an ignored user made the original post" do+ let!(:post) { Fabricate(:post, topic: topic, user: user) }- it "filters out ignored user posts" do+ it "filters out ignored user posts only" dotv = TopicView.new(topic.id, evil_trout)expect(tv.filtered_post_ids).to eq([post.id, post2.id])end+ end- describe "when an ignored user made the original post" do- let!(:post) { Fabricate(:post, topic: topic, user: user) }-- it "filters out ignored user posts only" do- tv = TopicView.new(topic.id, evil_trout)- expect(tv.filtered_post_ids).to eq([post.id, post2.id])- end- end-- describe "when an anonymous user made a post" do- let(:anonymous) { Fabricate(:anonymous) }- let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) }+ describe "when an anonymous user made a post" do+ let(:anonymous) { Fabricate(:anonymous) }+ let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) }- it "filters out ignored user posts only" do- tv = TopicView.new(topic.id, evil_trout)- expect(tv.filtered_post_ids).to eq([post.id, post2.id, post4.id])- end+ it "filters out ignored user posts only" do+ tv = TopicView.new(topic.id, evil_trout)+ expect(tv.filtered_post_ids).to eq([post.id, post2.id, post4.id])end+ end- describe "when an anonymous (non signed-in) user is viewing a Topic" do- let(:anonymous) { Fabricate(:anonymous) }- let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) }+ describe "when an anonymous (non signed-in) user is viewing a Topic" do+ let(:anonymous) { Fabricate(:anonymous) }+ let!(:post4) { Fabricate(:post, topic: topic, user: anonymous) }- it "filters out ignored user posts only" do- tv = TopicView.new(topic.id, nil)- expect(tv.filtered_post_ids).to eq([post.id, post2.id, post3.id, post4.id])- end+ it "filters out ignored user posts only" do+ tv = TopicView.new(topic.id, nil)+ expect(tv.filtered_post_ids).to eq([post.id, post2.id, post3.id, post4.id])end+ end- describe "when a staff user is ignored" do- let!(:admin) { Fabricate(:user, admin: true) }- let!(:admin_ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: admin) }- let!(:post4) { Fabricate(:post, topic: topic, user: admin) }+ describe "when a staff user is ignored" do+ let!(:admin) { Fabricate(:user, admin: true) }+ let!(:admin_ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: admin) }+ let!(:post4) { Fabricate(:post, topic: topic, user: admin) }- it "filters out ignored user excluding the staff user" do- tv = TopicView.new(topic.id, evil_trout)- expect(tv.filtered_post_ids).to eq([post.id, post2.id, post4.id])- end+ it "filters out ignored user excluding the staff user" do+ tv = TopicView.new(topic.id, evil_trout)+ expect(tv.filtered_post_ids).to eq([post.id, post2.id, post4.id])endendenddiff --git a/spec/jobs/ignored_users_summary_spec.rb b/spec/jobs/ignored_users_summary_spec.rbindex e4cff1f9b00..1d01e823996 100644--- a/spec/jobs/ignored_users_summary_spec.rb+++ b/spec/jobs/ignored_users_summary_spec.rb@@ -4,7 +4,6 @@ require_dependency 'jobs/scheduled/ignored_users_summary'describe Jobs::IgnoredUsersSummary dobefore do- SiteSetting.ignore_user_enabled = trueSiteSetting.ignored_users_count_message_threshold = 1SiteSetting.ignored_users_message_gap_days = 365enddiff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rbindex 6473b25a23f..5b7a9a8a060 100644--- a/spec/requests/users_controller_spec.rb+++ b/spec/requests/users_controller_spec.rb@@ -2033,55 +2033,42 @@ describe UsersController dosign_in(user)end- context 'when ignore_user_enable is OFF' do- it 'raises an error when not logged in' do- put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "" }- expect(response.status).to eq(404)+ let!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }+ let!(:muted_user) { Fabricate(:muted_user, user: user, muted_user: another_user) }++ context 'when changing notification level to normal' do+ it 'changes notification level to normal' do+ put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }+ expect(IgnoredUser.count).to eq(0)+ expect(MutedUser.count).to eq(0)endend- context 'when ignore_user_enable is ON' do- before do- SiteSetting.ignore_user_enabled = true- end-- let!(:ignored_user) { Fabricate(:ignored_user, user: user, ignored_user: another_user) }- let!(:muted_user) { Fabricate(:muted_user, user: user, muted_user: another_user) }-- context 'when changing notification level to normal' do- it 'changes notification level to normal' do- put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "normal" }- expect(IgnoredUser.count).to eq(0)- expect(MutedUser.count).to eq(0)- end+ context 'when changing notification level to mute' do+ it 'changes notification level to mute' do+ put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "mute" }+ expect(IgnoredUser.count).to eq(0)+ expect(MutedUser.find_by(user_id: user.id, muted_user_id: another_user.id)).to be_presentend+ end- context 'when changing notification level to mute' do- it 'changes notification level to mute' do- put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "mute" }- expect(IgnoredUser.count).to eq(0)- expect(MutedUser.find_by(user_id: user.id, muted_user_id: another_user.id)).to be_present- end+ context 'when changing notification level to ignore' do+ it 'changes notification level to ignore' do+ put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "ignore" }+ expect(MutedUser.count).to eq(0)+ expect(IgnoredUser.find_by(user_id: user.id, ignored_user_id: another_user.id)).to be_presentend- context 'when changing notification level to ignore' do+ context 'when expiring_at param is set' doit 'changes notification level to ignore' do- put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "ignore" }- expect(MutedUser.count).to eq(0)- expect(IgnoredUser.find_by(user_id: user.id, ignored_user_id: another_user.id)).to be_present- end-- context 'when expiring_at param is set' do- it 'changes notification level to ignore' do- freeze_time(Time.now) do- expiring_at = 3.days.from_now- put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "ignore", expiring_at: expiring_at }-- ignored_user = IgnoredUser.find_by(user_id: user.id, ignored_user_id: another_user.id)- expect(ignored_user).to be_present- expect(ignored_user.expiring_at.to_i).to eq(expiring_at.to_i)- expect(MutedUser.count).to eq(0)- end+ freeze_time(Time.now) do+ expiring_at = 3.days.from_now+ put "/u/#{another_user.username}/notification_level.json", params: { notification_level: "ignore", expiring_at: expiring_at }++ ignored_user = IgnoredUser.find_by(user_id: user.id, ignored_user_id: another_user.id)+ expect(ignored_user).to be_present+ expect(ignored_user.expiring_at.to_i).to eq(expiring_at.to_i)+ expect(MutedUser.count).to eq(0)endendenddiff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex a10fc260e7a..31a8ca78961 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -35,10 +35,6 @@ describe UserUpdater doenddescribe '#update_ignored_users' do- before do- SiteSetting.ignore_user_enabled = true- end-it 'updates ignored users' dou1 = Fabricate(:user, trust_level: 2)u2 = Fabricate(:user, trust_level: 2)