diff --git a/app/assets/javascripts/discourse/app/routes/new-category.js b/app/assets/javascripts/discourse/app/routes/new-category.js index 20ab5603657..0ff104ea25c 100644 --- a/app/assets/javascripts/discourse/app/routes/new-category.js +++ b/app/assets/javascripts/discourse/app/routes/new-category.js @@ -1,17 +1,25 @@ import I18n from "I18n"; import DiscourseRoute from "discourse/routes/discourse"; import { SEARCH_PRIORITIES } from "discourse/lib/constants"; +import { Promise } from "rsvp"; export default DiscourseRoute.extend({ model() { - const groups = this.site.groups, - everyoneName = groups.findBy("id", 0).name; + return Promise.resolve(this.groupPermissions()) + .then((permissions) => { + return this.newCategoryWithPermissions(permissions); + }) + .catch(() => { + return this.newCategoryWithPermissions(this.defaultGroupPermissions()); + }); + }, + newCategoryWithPermissions(group_permissions) { return this.store.createRecord("category", { color: "0088CC", text_color: "FFFFFF", - group_permissions: [{ group_name: everyoneName, permission_type: 1 }], - available_groups: groups.map((g) => g.name), + group_permissions, + available_groups: this.site.groups.map((g) => g.name), allow_badges: true, topic_featured_link_allowed: true, custom_fields: {}, @@ -23,6 +31,21 @@ export default DiscourseRoute.extend({ return I18n.t("category.create"); }, + groupPermissions() { + // Override this function if you want different groupPermissions from a plugin. + // If your plugin override fails, permissions will fallback to defaultGroupPermissions + return this.defaultGroupPermissions(); + }, + + defaultGroupPermissions() { + return [ + { + group_name: this.site.groups.findBy("id", 0).name, + permission_type: 1, + }, + ]; + }, + renderTemplate() { this.render("edit-category-tabs", { controller: "edit-category-tabs",