odgn-rights 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/base-adapter.js +3 -1
- package/dist/adapters/postgres-adapter.js +4 -2
- package/dist/rights.d.ts +6 -0
- package/dist/rights.js +15 -0
- package/dist/role.d.ts +5 -0
- package/dist/role.js +17 -0
- package/package.json +1 -1
|
@@ -64,7 +64,9 @@ export class BaseAdapter {
|
|
|
64
64
|
validFrom: row.valid_from ? new Date(row.valid_from) : undefined,
|
|
65
65
|
validUntil: row.valid_until ? new Date(row.valid_until) : undefined
|
|
66
66
|
};
|
|
67
|
-
|
|
67
|
+
const right = new Right(row.path, init);
|
|
68
|
+
right._setDbId(row.id);
|
|
69
|
+
return right;
|
|
68
70
|
};
|
|
69
71
|
/**
|
|
70
72
|
* Convert a bitmask to an array of Flag values
|
|
@@ -233,11 +233,13 @@ export class PostgresAdapter extends BaseAdapter {
|
|
|
233
233
|
const roles = await this.loadRoles();
|
|
234
234
|
const roleMap = new Map();
|
|
235
235
|
for (const role of roles) {
|
|
236
|
-
registry
|
|
236
|
+
// Define the role in the registry and get the registered role back
|
|
237
|
+
const registeredRole = registry.define(role.name, role.rights);
|
|
237
238
|
const { roles: rolesTable } = this.tables;
|
|
238
239
|
const [roleRow] = await this.sql.unsafe(`SELECT id FROM ${rolesTable} WHERE name = $1`, [role.name]);
|
|
239
240
|
if (roleRow) {
|
|
240
|
-
|
|
241
|
+
// Store the registered role, not the original loaded role
|
|
242
|
+
roleMap.set(role.name, { id: roleRow.id, role: registeredRole });
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
const { roleInheritance } = this.tables;
|
package/dist/rights.d.ts
CHANGED
|
@@ -17,6 +17,12 @@ export declare class Rights {
|
|
|
17
17
|
set onChange(cb: () => void | undefined);
|
|
18
18
|
private notify;
|
|
19
19
|
add(right: Right): this;
|
|
20
|
+
/**
|
|
21
|
+
* Remove a specific right from the collection.
|
|
22
|
+
* @param right The right to remove
|
|
23
|
+
* @returns true if the right was found and removed, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
remove(right: Right): boolean;
|
|
20
26
|
findByTag(tag: string): Right[];
|
|
21
27
|
findByTags(tags: string[], mode?: 'and' | 'or'): Right[];
|
|
22
28
|
revokeByTag(tag: string): this;
|
package/dist/rights.js
CHANGED
|
@@ -18,6 +18,21 @@ export class Rights {
|
|
|
18
18
|
this.notify();
|
|
19
19
|
return this;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Remove a specific right from the collection.
|
|
23
|
+
* @param right The right to remove
|
|
24
|
+
* @returns true if the right was found and removed, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
remove(right) {
|
|
27
|
+
const idx = this.list.indexOf(right);
|
|
28
|
+
if (idx !== -1) {
|
|
29
|
+
this.list.splice(idx, 1);
|
|
30
|
+
this.matchCache.clear();
|
|
31
|
+
this.notify();
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
21
36
|
findByTag(tag) {
|
|
22
37
|
return this.list.filter(r => r.hasTag(tag));
|
|
23
38
|
}
|
package/dist/role.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare class Role {
|
|
|
9
9
|
private _cachedAllRights;
|
|
10
10
|
constructor(name: string, rights?: Rights);
|
|
11
11
|
inheritsFrom(role: Role): this;
|
|
12
|
+
/**
|
|
13
|
+
* Clear all parent role relationships.
|
|
14
|
+
* Useful when setting a new inheritance list.
|
|
15
|
+
*/
|
|
16
|
+
clearParents(): this;
|
|
12
17
|
/**
|
|
13
18
|
* Returns all rights associated with this role, including inherited ones.
|
|
14
19
|
*/
|
package/dist/role.js
CHANGED
|
@@ -20,6 +20,23 @@ export class Role {
|
|
|
20
20
|
}
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Clear all parent role relationships.
|
|
25
|
+
* Useful when setting a new inheritance list.
|
|
26
|
+
*/
|
|
27
|
+
clearParents() {
|
|
28
|
+
// Remove this role from each parent's children list
|
|
29
|
+
for (const parent of this.parents) {
|
|
30
|
+
const idx = parent.children.indexOf(this);
|
|
31
|
+
if (idx !== -1) {
|
|
32
|
+
parent.children.splice(idx, 1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Clear parents array
|
|
36
|
+
this.parents.length = 0;
|
|
37
|
+
this.invalidateCache();
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
23
40
|
/**
|
|
24
41
|
* Returns all rights associated with this role, including inherited ones.
|
|
25
42
|
*/
|