Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPROVE: avoid attempting to modify admin route etc when logged out o… #34

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions assets/javascripts/discourse/lib/layouts.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -232,33 +232,37 @@ function setupContext(context) {
const model = contextAttr(context, "model");

withPluginApi("0.8.32", (api) => {
api.modifyClass(`route:${route}`, {
pluginId: PLUGIN_ID,

renderTemplate() {
this.render("sidebar-wrapper");
this.render(template, {
into: "sidebar-wrapper",
outlet: "main-content",
controller,
model: this.modelFor(model),
});
},
});

let controllerClass = `controller:${controller}`;
let controllerExists = api._resolveClass(controllerClass);
const currentUser = api.getCurrentUser();

if (controllerExists) {
const klass = api._resolveClass(controllerClass, {});
klass.class.reopen(Sidebars);
api.modifyClass(controllerClass, {
if (!((!currentUser || currentUser.admin === false) && route === "admin")) {
api.modifyClass(`route:${route}`, {
pluginId: PLUGIN_ID,
layouts_context: name,

renderTemplate() {
this.render("sidebar-wrapper");
this.render(template, {
into: "sidebar-wrapper",
outlet: "main-content",
controller,
model: this.modelFor(model),
});
},
});
} else {
// eslint-disable-next-line no-console
console.warn("Layouts context is missing a controller: ", name);

let controllerClass = `controller:${controller}`;
let controllerExists = api._resolveClass(controllerClass);

if (controllerExists) {
const klass = api._resolveClass(controllerClass, {});
klass.class.reopen(Sidebars);
api.modifyClass(controllerClass, {
pluginId: PLUGIN_ID,
layouts_context: name,
});
} else {
// eslint-disable-next-line no-console
console.warn("Layouts context is missing a controller: ", name);
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-layouts
# about: A framework for custom Discourse layouts.
# version: 0.3.4
# version: 0.3.5
# authors: Angus McLeod, Keegan George
# contact_emails: development@pavilion.tech
# url: https://github.com/paviliondev/discourse-layouts
Expand Down
Loading