2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-07 06:32:59 +08:00
|
|
|
class AdminPluginSerializer < ApplicationSerializer
|
2015-02-11 01:14:23 +08:00
|
|
|
attributes :id,
|
|
|
|
:name,
|
2021-02-13 00:19:07 +08:00
|
|
|
:about,
|
2015-02-07 06:32:59 +08:00
|
|
|
:version,
|
2015-02-07 07:08:57 +08:00
|
|
|
:url,
|
2015-07-03 00:45:17 +08:00
|
|
|
:admin_route,
|
|
|
|
:enabled,
|
2018-04-06 10:54:58 +08:00
|
|
|
:enabled_setting,
|
2020-05-12 16:18:19 +08:00
|
|
|
:has_settings,
|
2024-05-23 10:04:26 +08:00
|
|
|
:has_only_enabled_setting,
|
2023-06-26 12:39:57 +08:00
|
|
|
:is_official,
|
2023-11-21 07:37:11 +08:00
|
|
|
:is_discourse_owned,
|
2023-11-30 08:53:17 +08:00
|
|
|
:label,
|
2023-06-26 12:39:57 +08:00
|
|
|
:commit_hash,
|
2023-10-10 08:16:13 +08:00
|
|
|
:commit_url,
|
2023-11-21 07:37:11 +08:00
|
|
|
:meta_url,
|
2024-03-21 11:42:06 +08:00
|
|
|
:authors
|
2015-02-07 06:32:59 +08:00
|
|
|
|
2015-02-11 01:14:23 +08:00
|
|
|
def id
|
2020-05-10 19:07:45 +08:00
|
|
|
object.directory_name
|
2015-02-11 01:14:23 +08:00
|
|
|
end
|
|
|
|
|
2015-02-07 06:32:59 +08:00
|
|
|
def name
|
|
|
|
object.metadata.name
|
|
|
|
end
|
|
|
|
|
2021-02-13 00:19:07 +08:00
|
|
|
def about
|
|
|
|
object.metadata.about
|
|
|
|
end
|
|
|
|
|
2015-02-07 06:32:59 +08:00
|
|
|
def version
|
|
|
|
object.metadata.version
|
|
|
|
end
|
|
|
|
|
2015-02-07 07:08:57 +08:00
|
|
|
def url
|
|
|
|
object.metadata.url
|
|
|
|
end
|
|
|
|
|
2023-11-21 07:37:11 +08:00
|
|
|
def authors
|
|
|
|
object.metadata.authors
|
|
|
|
end
|
|
|
|
|
2015-07-03 00:45:17 +08:00
|
|
|
def enabled
|
|
|
|
object.enabled?
|
|
|
|
end
|
|
|
|
|
2018-05-08 10:30:33 +08:00
|
|
|
def include_enabled_setting?
|
2018-05-16 14:26:03 +08:00
|
|
|
enabled_setting.present?
|
2015-07-03 00:45:17 +08:00
|
|
|
end
|
|
|
|
|
2018-05-08 10:30:33 +08:00
|
|
|
def enabled_setting
|
2018-05-16 14:26:03 +08:00
|
|
|
object.enabled_site_setting
|
2018-05-08 10:30:33 +08:00
|
|
|
end
|
|
|
|
|
2024-05-23 10:04:26 +08:00
|
|
|
def plugin_settings
|
|
|
|
@plugin_settings ||= SiteSetting.plugins.select { |_, v| v == id }
|
|
|
|
end
|
|
|
|
|
2020-05-12 16:18:19 +08:00
|
|
|
def has_settings
|
2024-05-23 10:04:26 +08:00
|
|
|
plugin_settings.values.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_only_enabled_setting
|
|
|
|
plugin_settings.keys.length == 1 && plugin_settings.keys.first == enabled_setting
|
2020-05-12 16:18:19 +08:00
|
|
|
end
|
|
|
|
|
2015-02-07 07:08:57 +08:00
|
|
|
def include_url?
|
|
|
|
url.present?
|
|
|
|
end
|
|
|
|
|
2015-02-07 06:32:59 +08:00
|
|
|
def admin_route
|
|
|
|
route = object.admin_route
|
|
|
|
return unless route
|
|
|
|
|
|
|
|
ret = route.slice(:location, :label)
|
2024-03-13 11:15:12 +08:00
|
|
|
if route[:use_new_show_route]
|
2024-05-02 09:36:46 +08:00
|
|
|
ret[:full_location] = "adminPlugins.show"
|
2024-03-13 11:15:12 +08:00
|
|
|
ret[:use_new_show_route] = true
|
|
|
|
else
|
|
|
|
ret[:full_location] = "adminPlugins.#{ret[:location]}"
|
|
|
|
end
|
2015-02-07 06:32:59 +08:00
|
|
|
ret
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_admin_route?
|
|
|
|
admin_route.present?
|
|
|
|
end
|
2018-04-06 10:54:58 +08:00
|
|
|
|
|
|
|
def is_official
|
|
|
|
Plugin::Metadata::OFFICIAL_PLUGINS.include?(object.name)
|
|
|
|
end
|
2023-06-26 12:39:57 +08:00
|
|
|
|
2023-11-30 08:53:17 +08:00
|
|
|
def include_label?
|
|
|
|
is_discourse_owned
|
|
|
|
end
|
|
|
|
|
|
|
|
def label
|
|
|
|
return if !is_discourse_owned
|
|
|
|
object.metadata.label
|
2023-11-21 07:37:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_discourse_owned
|
|
|
|
object.discourse_owned?
|
|
|
|
end
|
|
|
|
|
2023-06-26 12:39:57 +08:00
|
|
|
def commit_hash
|
|
|
|
object.commit_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_url
|
|
|
|
object.commit_url
|
|
|
|
end
|
2023-10-10 08:16:13 +08:00
|
|
|
|
|
|
|
def meta_url
|
|
|
|
return if object.metadata.meta_topic_id.blank?
|
|
|
|
"https://meta.discourse.org/t/#{object.metadata.meta_topic_id}"
|
|
|
|
end
|
2015-02-07 06:32:59 +08:00
|
|
|
end
|