mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: Always preload admin plugin list for admin in sidebar (#25606)
When we show the links to installed plugins in the admin sidebar (for plugins that have custom admin routes) we were previously only doing this if you opened /admin, not if you navigated there from the main forum. We should just always preload this data if the user is admin. This commit also changes `admin_sidebar_enabled_groups` to not be sent to the client as part of ongoing efforts to not check groups on the client, since not all a user's groups may be serialized.
This commit is contained in:
37
plugins/chat/spec/requests/application_controller_spec.rb
Normal file
37
plugins/chat/spec/requests/application_controller_spec.rb
Normal file
@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe ApplicationController do
|
||||
fab!(:user)
|
||||
fab!(:admin)
|
||||
|
||||
def preloaded_json
|
||||
JSON.parse(
|
||||
Nokogiri::HTML5.fragment(response.body).css("div#data-preloaded").first["data-preloaded"],
|
||||
)
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.chat_enabled = true
|
||||
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
|
||||
end
|
||||
|
||||
context "when user is admin" do
|
||||
it "has correctly loaded preloaded data for enabledPluginAdminRoutes" do
|
||||
sign_in(admin)
|
||||
get "/latest"
|
||||
expect(JSON.parse(preloaded_json["enabledPluginAdminRoutes"])).to include(
|
||||
{ "label" => "chat.admin.title", "location" => "chat" },
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is not admin" do
|
||||
it "does not include preloaded data for enabledPluginAdminRoutes" do
|
||||
sign_in(user)
|
||||
get "/latest"
|
||||
expect(preloaded_json["enabledPluginAdminRoutes"]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user