mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 00:43:43 +08:00
4e7a75a7ec
This commit adds new plugin show routes (`/admin/plugins/:plugin_id`) as we move towards every plugin having a consistent UI/landing page. As part of this, we are introducing a consistent way for plugins to show an inner sidebar in their config page, via a new plugin API `register_admin_config_nav_routes` This accepts an array of links with a label/text, and an ember route. Once this commit is merged we can start the process of conforming other plugins to follow this pattern, as well as supporting a single-page version of this for simpler plugins that don't require an inner sidebar. Part of /t/122841 internally
118 lines
2.0 KiB
Ruby
118 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AdminPluginSerializer < ApplicationSerializer
|
|
attributes :id,
|
|
:name,
|
|
:about,
|
|
:version,
|
|
:url,
|
|
:admin_route,
|
|
:enabled,
|
|
:enabled_setting,
|
|
:has_settings,
|
|
:is_official,
|
|
:is_discourse_owned,
|
|
:label,
|
|
:commit_hash,
|
|
:commit_url,
|
|
:meta_url,
|
|
:authors,
|
|
:admin_config_nav_routes
|
|
|
|
def admin_config_nav_routes
|
|
object.admin_config_nav_routes
|
|
end
|
|
|
|
def id
|
|
object.directory_name
|
|
end
|
|
|
|
def name
|
|
object.metadata.name
|
|
end
|
|
|
|
def about
|
|
object.metadata.about
|
|
end
|
|
|
|
def version
|
|
object.metadata.version
|
|
end
|
|
|
|
def url
|
|
object.metadata.url
|
|
end
|
|
|
|
def authors
|
|
object.metadata.authors
|
|
end
|
|
|
|
def enabled
|
|
object.enabled?
|
|
end
|
|
|
|
def include_enabled_setting?
|
|
enabled_setting.present?
|
|
end
|
|
|
|
def enabled_setting
|
|
object.enabled_site_setting
|
|
end
|
|
|
|
def has_settings
|
|
SiteSetting.plugins.values.include?(id)
|
|
end
|
|
|
|
def include_url?
|
|
url.present?
|
|
end
|
|
|
|
def admin_route
|
|
route = object.admin_route
|
|
return unless route
|
|
|
|
ret = route.slice(:location, :label)
|
|
if route[:use_new_show_route]
|
|
ret[:full_location] = "adminPlugins.show.#{ret[:location]}"
|
|
ret[:use_new_show_route] = true
|
|
else
|
|
ret[:full_location] = "adminPlugins.#{ret[:location]}"
|
|
end
|
|
ret
|
|
end
|
|
|
|
def include_admin_route?
|
|
admin_route.present?
|
|
end
|
|
|
|
def is_official
|
|
Plugin::Metadata::OFFICIAL_PLUGINS.include?(object.name)
|
|
end
|
|
|
|
def include_label?
|
|
is_discourse_owned
|
|
end
|
|
|
|
def label
|
|
return if !is_discourse_owned
|
|
object.metadata.label
|
|
end
|
|
|
|
def is_discourse_owned
|
|
object.discourse_owned?
|
|
end
|
|
|
|
def commit_hash
|
|
object.commit_hash
|
|
end
|
|
|
|
def commit_url
|
|
object.commit_url
|
|
end
|
|
|
|
def meta_url
|
|
return if object.metadata.meta_topic_id.blank?
|
|
"https://meta.discourse.org/t/#{object.metadata.meta_topic_id}"
|
|
end
|
|
end
|