1 | import { PermissionKind } from "./types.js";
|
2 | import { SPInstance, SPQueryable } from "../spqueryable.js";
|
3 | import { spPost } from "../operations.js";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export async function getUserEffectivePermissions(loginName) {
|
10 | const q = SPInstance(this, "getUserEffectivePermissions(@user)");
|
11 | q.query.set("@user", `'${loginName}'`);
|
12 | return q();
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 | export async function getCurrentUserEffectivePermissions() {
|
18 | return SPQueryable(this, "EffectiveBasePermissions")();
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export async function breakRoleInheritance(copyRoleAssignments = false, clearSubscopes = false) {
|
27 | await spPost(SPQueryable(this, `breakroleinheritance(copyroleassignments=${copyRoleAssignments}, clearsubscopes=${clearSubscopes})`));
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export async function resetRoleInheritance() {
|
34 | await spPost(SPQueryable(this, "resetroleinheritance"));
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export async function userHasPermissions(loginName, permission) {
|
43 | const perms = await getUserEffectivePermissions.call(this, loginName);
|
44 | return this.hasPermissions(perms, permission);
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | export async function currentUserHasPermissions(permission) {
|
52 | const perms = await getCurrentUserEffectivePermissions.call(this);
|
53 | return this.hasPermissions(perms, permission);
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | export function hasPermissions(value, perm) {
|
63 | if (!perm) {
|
64 | return true;
|
65 | }
|
66 | if (perm === PermissionKind.FullMask) {
|
67 | return (value.High & 32767) === 32767 && value.Low === 65535;
|
68 | }
|
69 | perm = perm - 1;
|
70 | let num = 1;
|
71 | if (perm >= 0 && perm < 32) {
|
72 | num = num << perm;
|
73 | return 0 !== (value.Low & num);
|
74 | }
|
75 | else if (perm >= 32 && perm < 64) {
|
76 | num = num << perm - 32;
|
77 | return 0 !== (value.High & num);
|
78 | }
|
79 | return false;
|
80 | }
|
81 |
|
82 |
|
\ | No newline at end of file |