From 65ad8750c7d4e3be60eeeae1e151f5bba705c180 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Tue, 30 Mar 2021 11:42:26 -0400 Subject: [PATCH] DEV: Remove draft attributes from topic lists (#12525) --- app/controllers/categories_controller.rb | 4 --- app/models/category_list.rb | 5 +-- app/models/draftable_list.rb | 33 ------------------- app/models/topic_list.rb | 6 ++-- app/serializers/category_list_serializer.rb | 5 +-- app/serializers/top_list_serializer.rb | 5 +-- app/serializers/topic_list_serializer.rb | 3 -- spec/requests/api/categories_spec.rb | 2 +- .../schemas/json/category_list_response.json | 12 ------- .../json/category_topics_response.json | 15 --------- spec/requests/categories_controller_spec.rb | 13 -------- spec/requests/tags_controller_spec.rb | 3 -- 12 files changed, 9 insertions(+), 97 deletions(-) delete mode 100644 app/models/draftable_list.rb diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index e6070790f41..b632d6b49b9 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -258,10 +258,6 @@ class CategoriesController < ApplicationController result.topic_list = TopicQuery.new(nil, topic_options).list_top_for(SiteSetting.top_page_default_timeframe.to_sym) end - result.topic_list.draft = result.category_list.draft - result.topic_list.draft_key = result.category_list.draft_key - result.topic_list.draft_sequence = result.category_list.draft_sequence - render_serialized(result, CategoryAndTopicListsSerializer, root: false) end diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 32efd7fafd7..7488a76178e 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -class CategoryList < DraftableList +class CategoryList + include ActiveModel::Serialization + cattr_accessor :preloaded_topic_custom_fields self.preloaded_topic_custom_fields = Set.new @@ -33,7 +35,6 @@ class CategoryList < DraftableList end end - super(@guardian.user) end def preload_key diff --git a/app/models/draftable_list.rb b/app/models/draftable_list.rb deleted file mode 100644 index 3a641a72a4e..00000000000 --- a/app/models/draftable_list.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -class DraftableList - include ActiveModel::Serialization - - def initialize(user) - @current_user = user - end - - def draft_key - @draft_key || Draft::NEW_TOPIC - end - - def draft_sequence - @draft_sequence || DraftSequence.current(@current_user, draft_key) - end - - def draft - @draft || Draft.get(@current_user, draft_key, draft_sequence) if @current_user - end - - def draft_key=(key) - @draft_key = key - end - - def draft_sequence=(sequence) - @draft_sequence = sequence - end - - def draft=(draft) - @draft = draft - end -end diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb index 9a69fe1c99b..4308d888b87 100644 --- a/app/models/topic_list.rb +++ b/app/models/topic_list.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true -class TopicList < DraftableList +class TopicList + include ActiveModel::Serialization + cattr_accessor :preloaded_custom_fields self.preloaded_custom_fields = Set.new @@ -52,8 +54,6 @@ class TopicList < DraftableList end @publish_read_state = !!@opts[:publish_read_state] - - super(current_user) end def top_tags diff --git a/app/serializers/category_list_serializer.rb b/app/serializers/category_list_serializer.rb index 275108bae92..1fe73e2229e 100644 --- a/app/serializers/category_list_serializer.rb +++ b/app/serializers/category_list_serializer.rb @@ -3,10 +3,7 @@ class CategoryListSerializer < ApplicationSerializer attributes :can_create_category, - :can_create_topic, - :draft, - :draft_key, - :draft_sequence + :can_create_topic has_many :categories, serializer: CategoryDetailedSerializer, embed: :objects diff --git a/app/serializers/top_list_serializer.rb b/app/serializers/top_list_serializer.rb index 195f92217d1..291089d9be3 100644 --- a/app/serializers/top_list_serializer.rb +++ b/app/serializers/top_list_serializer.rb @@ -2,10 +2,7 @@ class TopListSerializer < ApplicationSerializer - attributes :can_create_topic, - :draft, - :draft_key, - :draft_sequence + attributes :can_create_topic def can_create_topic scope.can_create?(Topic) diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb index 2766f9c30b7..a3ece4822f2 100644 --- a/app/serializers/topic_list_serializer.rb +++ b/app/serializers/topic_list_serializer.rb @@ -4,9 +4,6 @@ class TopicListSerializer < ApplicationSerializer attributes :can_create_topic, :more_topics_url, - :draft, - :draft_key, - :draft_sequence, :for_period, :per_page, :top_tags, diff --git a/spec/requests/api/categories_spec.rb b/spec/requests/api/categories_spec.rb index 938f110211c..e1311125cb7 100644 --- a/spec/requests/api/categories_spec.rb +++ b/spec/requests/api/categories_spec.rb @@ -33,7 +33,7 @@ describe 'categories' do end end - get 'Retreives a list of categories' do + get 'Retrieves a list of categories' do tags 'Categories' consumes 'application/json' expected_request_schema = nil diff --git a/spec/requests/api/schemas/json/category_list_response.json b/spec/requests/api/schemas/json/category_list_response.json index e4a7fa57424..1aa3c8f0648 100644 --- a/spec/requests/api/schemas/json/category_list_response.json +++ b/spec/requests/api/schemas/json/category_list_response.json @@ -11,18 +11,6 @@ "can_create_topic": { "type": "boolean" }, - "draft": { - "type": [ - "string", - "null" - ] - }, - "draft_key": { - "type": "string" - }, - "draft_sequence": { - "type": "integer" - }, "categories": { "type": "array", "items": [ diff --git a/spec/requests/api/schemas/json/category_topics_response.json b/spec/requests/api/schemas/json/category_topics_response.json index 772d42b1653..472616b35dc 100644 --- a/spec/requests/api/schemas/json/category_topics_response.json +++ b/spec/requests/api/schemas/json/category_topics_response.json @@ -43,18 +43,6 @@ "can_create_topic": { "type": "boolean" }, - "draft": { - "type": [ - "string", - "null" - ] - }, - "draft_key": { - "type": "string" - }, - "draft_sequence": { - "type": "integer" - }, "per_page": { "type": "integer" }, @@ -238,9 +226,6 @@ }, "required": [ "can_create_topic", - "draft", - "draft_key", - "draft_sequence", "per_page", "topics" ] diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb index 6fce406e9e3..ddbc383ac89 100644 --- a/spec/requests/categories_controller_spec.rb +++ b/spec/requests/categories_controller_spec.rb @@ -57,8 +57,6 @@ describe CategoriesController do it 'returns the right response for a normal user' do sign_in(user) - Draft.set(user, Draft::NEW_TOPIC, 0, 'hello') - get "/categories.json" expect(response.status).to eq(200) @@ -68,10 +66,6 @@ describe CategoriesController do expect(category_list["categories"].map { |c| c["id"] }).to contain_exactly( SiteSetting.get(:uncategorized_category_id), category.id ) - - expect(category_list["draft_sequence"]).to eq(0) - expect(category_list["draft_key"]).to eq(Draft::NEW_TOPIC) - expect(category_list["draft"]).to eq('hello') end end @@ -511,14 +505,7 @@ describe CategoriesController do topic_list = json['topic_list'] expect(category_list['categories'].size).to eq(2) # 'Uncategorized' and category - expect(category_list['draft_key']).to eq(Draft::NEW_TOPIC) - expect(category_list['draft_sequence']).to eq(nil) - expect(category_list['draft']).to eq(nil) - expect(topic_list['topics'].size).to eq(5) - expect(topic_list['draft_key']).to eq(Draft::NEW_TOPIC) - expect(topic_list['draft_sequence']).to eq(nil) - expect(topic_list['draft']).to eq(nil) Fabricate(:category, parent_category: category) diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb index cecb8a487ab..0232aa3c2b4 100644 --- a/spec/requests/tags_controller_spec.rb +++ b/spec/requests/tags_controller_spec.rb @@ -215,9 +215,6 @@ describe TagsController do topic_list = json["topic_list"] expect(topic_list["tags"].map { |t| t["id"] }).to contain_exactly(tag.id) - expect(topic_list["draft"]).to eq(nil) - expect(topic_list["draft_sequence"]).to eq(nil) - expect(topic_list["draft_key"]).to eq(Draft::NEW_TOPIC) end it "should handle invalid tags" do