DEV: Refactor default new group permissions (#11221)

This commit is contained in:
Mark VanLandingham 2020-11-12 10:37:33 -06:00 committed by GitHub
parent 7fe0830fa8
commit fa29c2e7b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 4 deletions

View File

@ -1,17 +1,25 @@
import I18n from "I18n"; import I18n from "I18n";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { SEARCH_PRIORITIES } from "discourse/lib/constants"; import { SEARCH_PRIORITIES } from "discourse/lib/constants";
import { Promise } from "rsvp";
export default DiscourseRoute.extend({ export default DiscourseRoute.extend({
model() { model() {
const groups = this.site.groups, return Promise.resolve(this.groupPermissions())
everyoneName = groups.findBy("id", 0).name; .then((permissions) => {
return this.newCategoryWithPermissions(permissions);
})
.catch(() => {
return this.newCategoryWithPermissions(this.defaultGroupPermissions());
});
},
newCategoryWithPermissions(group_permissions) {
return this.store.createRecord("category", { return this.store.createRecord("category", {
color: "0088CC", color: "0088CC",
text_color: "FFFFFF", text_color: "FFFFFF",
group_permissions: [{ group_name: everyoneName, permission_type: 1 }], group_permissions,
available_groups: groups.map((g) => g.name), available_groups: this.site.groups.map((g) => g.name),
allow_badges: true, allow_badges: true,
topic_featured_link_allowed: true, topic_featured_link_allowed: true,
custom_fields: {}, custom_fields: {},
@ -23,6 +31,21 @@ export default DiscourseRoute.extend({
return I18n.t("category.create"); 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() { renderTemplate() {
this.render("edit-category-tabs", { this.render("edit-category-tabs", {
controller: "edit-category-tabs", controller: "edit-category-tabs",