-
Notifications
You must be signed in to change notification settings - Fork 51
Description
First of all, thanks for writing this addon, we are relying a lot on it in our app.
While upgrading to the latest version of ember-can we came across an issue that currently breaks our app.
We rely on the unknownProperty of EmberObject to match abilities with a preloaded list we get from our backend to avoid defining all of them by hands.
To give you some insight, here's our base ability class :
export default class Base extends Ability {
@alias('session.currentUser') user;
@alias('session.currentDistributor') distributor;
hasAbility(key) {
let user = this.get('user');
return user ? user.hasAbility(camelize(key.replace('can', '')), this.get('subject')) : false;
}
unknownProperty(key) {
return this.hasAbility(key);
}
}Unfortunately, there was a change introduced in 2d8a197#diff-6ef2539ada25eeefeef778ae6f0aef826e9bf2ba2e8b94cf138f1ea70267de2dR21, that breaks the helper in our case.
We get the error :
Uncaught (in promise) Error: Assertion Failed: You attempted to access the `canManage` property (of <idol@ability:product::ember524>).
Since Ember 3.1, this is usually fine as you no longer need to use `.get()`
to access computed properties. However, in this case, the object in question
is a special kind of Ember object (a proxy). Therefore, it is still necessary
to use `.get('canManage')` in this case.
This obviously happens because of our use of unknownProperty while ember-can doesn't use ember's get method to retrieve the abilities properties, removing it fixes the error.
I understand that you removed the use ember's get method to support native class but our issue can easily be fixed by checking if the ability inherits EmberObject like so :
if(ability instanceof EmberObject) {
return ability.get(propertyName);
}
return ability[propertyName];I can open a PR with our fix if this is something you'd be okay with.