diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6 index fd99d494b6f..906d4e8fdf2 100644 --- a/app/assets/javascripts/discourse/models/category.js.es6 +++ b/app/assets/javascripts/discourse/models/category.js.es6 @@ -1,19 +1,24 @@ import RestModel from 'discourse/models/rest'; +import { on } from 'ember-addons/ember-computed-decorators'; const Category = RestModel.extend({ - init: function() { - this._super(); - var availableGroups = Em.A(this.get("available_groups")); - + @on('init') + setupGroupsAndPermissions() { + const availableGroups = this.get('available_groups'); + if (!availableGroups) { return; } this.set("availableGroups", availableGroups); - this.set("permissions", Em.A(_.map(this.group_permissions, function(elem){ - availableGroups.removeObject(elem.group_name); - return { - group_name: elem.group_name, - permission: Discourse.PermissionType.create({id: elem.permission_type}) - }; - }))); + + const groupPermissions = this.get('group_permissions'); + if (groupPermissions) { + this.set('permissions', groupPermissions.map((elem) => { + availableGroups.removeObject(elem.group_name); + return { + group_name: elem.group_name, + permission: Discourse.PermissionType.create({id: elem.permission_type}) + }; + })); + } }, availablePermissions: function(){ diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index b8654da919e..17023a74aab 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -129,6 +129,7 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, { editCategory(category) { Category.reloadById(category.get('id')).then((atts) => { const model = this.store.createRecord('category', atts.category); + model.setupGroupsAndPermissions(); this.site.updateCategory(model); showModal('editCategory', { model }); this.controllerFor('editCategory').set('selectedTab', 'general');