From c740b423286871eab7c17ca24917b58f379d055f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 12 Feb 2016 12:10:30 +0100 Subject: [PATCH 1/5] FIX: whitelist post_types used in context in email notifications --- app/mailers/user_notifications.rb | 5 ++++- spec/mailers/user_notifications_spec.rb | 27 ++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 6f2345137bc..51729427816 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -186,11 +186,14 @@ class UserNotifications < ActionMailer::Base end def self.get_context_posts(post, topic_user) + allowed_post_types = [Post.types[:regular]] + allowed_post_types << Post.types[:whisper] if topic_user.try(:user).try(:staff?) + context_posts = Post.where(topic_id: post.topic_id) .where("post_number < ?", post.post_number) .where(user_deleted: false) .where(hidden: false) - .where(post_type: Topic.visible_post_types) + .where(post_type: allowed_post_types) .order('created_at desc') .limit(SiteSetting.email_posts_context) diff --git a/spec/mailers/user_notifications_spec.rb b/spec/mailers/user_notifications_spec.rb index 39348495442..947dd9a466b 100644 --- a/spec/mailers/user_notifications_spec.rb +++ b/spec/mailers/user_notifications_spec.rb @@ -6,21 +6,20 @@ describe UserNotifications do describe "#get_context_posts" do it "does not include hidden/deleted/user_deleted posts in context" do - post = create_post - reply1 = create_post(topic: post.topic) - reply2 = create_post(topic: post.topic) - reply3 = create_post(topic: post.topic) - reply4 = create_post(topic: post.topic) + post1 = create_post + post2 = Fabricate(:post, topic: post1.topic, deleted_at: 1.day.ago) + post3 = Fabricate(:post, topic: post1.topic, user_deleted: true) + post4 = Fabricate(:post, topic: post1.topic, hidden: true) + post5 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:moderator_action]) + post6 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:small_action]) + post7 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:whisper]) + last = Fabricate(:post, topic: post1.topic) - reply1.trash! - - reply2.user_deleted = true - reply2.save - - reply3.hidden = true - reply3.save - - expect(UserNotifications.get_context_posts(reply4, nil).count).to eq(1) + # default is only post #1 + expect(UserNotifications.get_context_posts(last, nil).count).to eq(1) + # staff members can also see the whisper + tu = TopicUser.new(topic: post1.topic, user: build(:moderator)) + expect(UserNotifications.get_context_posts(last, tu).count).to eq(2) end end From 6fc2d9db3a3c48ee8379f4c5061ecebada96729c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Sat, 13 Feb 2016 00:02:23 +0800 Subject: [PATCH 2/5] UX: Fix a bunch of overflowing links on mobile nav. --- app/assets/stylesheets/mobile/discourse.scss | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/mobile/discourse.scss b/app/assets/stylesheets/mobile/discourse.scss index acc5ab256c5..d8b34c96abb 100644 --- a/app/assets/stylesheets/mobile/discourse.scss +++ b/app/assets/stylesheets/mobile/discourse.scss @@ -126,6 +126,7 @@ h2#site-text-logo padding: 8px 10px; height: 100%; width: 100%; + box-sizing: border-box; display: block; } .fa-caret-down { @@ -142,16 +143,16 @@ h2#site-text-logo position: absolute; z-index: 10000000; background-color: $secondary; - width: 98%; + width: 100%; list-style: none; margin: 0; padding: 5px; border: 1px solid #eaeaea; + box-sizing: border-box; li { margin: 5px 0; padding: 0; a { - width: 100%; height: 100%; display: block; padding: 5px 8px; From 06c9e799844a622971b2af4874d722a20896687c Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 12 Feb 2016 14:33:13 -0500 Subject: [PATCH 3/5] FIX: pending flags reminder email was ignoring the 'notify about flags after' site setting. --- app/jobs/scheduled/pending_flags_reminder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/scheduled/pending_flags_reminder.rb b/app/jobs/scheduled/pending_flags_reminder.rb index d4a68e6f145..8b196d4ae67 100644 --- a/app/jobs/scheduled/pending_flags_reminder.rb +++ b/app/jobs/scheduled/pending_flags_reminder.rb @@ -9,7 +9,7 @@ module Jobs def execute(args) if SiteSetting.notify_about_flags_after > 0 && PostAction.flagged_posts_count > 0 && - FlagQuery.flagged_post_actions('active').where('post_actions.created_at < ?', 48.hours.ago).pluck(:id).count > 0 + FlagQuery.flagged_post_actions('active').where('post_actions.created_at < ?', SiteSetting.notify_about_flags_after.to_i.hours.ago).pluck(:id).count > 0 message = PendingFlagsMailer.notify Email::Sender.new(message, :pending_flags_reminder).send From 3939b9ec7d2bd4ee3f521878a8f013ba350709b5 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 12 Feb 2016 17:20:38 -0500 Subject: [PATCH 4/5] FIX: restore in development mode connects to the wrong database --- lib/backup_restore/backup_restore.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/backup_restore/backup_restore.rb b/lib/backup_restore/backup_restore.rb index e0f02ecb1b3..cde7cfefd4d 100644 --- a/lib/backup_restore/backup_restore.rb +++ b/lib/backup_restore/backup_restore.rb @@ -100,7 +100,7 @@ module BackupRestore DatabaseConfiguration = Struct.new(:host, :port, :username, :password, :database) def self.database_configuration - config = Rails.env.production? ? ActiveRecord::Base.connection_pool.spec.config : Rails.configuration.database_configuration[Rails.env] + config = ActiveRecord::Base.connection_pool.spec.config config = config.with_indifferent_access DatabaseConfiguration.new( From b1e68390f4c4ab2fa0e94e3ce37f5731b8cc1686 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 13 Feb 2016 17:49:26 +1100 Subject: [PATCH 5/5] FIX: false overrides should be permitted via ENV --- lib/site_setting_extension.rb | 2 +- spec/components/site_setting_extension_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index a6a46d6390b..7912d8dbea2 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -121,7 +121,7 @@ module SiteSettingExtension # exists it will be used instead of the setting and the setting will be hidden. # Useful for things like API keys on multisite. if opts[:shadowed_by_global] && GlobalSetting.respond_to?(name) - if (val = GlobalSetting.send(name)).present? + unless (val = GlobalSetting.send(name)) == ''.freeze hidden_settings << name shadowed_settings << name current_value = val diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rb index 8d9fd2eb82a..f6982e8ef0c 100644 --- a/spec/components/site_setting_extension_spec.rb +++ b/spec/components/site_setting_extension_spec.rb @@ -470,6 +470,18 @@ describe SiteSettingExtension do end end + context "with a false override" do + before do + GlobalSetting.stubs(:bool).returns(false) + settings.setting(:bool, true, shadowed_by_global: true) + settings.refresh! + end + + it "should return default cause nothing is set" do + expect(settings.bool).to eq(false) + end + end + context "with global setting" do before do GlobalSetting.stubs(:trout_api_key).returns('purringcat')