mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 09:17:30 +08:00
DEV: Refactor default new group permissions (#11221)
This commit is contained in:
parent
7fe0830fa8
commit
fa29c2e7b9
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user