rflib-plugin 0.22.0 → 0.23.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.
Files changed (37) hide show
  1. package/README.md +104 -0
  2. package/lib/commands/rflib/debug/recordaccess/get.d.ts +14 -0
  3. package/lib/commands/rflib/debug/recordaccess/get.js +58 -0
  4. package/lib/commands/rflib/debug/recordaccess/get.js.map +1 -0
  5. package/lib/commands/rflib/debug/userpermissions/compare.d.ts +17 -0
  6. package/lib/commands/rflib/debug/userpermissions/compare.js +115 -0
  7. package/lib/commands/rflib/debug/userpermissions/compare.js.map +1 -0
  8. package/lib/commands/rflib/debug/userpermissions/get.d.ts +1 -0
  9. package/lib/commands/rflib/debug/userpermissions/get.js +19 -6
  10. package/lib/commands/rflib/debug/userpermissions/get.js.map +1 -1
  11. package/lib/commands/rflib/debug/userpermissions/whohas.d.ts +22 -0
  12. package/lib/commands/rflib/debug/userpermissions/whohas.js +138 -0
  13. package/lib/commands/rflib/debug/userpermissions/whohas.js.map +1 -0
  14. package/lib/shared/orgClient.d.ts +6 -0
  15. package/lib/shared/orgClient.js +3 -0
  16. package/lib/shared/orgClient.js.map +1 -1
  17. package/lib/shared/permissionAggregator.d.ts +6 -0
  18. package/lib/shared/permissionAggregator.js +18 -1
  19. package/lib/shared/permissionAggregator.js.map +1 -1
  20. package/lib/shared/permissionCheck.d.ts +130 -12
  21. package/lib/shared/permissionCheck.js +60 -38
  22. package/lib/shared/permissionCheck.js.map +1 -1
  23. package/lib/shared/permissionEffective.d.ts +72 -0
  24. package/lib/shared/permissionEffective.js +218 -0
  25. package/lib/shared/permissionEffective.js.map +1 -0
  26. package/lib/shared/permissionWhoHas.d.ts +40 -0
  27. package/lib/shared/permissionWhoHas.js +232 -0
  28. package/lib/shared/permissionWhoHas.js.map +1 -0
  29. package/lib/shared/recordAccess.d.ts +41 -0
  30. package/lib/shared/recordAccess.js +117 -0
  31. package/lib/shared/recordAccess.js.map +1 -0
  32. package/messages/rflib.debug.recordaccess.get.md +59 -0
  33. package/messages/rflib.debug.userpermissions.compare.md +115 -0
  34. package/messages/rflib.debug.userpermissions.get.md +14 -0
  35. package/messages/rflib.debug.userpermissions.whohas.md +132 -0
  36. package/oclif.manifest.json +1076 -670
  37. package/package.json +5 -2
package/README.md CHANGED
@@ -258,14 +258,33 @@ sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX
258
258
 
259
259
  # Check Apex class/page access
260
260
  sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX --permission-type APEX
