app factory AclHelper function return Checks if perm is included in th

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
app.factory('AclHelper', function() {
return {
/* Checks if `perm` is included in the `permList`. Handles wildcards ('*') and permission prefixes ('app.model:').
* Third parameter will be ignored if `perm` itself contains a prefix. Otherwise `prefix` will be prepended to
* the `perm` when performing the check.
*/
hasPerm: function(perm, permList, prefix) {
var not = perm.indexOf('!') == 0;
if (not)
perm = perm.slice(1);
var bits = perm.split(':');
if (bits.length > 1){
prefix = bits[0];
perm = bits[1];
}
var v = $.inArray('*', permList) >= 0 || $.inArray(perm, permList) >= 0;
if (!v && prefix != undefined){
v = $.inArray(prefix + ":*", permList) >= 0 || $.inArray(prefix + ":" + perm, permList) >= 0;
}
if (not)
v = !v;
return v;
}
}
});
// В контроллере потом (или где хочешь):
...
return AclHelper.has_perm('contacts.contact:update', contact._permissions);