1 |
|
2 |
|
3 | !function(exports) {
|
4 |
|
5 | exports.createAcl = createAcl
|
6 |
|
7 | function createAcl(fn, modelCache) {
|
8 |
|
9 | return {
|
10 | check: check
|
11 | }
|
12 |
|
13 | function check(aclGroups, acl, _inherit) {
|
14 | if (!acl || !Array.isArray(aclGroups)) return false
|
15 | var tmp, inherit
|
16 | , fields = ["id"]
|
17 | , arr = acl.inherit
|
18 | , i = Array.isArray(arr) && arr.length
|
19 | , sum = i
|
20 |
|
21 | if (i) for (inherit = _inherit || {}; i--; ) {
|
22 | tmp = acl.inherit[i]
|
23 | tmp = tmp && !inherit[tmp] && modelCache[inherit[tmp] = tmp]
|
24 | tmp = tmp && tmp.data.enabled && check(aclGroups, tmp.data.acl, inherit)
|
25 | if (tmp === true) return true
|
26 | if (tmp) fields.push.apply(fields, tmp)
|
27 | }
|
28 |
|
29 | arr = acl.policy
|
30 | i = Array.isArray(arr) && arr.length
|
31 | sum += i
|
32 |
|
33 | if (i) for (i = acl.policy.length; i--; ) {
|
34 | tmp = acl.policy[i]
|
35 | if (
|
36 | tmp &&
|
37 | Array.isArray(tmp.who) &&
|
38 | tmp.acl & (_inherit ? 2 : 1) &&
|
39 | tmp.who.some(inArray, aclGroups) &&
|
40 | fn(tmp.acl, fields) === true
|
41 | ) return true
|
42 | }
|
43 |
|
44 | return sum ? fields.length > 1 && fields : null
|
45 | }
|
46 | }
|
47 |
|
48 | function inArray(value) {
|
49 | return this.indexOf(value) > -1
|
50 | }
|
51 | }(this)
|
52 |
|
53 |
|