261
+
262
+ # Get the combined permissions of a user, including custom and system permissions
263
+ sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX --permission-type ALL --effective
264
+ ```
265
+
266
+ By default, the command returns the raw permission records of each profile, permission set, and permission set group. With `--effective`, it merges them into the user's combined permissions instead:
267
+
268
+ ```json
269
+ {
270
+ "objects": { "Account": ["read", "create", "edit", "delete"] },
271
+ "fields": { "Account.AnnualRevenue": ["read", "edit"] },
272
+ "apexClasses": ["OrderController", "rflib__Logger"],
273
+ "apexPages": [],
274
+ "customPermissions": ["Approve_Discounts"],
275
+ "systemPermissions": ["ApiEnabled", "ViewSetup"]
276
+ }
261
277
  ```
262
278
 
279
+ Field access is only listed where the user also has that access on the object. Fields without field-level security, such as `Id` or required fields, aren't listed because they follow the object permission. Custom and system permissions are only included for `--permission-type ALL`. With `--effective`, `--user-id` also accepts a username.
280
+
263
281
  #### Command Options
264
282
 
265
283
  - `--target-org (-o)`: Username or alias of the target org *(required)*
266
284
  - `--user-id (-u)`: Salesforce User ID (15 or 18 character) *(required)*
267
285
  - `--permission-type (-t)`: Type of permissions: `FLS`, `OLS`, `APEX`, or `ALL` *(required)*
268
286
  - `--sobject-type (-b)`: Optional SObject API name to filter FLS or OLS results (e.g. `Account`)
287
+ - `--effective (-e)`: Return the combined permissions instead of the raw permission records
269
288
 
270
289
  ---
271
290
 
@@ -322,6 +341,91 @@ The command only reads standard setup objects, so the RFLIB package doesn't need
322
341
 
323
342
  ---
324
343
 
344
+ ### `sf rflib debug userpermissions whohas`
345
+
346
+ The reverse of `userpermissions check`: find the users who have a specific permission, and the profiles, permission sets, and permission set groups that grant it.
347
+
348
+ ```bash
349
+ # Who can edit a field?
350
+ sf rflib debug userpermissions whohas --target-org myOrg --field Account.AnnualRevenue --access edit
351
+
352
+ # Who has Modify All Data?
353
+ sf rflib debug userpermissions whohas --target-org myOrg --system-permission ModifyAllData
354
+
355
+ # Who can access an Apex class, including inactive users?
356
+ sf rflib debug userpermissions whohas --target-org myOrg --apex-class OrderController --include-inactive
357
+ ```
358
+
359
+ The same permission rules as `userpermissions check` apply. For example, a field check only includes users who also have the matching access on the object, and an Apex class check includes users with Author Apex. The result lists the granting sources with the number of matching users for each, and the users with the sources that give them the access. Sources that grant the access but have no matching users are only counted (`unassignedSourceCount`).
360
+
361
+ #### Command Options
362
+
363
+ - `--target-org (-o)`: Username or alias of the target org *(required)*
364
+ - Exactly one of `--object (-b)`, `--field (-f)`, `--apex-class`, `--apex-page`, `--custom-permission`, or `--system-permission`, as for `userpermissions check`
365
+ - `--access (-a)`: Access level for `--object` or `--field` (default: `read`)
366
+ - `--include-inactive`: Include inactive users (default: only active users)
367
+ - `--user-limit (-l)`: Maximum number of users to return, 1–2000 (default: 200). The total is always returned in `userCount`.
368
+
369
+ ---
370
+
371
+ ### `sf rflib debug userpermissions compare`
372
+
373
+ Compare the permissions of two users and show only the differences, for example to find out why something works for one user but not for another.
374
+
375
+ ```bash
376
+ # Compare all permissions
377
+ sf rflib debug userpermissions compare --target-org myOrg --user jane@example.com --other-user bob@example.com
378
+
379
+ # Compare object and field access on Account
380
+ sf rflib debug userpermissions compare --target-org myOrg --user jane@example.com --other-user bob@example.com --permission-type FLS --sobject-type Account
381
+ ```
382
+
383
+ Example output:
384
+
385
+ ```text
386
+ Comparing jane@example.com with bob@example.com
387
+ Objects:
388
+ Account: only bob@example.com has delete, viewall
389
+ Fields:
390
+ Account.AnnualRevenue: only bob@example.com has edit
391
+ System permissions:
392
+ only bob@example.com has ModifyAllData
393
+ ```
394
+
395
+ The comparison uses the same combined permissions as `userpermissions get --effective`. In large orgs, use `--sobject-type` to keep the field comparison below the query row limit.
396
+
397
+ #### Command Options
398
+
399
+ - `--target-org (-o)`: Username or alias of the target org *(required)*
400
+ - `--user (-u)`: User ID or username of the first user *(required)*
401
+ - `--other-user (-w)`: User ID or username of the second user *(required)*
402
+ - `--permission-type (-t)`: `FLS`, `OLS`, `APEX`, or `ALL` (default: `ALL`, which also compares custom and system permissions)
403
+ - `--sobject-type (-b)`: Optional SObject API name to limit the object and field comparison to
404
+
405
+ ---
406
+
407
+ ### `sf rflib debug recordaccess get`
408
+
409
+ Check a user's access to specific records, including sharing (org-wide defaults, role hierarchy, sharing rules, teams, and manual shares), with `UserRecordAccess`.
410
+
411
+ ```bash
412
+ sf rflib debug recordaccess get --target-org myOrg --user jane@example.com --record-id 001XXXXXXXXXXXXXXX --record-id 006XXXXXXXXXXXXXXX
413
+ ```
414
+
415
+ For each record, the result contains the read, edit, delete, transfer, and full access flags, the highest access level, and the user's object permissions on the record's object. The notes tell apart missing object permissions from missing sharing, for example:
416
+
417
+ ```text
418
+ 001XXXXXXXXXXXXXXX: The user has Read on Account, but sharing doesn't give them access to this record. Check the org-wide default, role hierarchy, sharing rules, teams, and manual shares.
419
+ ```
420
+
421
+ #### Command Options
422
+
423
+ - `--target-org (-o)`: Username or alias of the target org *(required)*
424
+ - `--user (-u)`: User ID or username *(required)*
425
+ - `--record-id (-r)`: ID of a record to check; specify up to 200 times *(required)*
426
+
427
+ ---
428
+
325
429
  ## RFLIB Package Commands
326
430
 
327
431
  ### `sf rflib packages upgrade`
@@ -0,0 +1,14 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { type RecordAccessResult } from '../../../../shared/orgClient.js';
3
+ export type RflibDebugRecordAccessGetResult = RecordAccessResult;
4
+ export default class RflibDebugRecordAccessGet extends SfCommand<RflibDebugRecordAccessGetResult> {
5
+ static readonly summary: string;
6
+ static readonly description: string;
7
+ static readonly examples: string[];
8
+ static readonly flags: {
9
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
10
+ user: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'record-id': import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
12
+ };
13
+ run(): Promise<RflibDebugRecordAccessGetResult>;
14
+ }
@@ -0,0 +1,58 @@
1
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
2
+ import { Messages } from '@salesforce/core';
3
+ import { getRecordAccess } from '../../../../shared/orgClient.js';
4
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
5
+ const messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.recordaccess.get');
6
+ export default class RflibDebugRecordAccessGet extends SfCommand {
7
+ static summary = messages.getMessage('summary');
8
+ static description = messages.getMessage('description');
9
+ static examples = messages.getMessages('examples');
10
+ static flags = {
11
+ 'target-org': Flags.requiredOrg({
12
+ summary: messages.getMessage('flags.target-org.summary'),
13
+ description: messages.getMessage('flags.target-org.description'),
14
+ char: 'o',
15
+ required: true,
16
+ }),
17
+ user: Flags.string({
18
+ summary: messages.getMessage('flags.user.summary'),
19
+ description: messages.getMessage('flags.user.description'),
20
+ char: 'u',
21
+ required: true,
22
+ }),
23
+ 'record-id': Flags.string({
24
+ summary: messages.getMessage('flags.record-id.summary'),
25
+ description: messages.getMessage('flags.record-id.description'),
26
+ char: 'r',
27
+ required: true,
28
+ multiple: true,
29
+ }),
30
+ };
31
+ async run() {
32
+ const { flags } = await this.parse(RflibDebugRecordAccessGet);
33
+ const conn = flags['target-org'].getConnection(undefined);
34
+ this.spinner.start('Checking record access...');
35
+ const result = await getRecordAccess(conn, { user: flags.user, recordIds: flags['record-id'] });
36
+ this.spinner.stop();
37
+ this.log(messages.getMessage('info.user', [result.user.username]));
38
+ this.table({
39
+ data: result.records.map((record) => ({
40
+ recordId: record.recordId,
41
+ object: record.sobjectType ?? '',
42
+ access: record.found ? record.maxAccessLevel : messages.getMessage('info.notFound'),
43
+ })),
44
+ columns: [
45
+ { key: 'recordId', name: 'Record ID' },
46
+ { key: 'object', name: 'Object' },
47
+ { key: 'access', name: 'Max Access' },
48
+ ],
49
+ });
50
+ for (const record of result.records) {
51
+ for (const note of record.notes) {
52
+ this.log(messages.getMessage('info.note', [record.recordId, note]));
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ }
58
+ //# sourceMappingURL=get.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/debug/recordaccess/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAA2B,MAAM,iCAAiC,CAAC;AAI3F,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,8BAA8B,CAAC,CAAC;AAEvF,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,SAA0C;IACxF,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC;YAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC;YAC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O,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBACpC,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,MAAM,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;gBAChC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC;aACpF,CAAC,CAAC;YACH,OAAO,EAAE;gBACP,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE;gBACtC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACjC,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE;aACtC;SACF,CAAC,CAAC;QACH,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["import { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages } from '@salesforce/core';\nimport { getRecordAccess, type RecordAccessResult } from '../../../../shared/orgClient.js';\n\nexport type RflibDebugRecordAccessGetResult = RecordAccessResult;\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.recordaccess.get');\n\nexport default class RflibDebugRecordAccessGet extends SfCommand<RflibDebugRecordAccessGetResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n 'target-org': Flags.requiredOrg({\n summary: messages.getMessage('flags.target-org.summary'),\n description: messages.getMessage('flags.target-org.description'),\n char: 'o',\n required: true,\n }),\n user: Flags.string({\n summary: messages.getMessage('flags.user.summary'),\n description: messages.getMessage('flags.user.description'),\n char: 'u',\n required: true,\n }),\n 'record-id': Flags.string({\n summary: messages.getMessage('flags.record-id.summary'),\n description: messages.getMessage('flags.record-id.description'),\n char: 'r',\n required: true,\n multiple: true,\n }),\n };\n\n public async run(): Promise<RflibDebugRecordAccessGetResult> {\n const { flags } = await this.parse(RflibDebugRecordAccessGet);\n const conn = flags['target-org'].getConnection(undefined);\n\n this.spinner.start('Checking record access...');\n const result = await getRecordAccess(conn, { user: flags.user, recordIds: flags['record-id'] });\n this.spinner.stop();\n\n this.log(messages.getMessage('info.user', [result.user.username]));\n this.table({\n data: result.records.map((record) => ({\n recordId: record.recordId,\n object: record.sobjectType ?? '',\n access: record.found ? record.maxAccessLevel : messages.getMessage('info.notFound'),\n })),\n columns: [\n { key: 'recordId', name: 'Record ID' },\n { key: 'object', name: 'Object' },\n { key: 'access', name: 'Max Access' },\n ],\n });\n for (const record of result.records) {\n for (const note of record.notes) {\n this.log(messages.getMessage('info.note', [record.recordId, note]));\n }\n }\n return result;\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { type ComparePermissionsResult } from '../../../../shared/orgClient.js';
3
+ export type RflibDebugUserPermissionsCompareResult = ComparePermissionsResult;
4
+ export default class RflibDebugUserPermissionsCompare extends SfCommand<RflibDebugUserPermissionsCompareResult> {
5
+ static readonly summary: string;
6
+ static readonly description: string;
7
+ static readonly examples: string[];
8
+ static readonly flags: {
9
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
10
+ user: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'other-user': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'permission-type': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'sobject-type': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ };
15
+ run(): Promise<RflibDebugUserPermissionsCompareResult>;
16
+ private report;
17
+ }
@@ -0,0 +1,115 @@
1
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
2
+ import { Messages } from '@salesforce/core';
3
+ import { comparePermissions, } from '../../../../shared/orgClient.js';
4
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
5
+ const messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.compare');
6
+ const LIST_SECTIONS = [
7
+ ['apexClasses', 'info.section.apexClasses'],
8
+ ['apexPages', 'info.section.apexPages'],
9
+ ['customPermissions', 'info.section.customPermissions'],
10
+ ['systemPermissions', 'info.section.systemPermissions'],
11
+ ];
12
+ // Admins can have hundreds of Apex classes or system permissions; the JSON result has all of them.
13
+ const MAX_LISTED = 20;
14
+ function formatList(items) {
15
+ if (items.length <= MAX_LISTED)
16
+ return items.join(', ');
17
+ return messages.getMessage('info.andMore', [items.slice(0, MAX_LISTED).join(', '), items.length - MAX_LISTED]);
18
+ }
19
+ function describeDiff(diff, user, other) {
20
+ const parts = [];
21
+ if (diff.onlyUser.length > 0)
22
+ parts.push(messages.getMessage('info.onlyUser', [user, diff.onlyUser.join(', ')]));
23
+ if (diff.onlyOtherUser.length > 0) {
24
+ parts.push(messages.getMessage('info.onlyUser', [other, diff.onlyOtherUser.join(', ')]));
25
+ }
26
+ return parts.join('; ');
27
+ }
28
+ export default class RflibDebugUserPermissionsCompare extends SfCommand {
29
+ static summary = messages.getMessage('summary');
30
+ static description = messages.getMessage('description');
31
+ static examples = messages.getMessages('examples');
32
+ static flags = {
33
+ 'target-org': Flags.requiredOrg({
34
+ summary: messages.getMessage('flags.target-org.summary'),
35
+ description: messages.getMessage('flags.target-org.description'),
36
+ char: 'o',
37
+ required: true,
38
+ }),
39
+ user: Flags.string({
40
+ summary: messages.getMessage('flags.user.summary'),
41
+ description: messages.getMessage('flags.user.description'),
42
+ char: 'u',
43
+ required: true,
44
+ }),
45
+ 'other-user': Flags.string({
46
+ summary: messages.getMessage('flags.other-user.summary'),
47
+ description: messages.getMessage('flags.other-user.description'),
48
+ char: 'w',
49
+ required: true,
50
+ }),
51
+ 'permission-type': Flags.string({
52
+ summary: messages.getMessage('flags.permission-type.summary'),
53
+ description: messages.getMessage('flags.permission-type.description'),
54
+ char: 't',
55
+ options: ['FLS', 'OLS', 'APEX', 'ALL'],
56
+ default: 'ALL',
57
+ }),
58
+ 'sobject-type': Flags.string({
59
+ summary: messages.getMessage('flags.sobject-type.summary'),
60
+ description: messages.getMessage('flags.sobject-type.description'),
61
+ char: 'b',
62
+ }),
63
+ };
64
+ async run() {
65
+ const { flags } = await this.parse(RflibDebugUserPermissionsCompare);
66
+ const conn = flags['target-org'].getConnection(undefined);
67
+ this.spinner.start('Comparing user permissions...');
68
+ const result = await comparePermissions(conn, {
69
+ user: flags.user,
70
+ otherUser: flags['other-user'],
71
+ permissionType: flags['permission-type'],
72
+ sobjectType: flags['sobject-type'],
73
+ });
74
+ this.spinner.stop();
75
+ this.report(result);
76
+ return result;
77
+ }
78
+ report(result) {
79
+ const user = result.user.username;
80
+ const other = result.otherUser.username;
81
+ this.log(messages.getMessage('info.comparing', [user, other]));
82
+ if (result.identical) {
83
+ this.log(messages.getMessage('info.identical'));
84
+ }
85
+ for (const [key, section] of [
86
+ ['objects', 'info.section.objects'],
87
+ ['fields', 'info.section.fields'],
88
+ ]) {
89
+ const entries = Object.entries(result[key] ?? {});
90
+ if (entries.length === 0)
91
+ continue;
92
+ this.log(messages.getMessage(section));
93
+ for (const [name, diff] of entries) {
94
+ this.log(` ${messages.getMessage('info.accessDiff', [name, describeDiff(diff, user, other)])}`);
95
+ }
96
+ }
97
+ for (const [key, section] of LIST_SECTIONS) {
98
+ const diff = result[key];
99
+ if (!diff || (diff.onlyUser.length === 0 && diff.onlyOtherUser.length === 0))
100
+ continue;
101
+ this.log(messages.getMessage(section));
102
+ // Indented here because the message loader strips leading whitespace.
103
+ if (diff.onlyUser.length > 0) {
104
+ this.log(` ${messages.getMessage('info.onlyUser', [user, formatList(diff.onlyUser)])}`);
105
+ }
106
+ if (diff.onlyOtherUser.length > 0) {
107
+ this.log(` ${messages.getMessage('info.onlyUser', [other, formatList(diff.onlyOtherUser)])}`);
108
+ }
109
+ }
110
+ for (const note of result.notes) {
111
+ this.log(messages.getMessage('info.note', [note]));
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/debug/userpermissions/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,kBAAkB,GAGnB,MAAM,iCAAiC,CAAC;AAIzC,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,qCAAqC,CAAC,CAAC;AAE9F,MAAM,aAAa,GAAG;IACpB,CAAC,aAAa,EAAE,0BAA0B,CAAC;IAC3C,CAAC,WAAW,EAAE,wBAAwB,CAAC;IACvC,CAAC,mBAAmB,EAAE,gCAAgC,CAAC;IACvD,CAAC,mBAAmB,EAAE,gCAAgC,CAAC;CAC/C,CAAC;AAEX,mGAAmG;AACnG,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,SAAS,UAAU,CAAC,KAAwB;IAC1C,IAAI,KAAK,CAAC,MAAM,IAAI,UAAU;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,IAA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C,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC;IACH,CAAC","sourcesContent":["import { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages } from '@salesforce/core';\nimport {\n comparePermissions,\n type ComparePermissionsResult,\n type PermissionType,\n} from '../../../../shared/orgClient.js';\n\nexport type RflibDebugUserPermissionsCompareResult = ComparePermissionsResult;\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.compare');\n\nconst LIST_SECTIONS = [\n ['apexClasses', 'info.section.apexClasses'],\n ['apexPages', 'info.section.apexPages'],\n ['customPermissions', 'info.section.customPermissions'],\n ['systemPermissions', 'info.section.systemPermissions'],\n] as const;\n\n// Admins can have hundreds of Apex classes or system permissions; the JSON result has all of them.\nconst MAX_LISTED = 20;\n\nfunction formatList(items: readonly string[]): string {\n if (items.length <= MAX_LISTED) return items.join(', ');\n return messages.getMessage('info.andMore', [items.slice(0, MAX_LISTED).join(', '), items.length - MAX_LISTED]);\n}\n\nfunction describeDiff(diff: { onlyUser: string[]; onlyOtherUser: string[] }, user: string, other: string): string {\n const parts: string[] = [];\n if (diff.onlyUser.length > 0) parts.push(messages.getMessage('info.onlyUser', [user, diff.onlyUser.join(', ')]));\n if (diff.onlyOtherUser.length > 0) {\n parts.push(messages.getMessage('info.onlyUser', [other, diff.onlyOtherUser.join(', ')]));\n }\n return parts.join('; ');\n}\n\nexport default class RflibDebugUserPermissionsCompare extends SfCommand<RflibDebugUserPermissionsCompareResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n 'target-org': Flags.requiredOrg({\n summary: messages.getMessage('flags.target-org.summary'),\n description: messages.getMessage('flags.target-org.description'),\n char: 'o',\n required: true,\n }),\n user: Flags.string({\n summary: messages.getMessage('flags.user.summary'),\n description: messages.getMessage('flags.user.description'),\n char: 'u',\n required: true,\n }),\n 'other-user': Flags.string({\n summary: messages.getMessage('flags.other-user.summary'),\n description: messages.getMessage('flags.other-user.description'),\n char: 'w',\n required: true,\n }),\n 'permission-type': Flags.string({\n summary: messages.getMessage('flags.permission-type.summary'),\n description: messages.getMessage('flags.permission-type.description'),\n char: 't',\n options: ['FLS', 'OLS', 'APEX', 'ALL'],\n default: 'ALL',\n }),\n 'sobject-type': Flags.string({\n summary: messages.getMessage('flags.sobject-type.summary'),\n description: messages.getMessage('flags.sobject-type.description'),\n char: 'b',\n }),\n };\n\n public async run(): Promise<RflibDebugUserPermissionsCompareResult> {\n const { flags } = await this.parse(RflibDebugUserPermissionsCompare);\n const conn = flags['target-org'].getConnection(undefined);\n\n this.spinner.start('Comparing user permissions...');\n const result = await comparePermissions(conn, {\n user: flags.user,\n otherUser: flags['other-user'],\n permissionType: flags['permission-type'] as PermissionType,\n sobjectType: flags['sobject-type'],\n });\n this.spinner.stop();\n\n this.report(result);\n return result;\n }\n\n private report(result: ComparePermissionsResult): void {\n const user = result.user.username;\n const other = result.otherUser.username;\n this.log(messages.getMessage('info.comparing', [user, other]));\n if (result.identical) {\n this.log(messages.getMessage('info.identical'));\n }\n\n for (const [key, section] of [\n ['objects', 'info.section.objects'],\n ['fields', 'info.section.fields'],\n ] as const) {\n const entries = Object.entries(result[key] ?? {});\n if (entries.length === 0) continue;\n this.log(messages.getMessage(section));\n for (const [name, diff] of entries) {\n this.log(` ${messages.getMessage('info.accessDiff', [name, describeDiff(diff, user, other)])}`);\n }\n }\n\n for (const [key, section] of LIST_SECTIONS) {\n const diff = result[key];\n if (!diff || (diff.onlyUser.length === 0 && diff.onlyOtherUser.length === 0)) continue;\n this.log(messages.getMessage(section));\n // Indented here because the message loader strips leading whitespace.\n if (diff.onlyUser.length > 0) {\n this.log(` ${messages.getMessage('info.onlyUser', [user, formatList(diff.onlyUser)])}`);\n }\n if (diff.onlyOtherUser.length > 0) {\n this.log(` ${messages.getMessage('info.onlyUser', [other, formatList(diff.onlyOtherUser)])}`);\n }\n }\n\n for (const note of result.notes) {\n this.log(messages.getMessage('info.note', [note]));\n }\n }\n}\n"]}
@@ -9,6 +9,7 @@ export default class RflibDebugUserPermissionsGet extends SfCommand<RflibDebugUs
9
9
  'user-id': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
10
  'permission-type': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
11
  'sobject-type': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ effective: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
13
  };
13
14
  run(): Promise<RflibDebugUserPermissionsGetResult>;
14
15
  }
@@ -1,6 +1,6 @@
1
1
  import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
2
2
  import { Messages } from '@salesforce/core';
3
- import { getUserPermissions } from '../../../../shared/orgClient.js';
3
+ import { getEffectivePermissions, getUserPermissions } from '../../../../shared/orgClient.js';
4
4
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
5
5
  const messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.get');
6
6
  export default class RflibDebugUserPermissionsGet extends SfCommand {
@@ -32,16 +32,29 @@ export default class RflibDebugUserPermissionsGet extends SfCommand {
32
32
  description: messages.getMessage('flags.sobject-type.description'),
33
33
  char: 'b',
34
34
  }),
35
+ effective: Flags.boolean({
36
+ summary: messages.getMessage('flags.effective.summary'),
37
+ description: messages.getMessage('flags.effective.description'),
38
+ char: 'e',
39
+ default: false,
40
+ }),
35
41
  };
36
42
  async run() {
37
43
  const { flags } = await this.parse(RflibDebugUserPermissionsGet);
38
44
  const conn = flags['target-org'].getConnection(undefined);
39
45
  this.spinner.start('Retrieving user permissions...');
40
- const payload = await getUserPermissions(conn, {
41
- userId: flags['user-id'],
42
- permissionType: flags['permission-type'],
43
- sobjectType: flags['sobject-type'],
44
- });
46
+ const permissionType = flags['permission-type'];
47
+ const payload = flags.effective
48
+ ? await getEffectivePermissions(conn, {
49
+ user: flags['user-id'],
50
+ permissionType,
51
+ sobjectType: flags['sobject-type'],
52
+ })
53
+ : await getUserPermissions(conn, {
54
+ userId: flags['user-id'],
55
+ permissionType,
56
+ sobjectType: flags['sobject-type'],
57
+ });
45
58
  this.spinner.stop();
46
59
  // For human invocations, render the payload as JSON. Under --json, SfCommand
47
60
  // suppresses log output and wraps this method's return value directly.
@@ -1 +1 @@
1
- {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/debug/userpermissions/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAuB,MAAM,iCAAiC,CAAC;AAI1F,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,iCAAiC,CAAC,CAAC;AAE1F,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAA6C;IAC9F,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC;YAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC;YACxD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;YAChE,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,I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E,CAAC;QAEpB,6EAA6E;QAC7E,uEAAuE;QACvE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC;IACjB,CAAC","sourcesContent":["import { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages } from '@salesforce/core';\nimport { getUserPermissions, type PermissionType } from '../../../../shared/orgClient.js';\n\nexport type RflibDebugUserPermissionsGetResult = Record<string, unknown>;\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.get');\n\nexport default class RflibDebugUserPermissionsGet extends SfCommand<RflibDebugUserPermissionsGetResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n 'target-org': Flags.requiredOrg({\n summary: messages.getMessage('flags.target-org.summary'),\n description: messages.getMessage('flags.target-org.description'),\n char: 'o',\n required: true,\n }),\n 'user-id': Flags.string({\n summary: messages.getMessage('flags.user-id.summary'),\n description: messages.getMessage('flags.user-id.description'),\n char: 'u',\n required: true,\n }),\n 'permission-type': Flags.string({\n summary: messages.getMessage('flags.permission-type.summary'),\n description: messages.getMessage('flags.permission-type.description'),\n char: 't',\n required: true,\n options: ['FLS', 'OLS', 'APEX', 'ALL'],\n }),\n 'sobject-type': Flags.string({\n summary: messages.getMessage('flags.sobject-type.summary'),\n description: messages.getMessage('flags.sobject-type.description'),\n char: 'b',\n }),\n };\n\n public async run(): Promise<RflibDebugUserPermissionsGetResult> {\n const { flags } = await this.parse(RflibDebugUserPermissionsGet);\n const conn = flags['target-org'].getConnection(undefined);\n\n this.spinner.start('Retrieving user permissions...');\n const payload = await getUserPermissions(conn, {\n userId: flags['user-id'],\n permissionType: flags['permission-type'] as PermissionType,\n sobjectType: flags['sobject-type'],\n });\n this.spinner.stop();\n\n // For human invocations, render the payload as JSON. Under --json, SfCommand\n // suppresses log output and wraps this method's return value directly.\n this.log(JSON.stringify(payload));\n return payload;\n }\n}\n"]}
1
+ {"version":3,"file":"get.js","sourceRoot":"","sources":["../../../../../src/commands/rflib/debug/userpermissions/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAuB,MAAM,iCAAiC,CAAC;AAKnH,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,EAAE,iCAAiC,CAAC,CAAC;AAE1F,MAAM,CAAC,OAAO,OAAO,4BAA6B,SAAQ,SAA6C;IAC9F,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC;YAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,0BAA0B,CAAC;YACxD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC;YAChE,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC;YACrD,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,2BAA2B,CAAC;YAC7D,IAAI,EAAE,GAAG;YACT,QAAQ,EAA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,CAAC;aACnC,CAAC;YACJ,CAAC,CAAC,MAAM,kBAAkB,CAAC,IAAI,EAAE;gBAC7B,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;gBACxB,cAAc;gBACd,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC;aACnC,CAAC,CAAC;QACP,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAEpB,6EAA6E;QAC7E,uEAAuE;QACvE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC;IACjB,CAAC","sourcesContent":["import { SfCommand, Flags } from '@salesforce/sf-plugins-core';\nimport { Messages } from '@salesforce/core';\nimport { getEffectivePermissions, getUserPermissions, type PermissionType } from '../../../../shared/orgClient.js';\n\n// With --effective, the result has the shape of EffectivePermissions.\nexport type RflibDebugUserPermissionsGetResult = Record<string, unknown>;\n\nMessages.importMessagesDirectoryFromMetaUrl(import.meta.url);\nconst messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.get');\n\nexport default class RflibDebugUserPermissionsGet extends SfCommand<RflibDebugUserPermissionsGetResult> {\n public static readonly summary = messages.getMessage('summary');\n public static readonly description = messages.getMessage('description');\n public static readonly examples = messages.getMessages('examples');\n\n public static readonly flags = {\n 'target-org': Flags.requiredOrg({\n summary: messages.getMessage('flags.target-org.summary'),\n description: messages.getMessage('flags.target-org.description'),\n char: 'o',\n required: true,\n }),\n 'user-id': Flags.string({\n summary: messages.getMessage('flags.user-id.summary'),\n description: messages.getMessage('flags.user-id.description'),\n char: 'u',\n required: true,\n }),\n 'permission-type': Flags.string({\n summary: messages.getMessage('flags.permission-type.summary'),\n description: messages.getMessage('flags.permission-type.description'),\n char: 't',\n required: true,\n options: ['FLS', 'OLS', 'APEX', 'ALL'],\n }),\n 'sobject-type': Flags.string({\n summary: messages.getMessage('flags.sobject-type.summary'),\n description: messages.getMessage('flags.sobject-type.description'),\n char: 'b',\n }),\n effective: Flags.boolean({\n summary: messages.getMessage('flags.effective.summary'),\n description: messages.getMessage('flags.effective.description'),\n char: 'e',\n default: false,\n }),\n };\n\n public async run(): Promise<RflibDebugUserPermissionsGetResult> {\n const { flags } = await this.parse(RflibDebugUserPermissionsGet);\n const conn = flags['target-org'].getConnection(undefined);\n\n this.spinner.start('Retrieving user permissions...');\n const permissionType = flags['permission-type'] as PermissionType;\n const payload = flags.effective\n ? await getEffectivePermissions(conn, {\n user: flags['user-id'],\n permissionType,\n sobjectType: flags['sobject-type'],\n })\n : await getUserPermissions(conn, {\n userId: flags['user-id'],\n permissionType,\n sobjectType: flags['sobject-type'],\n });\n this.spinner.stop();\n\n // For human invocations, render the payload as JSON. Under --json, SfCommand\n // suppresses log output and wraps this method's return value directly.\n this.log(JSON.stringify(payload));\n return payload;\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { type WhoHasPermissionResult } from '../../../../shared/orgClient.js';
3
+ export type RflibDebugUserPermissionsWhoHasResult = WhoHasPermissionResult;
4
+ export default class RflibDebugUserPermissionsWhoHas extends SfCommand<RflibDebugUserPermissionsWhoHasResult> {
5
+ static readonly summary: string;
6
+ static readonly description: string;
7
+ static readonly examples: string[];
8
+ static readonly flags: {
9
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
10
+ object: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ field: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ access: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ 'apex-class': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ 'apex-page': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ 'custom-permission': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ 'system-permission': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ 'include-inactive': import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ 'user-limit': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
19
+ };
20
+ run(): Promise<RflibDebugUserPermissionsWhoHasResult>;
21
+ private report;
22
+ }
@@ -0,0 +1,138 @@
1
+ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
2
+ import { Messages } from '@salesforce/core';
3
+ import { ACCESS_LEVELS, whoHasPermission } from '../../../../shared/orgClient.js';
4
+ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
5
+ const messages = Messages.loadMessages('rflib-plugin', 'rflib.debug.userpermissions.whohas');
6
+ const CHECK_FLAGS = ['object', 'field', 'apex-class', 'apex-page', 'custom-permission', 'system-permission'];
7
+ const SOURCE_LABELS = {
8
+ Profile: 'Profile',
9
+ PermissionSet: 'Permission Set',
10
+ PermissionSetGroup: 'Permission Set Group',
11
+ };
12
+ export default class RflibDebugUserPermissionsWhoHas extends SfCommand {
13
+ static summary = messages.getMessage('summary');
14
+ static description = messages.getMessage('description');
15
+ static examples = messages.getMessages('examples');
16
+ static flags = {
17
+ 'target-org': Flags.requiredOrg({
18
+ summary: messages.getMessage('flags.target-org.summary'),
19
+ description: messages.getMessage('flags.target-org.description'),
20
+ char: 'o',
21
+ required: true,
22
+ }),
23
+ object: Flags.string({
24
+ summary: messages.getMessage('flags.object.summary'),
25
+ description: messages.getMessage('flags.object.description'),
26
+ char: 'b',
27
+ exactlyOne: CHECK_FLAGS,
28
+ }),
29
+ field: Flags.string({
30
+ summary: messages.getMessage('flags.field.summary'),
31
+ description: messages.getMessage('flags.field.description'),
32
+ char: 'f',
33
+ exactlyOne: CHECK_FLAGS,
34
+ }),
35
+ access: Flags.string({
36
+ summary: messages.getMessage('flags.access.summary'),
37
+ description: messages.getMessage('flags.access.description'),
38
+ char: 'a',
39
+ options: ACCESS_LEVELS,
40
+ }),
41
+ 'apex-class': Flags.string({
42
+ summary: messages.getMessage('flags.apex-class.summary'),
43
+ description: messages.getMessage('flags.apex-class.description'),
44
+ exactlyOne: CHECK_FLAGS,
45
+ }),
46
+ 'apex-page': Flags.string({
47
+ summary: messages.getMessage('flags.apex-page.summary'),
48
+ description: messages.getMessage('flags.apex-page.description'),
49
+ exactlyOne: CHECK_FLAGS,
50
+ }),
51
+ 'custom-permission': Flags.string({
52
+ summary: messages.getMessage('flags.custom-permission.summary'),
53
+ description: messages.getMessage('flags.custom-permission.description'),
54
+ exactlyOne: CHECK_FLAGS,
55
+ }),
56
+ 'system-permission': Flags.string({
57
+ summary: messages.getMessage('flags.system-permission.summary'),
58
+ description: messages.getMessage('flags.system-permission.description'),
59
+ exactlyOne: CHECK_FLAGS,
60
+ }),
61
+ 'include-inactive': Flags.boolean({
62
+ summary: messages.getMessage('flags.include-inactive.summary'),
63
+ description: messages.getMessage('flags.include-inactive.description'),
64
+ default: false,
65
+ }),
66
+ 'user-limit': Flags.integer({
67
+ summary: messages.getMessage('flags.user-limit.summary'),
68
+ description: messages.getMessage('flags.user-limit.description'),
69
+ char: 'l',
70
+ min: 1,
71
+ max: 2000,
72
+ default: 200,
73
+ }),
74
+ };
75
+ async run() {
76
+ const { flags } = await this.parse(RflibDebugUserPermissionsWhoHas);
77
+ const conn = flags['target-org'].getConnection(undefined);
78
+ this.spinner.start('Finding users with the permission...');
79
+ const result = await whoHasPermission(conn, {
80
+ object: flags.object,
81
+ field: flags.field,
82
+ access: flags.access,
83
+ apexClass: flags['apex-class'],
84
+ apexPage: flags['apex-page'],
85
+ customPermission: flags['custom-permission'],
86
+ systemPermission: flags['system-permission'],
87
+ includeInactive: flags['include-inactive'],
88
+ limit: flags['user-limit'],
89
+ });
90
+ this.spinner.stop();
91
+ this.report(result);
92
+ return result;
93
+ }
94
+ report(result) {
95
+ this.log(result.summary);
96
+ if (result.sources.length > 0) {
97
+ this.log(messages.getMessage('info.sources'));
98
+ this.table({
99
+ data: result.sources.map((source) => ({
100
+ type: SOURCE_LABELS[source.type],
101
+ name: source.name,
102
+ permission: source.permission,
103
+ users: source.userCount,
104
+ })),
105
+ columns: [
106
+ { key: 'type', name: 'Type' },
107
+ { key: 'name', name: 'Name' },
108
+ { key: 'permission', name: 'Permission' },
109
+ { key: 'users', name: 'Users' },
110
+ ],
111
+ });
112
+ }
113
+ if (result.users.length > 0) {
114
+ this.log(messages.getMessage('info.users'));
115
+ this.table({
116
+ data: result.users.map((user) => ({
117
+ username: user.username,
118
+ name: user.name,
119
+ profile: user.profileName,
120
+ sources: user.sources.join(', '),
121
+ })),
122
+ columns: [
123
+ { key: 'username', name: 'Username' },
124
+ { key: 'name', name: 'Name' },
125
+ { key: 'profile', name: 'Profile' },
126
+ { key: 'sources', name: 'Granted By' },
127
+ ],
128
+ });
129
+ if (result.usersTruncated) {
130
+ this.log(messages.getMessage('info.usersTruncated', [result.users.length, result.userCount]));
131
+ }
132
+ }
133
+ for (const note of result.notes) {
134
+ this.log(messages.getMessage('info.note', [note]));
135
+ }
136
+ }
137
+ }
138
+ //# sourceMappingURL=whohas.js.map