DEV:add uploaded_meta option in category for category meta image (#6724)

This commit is contained in:
Saurabh Patel
2018-12-07 22:24:08 +07:00
committed by Régis Hanol
parent 86f8734bc0
commit 9e3143445b
8 changed files with 15 additions and 3 deletions

View File

@ -276,6 +276,7 @@ class CategoriesController < ApplicationController
:auto_close_based_on_last_post, :auto_close_based_on_last_post,
:uploaded_logo_id, :uploaded_logo_id,
:uploaded_background_id, :uploaded_background_id,
:uploaded_meta_id,
:slug, :slug,
:allow_badges, :allow_badges,
:topic_template, :topic_template,

View File

@ -55,7 +55,7 @@ module Jobs
.joins("LEFT JOIN users u ON u.uploaded_avatar_id = uploads.id") .joins("LEFT JOIN users u ON u.uploaded_avatar_id = uploads.id")
.joins("LEFT JOIN user_avatars ua ON ua.gravatar_upload_id = uploads.id OR ua.custom_upload_id = uploads.id") .joins("LEFT JOIN user_avatars ua ON ua.gravatar_upload_id = uploads.id OR ua.custom_upload_id = uploads.id")
.joins("LEFT JOIN user_profiles up ON up.profile_background = uploads.url OR up.card_background = uploads.url") .joins("LEFT JOIN user_profiles up ON up.profile_background = uploads.url OR up.card_background = uploads.url")
.joins("LEFT JOIN categories c ON c.uploaded_logo_id = uploads.id OR c.uploaded_background_id = uploads.id") .joins("LEFT JOIN categories c ON c.uploaded_logo_id = uploads.id OR c.uploaded_background_id = uploads.id OR c.uploaded_meta_id = uploads.id")
.joins("LEFT JOIN custom_emojis ce ON ce.upload_id = uploads.id") .joins("LEFT JOIN custom_emojis ce ON ce.upload_id = uploads.id")
.joins("LEFT JOIN theme_fields tf ON tf.upload_id = uploads.id") .joins("LEFT JOIN theme_fields tf ON tf.upload_id = uploads.id")
.joins("LEFT JOIN user_exports ue ON ue.upload_id = uploads.id") .joins("LEFT JOIN user_exports ue ON ue.upload_id = uploads.id")

View File

@ -28,6 +28,7 @@ class Category < ActiveRecord::Base
belongs_to :latest_post, class_name: "Post" belongs_to :latest_post, class_name: "Post"
belongs_to :uploaded_logo, class_name: "Upload" belongs_to :uploaded_logo, class_name: "Upload"
belongs_to :uploaded_background, class_name: "Upload" belongs_to :uploaded_background, class_name: "Upload"
belongs_to :uploaded_meta, class_name: "Upload"
has_many :topics has_many :topics
has_many :category_users has_many :category_users
@ -667,6 +668,7 @@ end
# sort_ascending :boolean # sort_ascending :boolean
# uploaded_logo_id :integer # uploaded_logo_id :integer
# uploaded_background_id :integer # uploaded_background_id :integer
# uploaded_meta_id :integer
# topic_featured_link_allowed :boolean default(TRUE) # topic_featured_link_allowed :boolean default(TRUE)
# all_topics_wiki :boolean default(FALSE), not null # all_topics_wiki :boolean default(FALSE), not null
# show_subcategory_list :boolean default(FALSE) # show_subcategory_list :boolean default(FALSE)

View File

@ -69,6 +69,7 @@ class CategoryList
@categories = Category.includes( @categories = Category.includes(
:uploaded_background, :uploaded_background,
:uploaded_logo, :uploaded_logo,
:uploaded_meta,
:topic_only_relative_url, :topic_only_relative_url,
subcategories: [:topic_only_relative_url] subcategories: [:topic_only_relative_url]
).secured(@guardian) ).secured(@guardian)

View File

@ -28,7 +28,7 @@ class Site
def categories def categories
@categories ||= begin @categories ||= begin
categories = Category categories = Category
.includes(:uploaded_logo, :uploaded_background) .includes(:uploaded_logo, :uploaded_background, :uploaded_meta)
.secured(@guardian) .secured(@guardian)
.joins('LEFT JOIN topics t on t.id = categories.topic_id') .joins('LEFT JOIN topics t on t.id = categories.topic_id')
.select('categories.*, t.slug topic_slug') .select('categories.*, t.slug topic_slug')

View File

@ -30,6 +30,7 @@ class BasicCategorySerializer < ApplicationSerializer
has_one :uploaded_logo, embed: :object, serializer: CategoryUploadSerializer has_one :uploaded_logo, embed: :object, serializer: CategoryUploadSerializer
has_one :uploaded_background, embed: :object, serializer: CategoryUploadSerializer has_one :uploaded_background, embed: :object, serializer: CategoryUploadSerializer
has_one :uploaded_meta, embed: :object, serializer: CategoryUploadSerializer
def include_parent_category_id? def include_parent_category_id?
parent_category_id parent_category_id

View File

@ -0,0 +1,5 @@
class AddUploadedMetaIdToCategories < ActiveRecord::Migration[5.2]
def change
add_column :categories, :uploaded_meta_id, :integer
end
end

View File

@ -132,7 +132,8 @@ describe CategoriesController do
permissions: { permissions: {
"everyone" => readonly, "everyone" => readonly,
"staff" => create_post "staff" => create_post
} },
uploaded_meta_id: 2
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)
@ -145,6 +146,7 @@ describe CategoriesController do
expect(category.color).to eq("ff0") expect(category.color).to eq("ff0")
expect(category.auto_close_hours).to eq(72) expect(category.auto_close_hours).to eq(72)
expect(UserHistory.count).to eq(4) # 1 + 3 (bootstrap mode) expect(UserHistory.count).to eq(4) # 1 + 3 (bootstrap mode)
expect(category.uploaded_meta_id).to eq(2)
end end
end end
end end