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

View File

@ -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",