DEV: Remove draft attributes from topic lists (#12525)
This commit is contained in:
parent
598718a19d
commit
65ad8750c7
|
@ -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)
|
result.topic_list = TopicQuery.new(nil, topic_options).list_top_for(SiteSetting.top_page_default_timeframe.to_sym)
|
||||||
end
|
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)
|
render_serialized(result, CategoryAndTopicListsSerializer, root: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class CategoryList < DraftableList
|
class CategoryList
|
||||||
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
cattr_accessor :preloaded_topic_custom_fields
|
cattr_accessor :preloaded_topic_custom_fields
|
||||||
self.preloaded_topic_custom_fields = Set.new
|
self.preloaded_topic_custom_fields = Set.new
|
||||||
|
|
||||||
|
@ -33,7 +35,6 @@ class CategoryList < DraftableList
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
super(@guardian.user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def preload_key
|
def preload_key
|
||||||
|
|
|
@ -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
|
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class TopicList < DraftableList
|
class TopicList
|
||||||
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
cattr_accessor :preloaded_custom_fields
|
cattr_accessor :preloaded_custom_fields
|
||||||
self.preloaded_custom_fields = Set.new
|
self.preloaded_custom_fields = Set.new
|
||||||
|
|
||||||
|
@ -52,8 +54,6 @@ class TopicList < DraftableList
|
||||||
end
|
end
|
||||||
|
|
||||||
@publish_read_state = !!@opts[:publish_read_state]
|
@publish_read_state = !!@opts[:publish_read_state]
|
||||||
|
|
||||||
super(current_user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def top_tags
|
def top_tags
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
class CategoryListSerializer < ApplicationSerializer
|
class CategoryListSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attributes :can_create_category,
|
attributes :can_create_category,
|
||||||
:can_create_topic,
|
:can_create_topic
|
||||||
:draft,
|
|
||||||
:draft_key,
|
|
||||||
:draft_sequence
|
|
||||||
|
|
||||||
has_many :categories, serializer: CategoryDetailedSerializer, embed: :objects
|
has_many :categories, serializer: CategoryDetailedSerializer, embed: :objects
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
class TopListSerializer < ApplicationSerializer
|
class TopListSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attributes :can_create_topic,
|
attributes :can_create_topic
|
||||||
:draft,
|
|
||||||
:draft_key,
|
|
||||||
:draft_sequence
|
|
||||||
|
|
||||||
def can_create_topic
|
def can_create_topic
|
||||||
scope.can_create?(Topic)
|
scope.can_create?(Topic)
|
||||||
|
|
|
@ -4,9 +4,6 @@ class TopicListSerializer < ApplicationSerializer
|
||||||
|
|
||||||
attributes :can_create_topic,
|
attributes :can_create_topic,
|
||||||
:more_topics_url,
|
:more_topics_url,
|
||||||
:draft,
|
|
||||||
:draft_key,
|
|
||||||
:draft_sequence,
|
|
||||||
:for_period,
|
:for_period,
|
||||||
:per_page,
|
:per_page,
|
||||||
:top_tags,
|
:top_tags,
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe 'categories' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'Retreives a list of categories' do
|
get 'Retrieves a list of categories' do
|
||||||
tags 'Categories'
|
tags 'Categories'
|
||||||
consumes 'application/json'
|
consumes 'application/json'
|
||||||
expected_request_schema = nil
|
expected_request_schema = nil
|
||||||
|
|
|
@ -11,18 +11,6 @@
|
||||||
"can_create_topic": {
|
"can_create_topic": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"draft": {
|
|
||||||
"type": [
|
|
||||||
"string",
|
|
||||||
"null"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"draft_key": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"draft_sequence": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"categories": {
|
"categories": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": [
|
"items": [
|
||||||
|
|
|
@ -43,18 +43,6 @@
|
||||||
"can_create_topic": {
|
"can_create_topic": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"draft": {
|
|
||||||
"type": [
|
|
||||||
"string",
|
|
||||||
"null"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"draft_key": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"draft_sequence": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"per_page": {
|
"per_page": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
|
@ -238,9 +226,6 @@
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"can_create_topic",
|
"can_create_topic",
|
||||||
"draft",
|
|
||||||
"draft_key",
|
|
||||||
"draft_sequence",
|
|
||||||
"per_page",
|
"per_page",
|
||||||
"topics"
|
"topics"
|
||||||
]
|
]
|
||||||
|
|
|
@ -57,8 +57,6 @@ describe CategoriesController do
|
||||||
it 'returns the right response for a normal user' do
|
it 'returns the right response for a normal user' do
|
||||||
sign_in(user)
|
sign_in(user)
|
||||||
|
|
||||||
Draft.set(user, Draft::NEW_TOPIC, 0, 'hello')
|
|
||||||
|
|
||||||
get "/categories.json"
|
get "/categories.json"
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
@ -68,10 +66,6 @@ describe CategoriesController do
|
||||||
expect(category_list["categories"].map { |c| c["id"] }).to contain_exactly(
|
expect(category_list["categories"].map { |c| c["id"] }).to contain_exactly(
|
||||||
SiteSetting.get(:uncategorized_category_id), category.id
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -511,14 +505,7 @@ describe CategoriesController do
|
||||||
topic_list = json['topic_list']
|
topic_list = json['topic_list']
|
||||||
|
|
||||||
expect(category_list['categories'].size).to eq(2) # 'Uncategorized' and category
|
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['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)
|
Fabricate(:category, parent_category: category)
|
||||||
|
|
||||||
|
|
|
@ -215,9 +215,6 @@ describe TagsController do
|
||||||
topic_list = json["topic_list"]
|
topic_list = json["topic_list"]
|
||||||
|
|
||||||
expect(topic_list["tags"].map { |t| t["id"] }).to contain_exactly(tag.id)
|
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
|
end
|
||||||
|
|
||||||
it "should handle invalid tags" do
|
it "should handle invalid tags" do
|
||||||
|
|
Loading…
Reference in New Issue