在我的应用程序中,我需要根据这样的多对多关系授予用户访问组织的权限:
App.User = DS.Model.extend({
fullname: DS.attr('string'),
password: DS.attr('string'),
administrator: DS.attr('boolean'),
organisation_users: DS.hasMany('organisation_user', {async: true})
});
App.OrganisationUser = DS.Model.extend({
organisation: DS.belongsTo('organisation', {async: true}),
user: DS.belongsTo('user', {async: true}),
administrator: DS.attr('boolean')
});
App.Organisation = DS.Model.extend({
fullname: DS.attr('string', {defaultValue: 'Unnamed University'}),
description: DS.attr('string'),
organisation_users: DS.hasMany('organisation_user', {asynch: false}),
});
我正在使用 Ember SimpleAuth 进行身份验证。因此,基于对上一个问题的回答,我在我的 OrganisationController 上实现了 isAuthorised,如下所示:
App.OrganisationController = Ember.Controller.extend({
//Determine whether the logged in user is authorised
isAuthorised: function() {
if(!this.get('session.isAuthenticated')) {
console.log("Not logged in...");
return false;
}
console.log("Does user [" + this.get('session.user.id') + "] have access to organisation [" + this.get('model.id') + "]?");
if(this.get('session.user.administrator')) {
console.log("Yes, because they are an administrator.");
return true;
} else {
console.log("Well, they are not an administrator so...");
}
console.log("We need to check " + this.get('model.fullname') + " for authorised users.");
this.get('model.organisation_users').forEach(function(org_user){
org_user.get('user').then(function(user) {
console.log(user.get('fullname') + " has access");
});
});
}.property('model', 'session.user'),
问题是,我不知道如何从中返回值。此外,当我加载 OrganisationRoute 时,它似乎工作正常,但是当我加载不同的路线并过渡到这条路线时,它失败了
Uncaught TypeError: Cannot read property 'resolve' of undefined
和
Uncaught Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.