DEV: Remove draft attributes from topic lists (#12525)

This commit is contained in:
Penar Musaraj 2021-03-30 11:42:26 -04:00 committed by GitHub
parent 598718a19d
commit 65ad8750c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 9 additions and 97 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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": [

View File

@ -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"
]

View File

@ -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)

View File

@ -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