FIX: Use standard error handling for requests, special-case moderators (#84)

By removing the catch and letting the error propagate to the top-level error handler, we can receive more detailed error reports including exactly which request failed.

The assumption that any request failure is a permissions error is replaced by an explicit client-side check before making any requests.
This commit is contained in:
Kane York 2020-12-07 15:13:14 -08:00 committed by GitHub
parent f70c95271a
commit 4506cf6a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 23 deletions

View File

@ -1,40 +1,40 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import User from "discourse/models/user";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
controllerName: "admin-plugins-explorer", controllerName: "admin-plugins-explorer",
model() { model() {
if (!User.currentProp("admin")) {
// display "Only available to admins" message
return { model: null, schema: null, disallow: true, groups: null };
}
const groupPromise = ajax("/admin/plugins/explorer/groups.json"); const groupPromise = ajax("/admin/plugins/explorer/groups.json");
const schemaPromise = ajax("/admin/plugins/explorer/schema.json", { const schemaPromise = ajax("/admin/plugins/explorer/schema.json", {
cache: true, cache: true,
}); });
const queryPromise = this.store.findAll("query"); const queryPromise = this.store.findAll("query");
return groupPromise return groupPromise.then((groups) => {
.then((groups) => { let groupNames = {};
let groupNames = {}; groups.forEach((g) => {
groups.forEach((g) => { groupNames[g.id] = g.name;
groupNames[g.id] = g.name;
});
return schemaPromise.then((schema) => {
return queryPromise.then((model) => {
model.forEach((query) => {
query.markNotDirty();
query.set(
"group_names",
(query.group_ids || []).map((id) => groupNames[id])
);
});
return { model, schema, groups };
});
});
})
.catch(() => {
schemaPromise.catch(() => {});
queryPromise.catch(() => {});
return { model: null, schema: null, disallow: true, groups: null };
}); });
return schemaPromise.then((schema) => {
return queryPromise.then((model) => {
model.forEach((query) => {
query.markNotDirty();
query.set(
"group_names",
(query.group_ids || []).map((id) => groupNames[id])
);
});
return { model, schema, groups };
});
});
});
}, },
setupController(controller, model) { setupController(controller, model) {