From a4c4f13901fbbfb7af28872aead1d65d94dfa807 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 9 Dec 2016 13:28:12 -0500 Subject: [PATCH] Remove the topic_featured_link_onebox setting. We will always try to onebox a link and add it to the body if topic_featured_link_enabled is enabled. --- .../javascripts/discourse/components/composer-body.js.es6 | 3 +-- app/assets/javascripts/discourse/models/composer.js.es6 | 5 ----- config/site_settings.yml | 3 --- lib/post_creator.rb | 7 +------ lib/post_revisor.rb | 7 ------- spec/components/post_creator_spec.rb | 8 +++----- test/javascripts/models/composer-test.js.es6 | 6 +++--- 7 files changed, 8 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-body.js.es6 b/app/assets/javascripts/discourse/components/composer-body.js.es6 index aba22cf7284..e9e4552a2b4 100644 --- a/app/assets/javascripts/discourse/components/composer-body.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-body.js.es6 @@ -13,8 +13,7 @@ export default Ember.Component.extend({ 'composer.canEditTitle:edit-title', 'composer.createdPost:created-post', 'composer.creatingTopic:topic', - 'composer.whisper:composing-whisper', - 'composer.showComposerEditor::topic-featured-link-only'], + 'composer.whisper:composing-whisper'], @computed('composer.composeState') composeState(composeState) { diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index eacdd96c78c..659568377db 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -195,11 +195,6 @@ const Composer = RestModel.extend({ }.property('action', 'post', 'topic', 'topic.title'), - @computed('canEditTopicFeaturedLink') - showComposerEditor(canEditTopicFeaturedLink) { - return canEditTopicFeaturedLink ? !this.siteSettings.topic_featured_link_onebox : true; - }, - // whether to disable the post button cantSubmitPost: function() { diff --git a/config/site_settings.yml b/config/site_settings.yml index aae34135a64..e901cd070d8 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -436,9 +436,6 @@ posting: topic_featured_link_enabled: client: true default: false - topic_featured_link_onebox: - client: true - default: false open_topic_featured_link_in_external_window: client: true default: true diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 6a788cf5bdb..8797a48f8f1 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -104,11 +104,6 @@ class PostCreator end end - onebox_featured_link = SiteSetting.topic_featured_link_enabled && SiteSetting.topic_featured_link_onebox && guardian.can_edit_featured_link?(find_category_id) - if onebox_featured_link - @opts[:raw] = DiscourseFeaturedLink.cache_onebox_link(@opts[:featured_link]) - end - setup_post return true if skip_validations? @@ -122,7 +117,7 @@ class PostCreator DiscourseEvent.trigger :before_create_post, @post DiscourseEvent.trigger :validate_post, @post - post_validator = Validators::PostValidator.new(skip_topic: true, skip_post_body: onebox_featured_link) + post_validator = Validators::PostValidator.new(skip_topic: true) post_validator.validate(@post) valid = @post.errors.blank? diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index a5451affba9..4fea530847f 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -102,13 +102,6 @@ class PostRevisor topic_changes.record_change('featured_link', topic_changes.topic.featured_link, featured_link) topic_changes.topic.featured_link = featured_link - - if SiteSetting.topic_featured_link_onebox - post = topic_changes.topic.first_post - post.raw = DiscourseFeaturedLink.cache_onebox_link(featured_link) - post.save! - post.rebake! - end end end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 197e6be9d40..1b56b8a7204 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -20,7 +20,7 @@ describe PostCreator do let(:creator_with_category) { PostCreator.new(user, basic_topic_params.merge(category: category.id )) } let(:creator_with_meta_data) { PostCreator.new(user, basic_topic_params.merge(meta_data: {hello: "world"} )) } let(:creator_with_image_sizes) { PostCreator.new(user, basic_topic_params.merge(image_sizes: image_sizes)) } - let(:creator_with_featured_link) { PostCreator.new(user, title: "featured link topic", archetype_id: 1, featured_link: "http://discourse.org") } + let(:creator_with_featured_link) { PostCreator.new(user, title: "featured link topic", archetype_id: 1, featured_link: "http://www.discourse.org", raw: "http://www.discourse.org") } it "can create a topic with null byte central" do post = PostCreator.create(user, title: "hello\u0000world this is title", raw: "this is my\u0000 first topic") @@ -244,12 +244,10 @@ describe PostCreator do end end - it 'creates a post without raw' do + it 'creates a post with featured link' do SiteSetting.topic_featured_link_enabled = true - SiteSetting.topic_featured_link_onebox = true post = creator_with_featured_link.create - expect(post.topic.featured_link).to eq('http://discourse.org') - expect(post.raw).to eq('http://discourse.org') + expect(post.topic.featured_link).to eq('http://www.discourse.org') end describe "topic's auto close" do diff --git a/test/javascripts/models/composer-test.js.es6 b/test/javascripts/models/composer-test.js.es6 index aa400397eba..a79bb85a6d1 100644 --- a/test/javascripts/models/composer-test.js.es6 +++ b/test/javascripts/models/composer-test.js.es6 @@ -41,9 +41,9 @@ test('missingReplyCharacters', function() { missingReplyCharacters('hi', false, true, Discourse.SiteSettings.min_first_post_length - 2, 'too short first post'); missingReplyCharacters('hi', true, false, Discourse.SiteSettings.min_private_message_post_length - 2, 'too short private message'); - Discourse.SiteSettings.topic_featured_link_onebox = true; - const composer = createComposer({ canEditTopicFeaturedLink: true }); - equal(composer.get('missingReplyCharacters'), 0, "don't require any post content"); + // TODO: test that presence of featured link makes this test pass + // const composer = createComposer({ canEditTopicFeaturedLink: true }); + // equal(composer.get('missingReplyCharacters'), 0, "don't require any post content"); }); test('missingTitleCharacters', function() {