-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.rb
More file actions
56 lines (47 loc) · 2.22 KB
/
plugin.rb
File metadata and controls
56 lines (47 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
# name: discourse-mini-mod
# about: Allows category group moderators to create and edit categories
# version: 0.1.0
# authors: alltechdev
# url: https://github.com/discourse/discourse-mini-mod
# required_version: 2.7.0
# enabled_site_setting: mini_mod_enabled
require_relative "lib/discourse_mini_mod/categories_controller_extension"
require_relative "lib/discourse_mini_mod/guardian_extensions"
require_relative "lib/discourse_mini_mod/topic_extension"
require_relative "lib/discourse_mini_mod/topic_view_details_serializer_extension"
# Load the admin JS bundle for category group moderators so they can access
# the category edit/create routes (which live in the admin bundle).
# Security: this only loads client-side route handlers. All actual permissions
# are enforced server-side by Guardian. The admin bundle is a public static
# asset — loading it grants no server-side privileges.
register_html_builder("server:before-head-close") do |controller|
next "" if controller.blank?
user = controller.current_user
next "" if user.blank? || user.staff?
next "" unless SiteSetting.mini_mod_enabled
next "" unless SiteSetting.enable_category_group_moderation
guardian = Guardian.new(user)
next "" unless guardian.send(:category_group_moderator_scope).exists?
chunks = EmberCli.script_chunks["chunk.admin"]
next "" if chunks.blank?
nonce = controller.helpers.csp_nonce_placeholder
chunks
.map do |script_name|
path = controller.helpers.script_asset_path(script_name)
%(<link rel="preload" href="#{path}" as="script" nonce="#{nonce}" data-discourse-entrypoint="admin">)
end
.join("\n")
end
after_initialize do
reloadable_patch do
::Guardian.prepend(DiscourseMiniMod::GuardianExtensions)
::Topic.prepend(DiscourseMiniMod::TopicExtension)
::TopicViewDetailsSerializer.prepend(DiscourseMiniMod::TopicViewDetailsSerializerExtension)
::CategoriesController.include(DiscourseMiniMod::CategoriesControllerExtension)
end
add_to_serializer(:current_user, :can_admin_tags) { scope.can_admin_tags? }
add_to_serializer(:current_user, :include_can_admin_tags?) do
SiteSetting.mini_mod_enabled && SiteSetting.mini_mod_manage_tags && SiteSetting.tagging_enabled
end
end