2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-14 00:30:23 -05:00
|
|
|
require "base64"
|
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
class ThemeFieldSerializer < ApplicationSerializer
|
2017-05-09 17:20:28 -04:00
|
|
|
attributes :name, :target, :value, :error, :type_id, :upload_id, :url, :filename
|
|
|
|
|
|
|
|
def include_url?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_upload_id?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_filename?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
object.upload&.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def filename
|
|
|
|
object.upload&.original_filename
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
def target
|
2018-03-04 19:04:23 -05:00
|
|
|
Theme.lookup_target(object.target_id)&.to_s
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
2017-04-19 16:46:28 -04:00
|
|
|
|
|
|
|
def include_error?
|
|
|
|
object.error.present?
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
2019-01-23 04:20:13 -05:00
|
|
|
class BasicThemeSerializer < ApplicationSerializer
|
2018-08-23 21:30:00 -04:00
|
|
|
attributes :id, :name, :created_at, :updated_at, :default, :component
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
def include_default?
|
2018-07-12 00:18:21 -04:00
|
|
|
object.id == SiteSetting.default_theme_id
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RemoteThemeSerializer < ApplicationSerializer
|
2020-03-17 18:27:54 -04:00
|
|
|
attributes :id,
|
|
|
|
:remote_url,
|
|
|
|
:remote_version,
|
|
|
|
:local_version,
|
|
|
|
:commits_behind,
|
|
|
|
:branch,
|
2019-01-25 09:19:01 -05:00
|
|
|
:remote_updated_at,
|
|
|
|
:updated_at,
|
|
|
|
:github_diff_link,
|
|
|
|
:last_error_text,
|
|
|
|
:is_git?,
|
|
|
|
:license_url,
|
|
|
|
:about_url,
|
|
|
|
:authors,
|
|
|
|
:theme_version,
|
|
|
|
:minimum_discourse_version,
|
|
|
|
:maximum_discourse_version
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
# wow, AMS has some pretty nutty logic where it tries to find the path here
|
|
|
|
# from action dispatch, tell it not to
|
|
|
|
def about_url
|
|
|
|
object.about_url
|
|
|
|
end
|
2018-08-06 01:29:15 -04:00
|
|
|
|
|
|
|
def include_github_diff_link?
|
|
|
|
github_diff_link.present?
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
2019-01-23 04:20:13 -05:00
|
|
|
class ThemeSerializer < BasicThemeSerializer
|
2020-11-16 07:44:09 -05:00
|
|
|
attributes :color_scheme,
|
|
|
|
:color_scheme_id,
|
|
|
|
:user_selectable,
|
|
|
|
:auto_update,
|
|
|
|
:remote_theme_id,
|
|
|
|
:settings,
|
|
|
|
:errors,
|
|
|
|
:supported?,
|
|
|
|
:description,
|
|
|
|
:enabled?,
|
|
|
|
:disabled_at
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-05-18 04:09:21 -04:00
|
|
|
has_one :user, serializer: UserNameSerializer, embed: :object
|
2019-07-03 04:18:11 -04:00
|
|
|
has_one :disabled_by, serializer: UserNameSerializer, embed: :object
|
2018-05-18 04:09:21 -04:00
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
has_many :theme_fields, serializer: ThemeFieldSerializer, embed: :objects
|
2019-01-23 04:20:13 -05:00
|
|
|
has_many :child_themes, serializer: BasicThemeSerializer, embed: :objects
|
|
|
|
has_many :parent_themes, serializer: BasicThemeSerializer, embed: :objects
|
2017-04-12 10:52:52 -04:00
|
|
|
has_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects
|
2019-01-17 06:46:11 -05:00
|
|
|
has_many :translations, serializer: ThemeTranslationSerializer, embed: :objects
|
2017-04-13 10:51:44 -04:00
|
|
|
|
2018-10-03 17:03:06 -04:00
|
|
|
def initialize(theme, options = {})
|
|
|
|
super
|
|
|
|
@errors = []
|
2021-04-28 18:00:37 -04:00
|
|
|
|
|
|
|
object.theme_fields.each { |o| @errors << o.error if o.error }
|
2018-10-03 17:03:06 -04:00
|
|
|
end
|
|
|
|
|
2017-04-13 10:51:44 -04:00
|
|
|
def child_themes
|
2018-12-20 12:13:05 -05:00
|
|
|
object.child_themes
|
2017-04-13 10:51:44 -04:00
|
|
|
end
|
2018-03-04 19:04:23 -05:00
|
|
|
|
2019-01-23 04:20:13 -05:00
|
|
|
def parent_themes
|
|
|
|
object.parent_themes
|
|
|
|
end
|
|
|
|
|
2018-03-04 19:04:23 -05:00
|
|
|
def settings
|
|
|
|
object.settings.map { |setting| ThemeSettingsSerializer.new(setting, root: false) }
|
2018-10-03 17:03:06 -04:00
|
|
|
rescue ThemeSettingsParser::InvalidYaml => e
|
|
|
|
@errors << e.message
|
|
|
|
nil
|
2018-03-04 19:04:23 -05:00
|
|
|
end
|
2018-08-23 21:30:00 -04:00
|
|
|
|
|
|
|
def include_child_themes?
|
|
|
|
!object.component?
|
|
|
|
end
|
2018-10-03 17:03:06 -04:00
|
|
|
|
|
|
|
def errors
|
|
|
|
@errors
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_errors?
|
|
|
|
@errors.present?
|
|
|
|
end
|
2019-01-25 09:19:01 -05:00
|
|
|
|
|
|
|
def description
|
|
|
|
object.internal_translations.find { |t| t.key == "theme_metadata.description" }&.value
|
|
|
|
end
|
2019-07-03 04:18:11 -04:00
|
|
|
|
|
|
|
def include_disabled_at?
|
|
|
|
object.component? && !object.enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_disabled_by?
|
|
|
|
include_disabled_at?
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|