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
@@ -0,0 +1,41 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import { type UserSummary } from './permissionCheck.js';
3
+ export type AccessLevel = 'None' | 'Read' | 'Edit' | 'Delete' | 'Transfer' | 'All';
4
+ export type RecordAccessArgs = {
5
+ /** User ID (15 or 18 characters) or username. */
6
+ user: string;
7
+ recordIds: readonly string[];
8
+ };
9
+ export type ObjectRecordAccess = {
10
+ read: boolean;
11
+ edit: boolean;
12
+ delete: boolean;
13
+ viewAll: boolean;
14
+ modifyAll: boolean;
15
+ };
16
+ export type RecordAccessEntry = {
17
+ recordId: string;
18
+ /** API name of the record's object, when it could be determined from the ID prefix. */
19
+ sobjectType?: string;
20
+ /** False when Salesforce returned no access information, e.g. because the record doesn't exist. */
21
+ found: boolean;
22
+ hasReadAccess: boolean;
23
+ hasEditAccess: boolean;
24
+ hasDeleteAccess: boolean;
25
+ hasTransferAccess: boolean;
26
+ hasAllAccess: boolean;
27
+ maxAccessLevel: AccessLevel;
28
+ /** The user's object permissions on the record's object. */
29
+ objectAccess?: ObjectRecordAccess;
30
+ notes: string[];
31
+ };
32
+ export type RecordAccessResult = {
33
+ user: UserSummary;
34
+ records: RecordAccessEntry[];
35
+ };
36
+ /**
37
+ * Checks a user's access to specific records, including sharing, with UserRecordAccess. For each
38
+ * record, the result also contains the user's object permissions and notes that tell apart missing
39
+ * object permissions from missing sharing.
40
+ */
41
+ export declare function getRecordAccess(conn: Connection, args: RecordAccessArgs): Promise<RecordAccessResult>;
@@ -0,0 +1,117 @@
1
+ import { buildIdList, escapeSingleQuotes, ID_PATTERN } from './permissionAggregator.js';
2
+ import { loadContext, queryObjectPermissions, resolveUser, toUserSummary, } from './permissionCheck.js';
3
+ // UserRecordAccess accepts at most 200 record IDs per query.
4
+ const MAX_RECORD_IDS = 200;
5
+ function maxAccessLevel(row) {
6
+ if (row?.HasAllAccess)
7
+ return 'All';
8
+ if (row?.HasTransferAccess)
9
+ return 'Transfer';
10
+ if (row?.HasDeleteAccess)
11
+ return 'Delete';
12
+ if (row?.HasEditAccess)
13
+ return 'Edit';
14
+ if (row?.HasReadAccess)
15
+ return 'Read';
16
+ return 'None';
17
+ }
18
+ function validateRecordIds(recordIds) {
19
+ const unique = [...new Set(recordIds)];
20
+ if (unique.length === 0) {
21
+ throw new Error('Specify at least one record ID.');
22
+ }
23
+ if (unique.length > MAX_RECORD_IDS) {
24
+ throw new Error(`Specify at most ${MAX_RECORD_IDS} record IDs.`);
25
+ }
26
+ for (const id of unique) {
27
+ if (!ID_PATTERN.test(id)) {
28
+ throw new Error(`Invalid record ID "${id}". Expected a 15 or 18 character Salesforce ID.`);
29
+ }
30
+ }
31
+ return unique;
32
+ }
33
+ async function loadObjectAccess(ctx, sobjectType) {
34
+ const rows = await queryObjectPermissions(ctx, sobjectType);
35
+ const has = (field) => rows.some((row) => row[field] === true);
36
+ return {
37
+ read: has('PermissionsRead'),
38
+ edit: has('PermissionsEdit'),
39
+ delete: has('PermissionsDelete'),
40
+ viewAll: has('PermissionsViewAllRecords'),
41
+ modifyAll: has('PermissionsModifyAllRecords'),
42
+ };
43
+ }
44
+ function explain(entry) {
45
+ if (!entry.found) {
46
+ return ['Salesforce returned no access information. The record may not exist, or it may have been deleted.'];
47
+ }
48
+ const object = entry.sobjectType ?? 'the object';
49
+ const access = entry.objectAccess;
50
+ if (!access)
51
+ return [];
52
+ if (!entry.hasReadAccess) {
53
+ return access.read
54
+ ? [
55
+ `The user has Read on ${object}, but sharing doesn't give them access to this record. ` +
56
+ 'Check the org-wide default, role hierarchy, sharing rules, teams, and manual shares.',
57
+ ]
58
+ : [
59
+ `The user has no Read permission on ${object}, so sharing can't give them access. Grant Read on the object first.`,
60
+ ];
61
+ }
62
+ if (!entry.hasEditAccess) {
63
+ return access.edit
64
+ ? [`The user has Edit on ${object}, but sharing only gives them Read access to this record.`]
65
+ : [`The user can't edit this record because they have no Edit permission on ${object}.`];
66
+ }
67
+ return [];
68
+ }
69
+ /**
70
+ * Checks a user's access to specific records, including sharing, with UserRecordAccess. For each
71
+ * record, the result also contains the user's object permissions and notes that tell apart missing
72
+ * object permissions from missing sharing.
73
+ */
74
+ export async function getRecordAccess(conn, args) {
75
+ if (!args.user) {
76
+ throw new Error('user is required');
77
+ }
78
+ const recordIds = validateRecordIds(args.recordIds);
79
+ const user = await resolveUser(conn, args.user);
80
+ const ctx = await loadContext(conn, user);
81
+ const rows = (await conn.query('SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess, HasTransferAccess, HasAllAccess ' +
82
+ `FROM UserRecordAccess WHERE UserId = '${escapeSingleQuotes(user.Id)}' AND RecordId IN ${buildIdList(recordIds)}`)).records;
83
+ // Salesforce returns 18-character IDs; match them to 15-character input by prefix.
84
+ const rowFor = (id) => rows.find((row) => row.RecordId.slice(0, 15) === id.slice(0, 15));
85
+ const global = (await conn.describeGlobal());
86
+ const objectsByPrefix = new Map(global.sobjects.filter((sobject) => sobject.keyPrefix).map((sobject) => [sobject.keyPrefix, sobject.name]));
87
+ const objectAccess = new Map();
88
+ const records = [];
89
+ for (const recordId of recordIds) {
90
+ const row = rowFor(recordId);
91
+ const sobjectType = objectsByPrefix.get(recordId.slice(0, 3));
92
+ if (sobjectType && !objectAccess.has(sobjectType)) {
93
+ // eslint-disable-next-line no-await-in-loop
94
+ objectAccess.set(sobjectType, await loadObjectAccess(ctx, sobjectType));
95
+ }
96
+ const entry = {
97
+ recordId: row?.RecordId ?? recordId,
98
+ ...(sobjectType ? { sobjectType } : {}),
99
+ found: row !== undefined,
100
+ hasReadAccess: row?.HasReadAccess === true,
101
+ hasEditAccess: row?.HasEditAccess === true,
102
+ hasDeleteAccess: row?.HasDeleteAccess === true,
103
+ hasTransferAccess: row?.HasTransferAccess === true,
104
+ hasAllAccess: row?.HasAllAccess === true,
105
+ maxAccessLevel: maxAccessLevel(row),
106
+ ...(sobjectType ? { objectAccess: objectAccess.get(sobjectType) } : {}),
107
+ notes: [],
108
+ };
109
+ entry.notes = explain(entry);
110
+ if (!user.IsActive) {
111
+ entry.notes.unshift('The user is inactive and cannot log in, regardless of their access.');
112
+ }
113
+ records.push(entry);
114
+ }
115
+ return { user: toUserSummary(user), records };
116
+ }
117
+ //# sourceMappingURL=recordAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordAccess.js","sourceRoot":"","sources":["../../src/shared/recordAccess.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,WAAW,EACX,aAAa,GAGd,MAAM,sBAAsB,CAAC;AAE9B,6DAA6D;AAC7D,MAAM,cAAc,GAAG,GAAG,CAAC;AAmD3B,SAAS,cAAc,CAAC,GAAoC;IAC1D,IAAI,GAAG,EAAE,YAAY;QAAE,OAAO,KAAK,CAAC;IACpC,IAAI,GAAG,EAAE,iBAAiB;QAAE,OAAO,UAAU,CAAC;IAC9C,IAAI,GAAG,EAAE,eAAe;QAAE,OAAO,QAAQ,CAAC;IAC1C,IAAI,GAAG,EAAE,aAAa;QAAE,OAAO,MAAM,CAAC;IACtC,IAAI,GAAG,EAAE,aAAa;QAAE,OAAO,MAAM,CAAC;IACtC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,SAA4B;IACrD,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IACvC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,MAAM,CAAC,MAAM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AiB,KAAK,IAAI;YAClD,YAAY,EAAE,GAAG,EAAE,YAAY,KAAK,IAAI;YACxC,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC;YACnC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvE,KAAK,EAAE,EAAE;SACV,CAAC;QACF,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,qEAAqE,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;AAChD,CAAC","sourcesContent":["import type { Connection } from '@salesforce/core';\nimport { buildIdList, escapeSingleQuotes, ID_PATTERN } from './permissionAggregator.js';\nimport {\n loadContext,\n queryObjectPermissions,\n resolveUser,\n toUserSummary,\n type CheckContext,\n type UserSummary,\n} from './permissionCheck.js';\n\n// UserRecordAccess accepts at most 200 record IDs per query.\nconst MAX_RECORD_IDS = 200;\n\nexport type AccessLevel = 'None' | 'Read' | 'Edit' | 'Delete' | 'Transfer' | 'All';\n\nexport type RecordAccessArgs = {\n /** User ID (15 or 18 characters) or username. */\n user: string;\n recordIds: readonly string[];\n};\n\nexport type ObjectRecordAccess = {\n read: boolean;\n edit: boolean;\n delete: boolean;\n viewAll: boolean;\n modifyAll: boolean;\n};\n\nexport type RecordAccessEntry = {\n recordId: string;\n /** API name of the record's object, when it could be determined from the ID prefix. */\n sobjectType?: string;\n /** False when Salesforce returned no access information, e.g. because the record doesn't exist. */\n found: boolean;\n hasReadAccess: boolean;\n hasEditAccess: boolean;\n hasDeleteAccess: boolean;\n hasTransferAccess: boolean;\n hasAllAccess: boolean;\n maxAccessLevel: AccessLevel;\n /** The user's object permissions on the record's object. */\n objectAccess?: ObjectRecordAccess;\n notes: string[];\n};\n\nexport type RecordAccessResult = {\n user: UserSummary;\n records: RecordAccessEntry[];\n};\n\ntype UserRecordAccessRow = {\n RecordId: string;\n HasReadAccess?: boolean;\n HasEditAccess?: boolean;\n HasDeleteAccess?: boolean;\n HasTransferAccess?: boolean;\n HasAllAccess?: boolean;\n};\n\ntype GlobalDescribe = { sobjects: Array<{ name: string; keyPrefix?: string | null }> };\n\nfunction maxAccessLevel(row: UserRecordAccessRow | undefined): AccessLevel {\n if (row?.HasAllAccess) return 'All';\n if (row?.HasTransferAccess) return 'Transfer';\n if (row?.HasDeleteAccess) return 'Delete';\n if (row?.HasEditAccess) return 'Edit';\n if (row?.HasReadAccess) return 'Read';\n return 'None';\n}\n\nfunction validateRecordIds(recordIds: readonly string[]): string[] {\n const unique = [...new Set(recordIds)];\n if (unique.length === 0) {\n throw new Error('Specify at least one record ID.');\n }\n if (unique.length > MAX_RECORD_IDS) {\n throw new Error(`Specify at most ${MAX_RECORD_IDS} record IDs.`);\n }\n for (const id of unique) {\n if (!ID_PATTERN.test(id)) {\n throw new Error(`Invalid record ID \"${id}\". Expected a 15 or 18 character Salesforce ID.`);\n }\n }\n return unique;\n}\n\nasync function loadObjectAccess(ctx: CheckContext, sobjectType: string): Promise<ObjectRecordAccess> {\n const rows = await queryObjectPermissions(ctx, sobjectType);\n const has = (field: string): boolean => rows.some((row) => row[field] === true);\n return {\n read: has('PermissionsRead'),\n edit: has('PermissionsEdit'),\n delete: has('PermissionsDelete'),\n viewAll: has('PermissionsViewAllRecords'),\n modifyAll: has('PermissionsModifyAllRecords'),\n };\n}\n\nfunction explain(entry: RecordAccessEntry): string[] {\n if (!entry.found) {\n return ['Salesforce returned no access information. The record may not exist, or it may have been deleted.'];\n }\n const object = entry.sobjectType ?? 'the object';\n const access = entry.objectAccess;\n if (!access) return [];\n if (!entry.hasReadAccess) {\n return access.read\n ? [\n `The user has Read on ${object}, but sharing doesn't give them access to this record. ` +\n 'Check the org-wide default, role hierarchy, sharing rules, teams, and manual shares.',\n ]\n : [\n `The user has no Read permission on ${object}, so sharing can't give them access. Grant Read on the object first.`,\n ];\n }\n if (!entry.hasEditAccess) {\n return access.edit\n ? [`The user has Edit on ${object}, but sharing only gives them Read access to this record.`]\n : [`The user can't edit this record because they have no Edit permission on ${object}.`];\n }\n return [];\n}\n\n/**\n * Checks a user's access to specific records, including sharing, with UserRecordAccess. For each\n * record, the result also contains the user's object permissions and notes that tell apart missing\n * object permissions from missing sharing.\n */\nexport async function getRecordAccess(conn: Connection, args: RecordAccessArgs): Promise<RecordAccessResult> {\n if (!args.user) {\n throw new Error('user is required');\n }\n const recordIds = validateRecordIds(args.recordIds);\n const user = await resolveUser(conn, args.user);\n const ctx = await loadContext(conn, user);\n\n const rows = (\n await conn.query<UserRecordAccessRow>(\n 'SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess, HasTransferAccess, HasAllAccess ' +\n `FROM UserRecordAccess WHERE UserId = '${escapeSingleQuotes(user.Id)}' AND RecordId IN ${buildIdList(recordIds)}`,\n )\n ).records;\n // Salesforce returns 18-character IDs; match them to 15-character input by prefix.\n const rowFor = (id: string): UserRecordAccessRow | undefined =>\n rows.find((row) => row.RecordId.slice(0, 15) === id.slice(0, 15));\n\n const global = (await conn.describeGlobal()) as unknown as GlobalDescribe;\n const objectsByPrefix = new Map(\n global.sobjects.filter((sobject) => sobject.keyPrefix).map((sobject) => [sobject.keyPrefix!, sobject.name]),\n );\n const objectAccess = new Map<string, ObjectRecordAccess>();\n\n const records: RecordAccessEntry[] = [];\n for (const recordId of recordIds) {\n const row = rowFor(recordId);\n const sobjectType = objectsByPrefix.get(recordId.slice(0, 3));\n if (sobjectType && !objectAccess.has(sobjectType)) {\n // eslint-disable-next-line no-await-in-loop\n objectAccess.set(sobjectType, await loadObjectAccess(ctx, sobjectType));\n }\n const entry: RecordAccessEntry = {\n recordId: row?.RecordId ?? recordId,\n ...(sobjectType ? { sobjectType } : {}),\n found: row !== undefined,\n hasReadAccess: row?.HasReadAccess === true,\n hasEditAccess: row?.HasEditAccess === true,\n hasDeleteAccess: row?.HasDeleteAccess === true,\n hasTransferAccess: row?.HasTransferAccess === true,\n hasAllAccess: row?.HasAllAccess === true,\n maxAccessLevel: maxAccessLevel(row),\n ...(sobjectType ? { objectAccess: objectAccess.get(sobjectType) } : {}),\n notes: [],\n };\n entry.notes = explain(entry);\n if (!user.IsActive) {\n entry.notes.unshift('The user is inactive and cannot log in, regardless of their access.');\n }\n records.push(entry);\n }\n\n return { user: toUserSummary(user), records };\n}\n"]}
@@ -0,0 +1,59 @@
1
+ # summary
2
+
3
+ Check a user's access to specific records, including sharing.
4
+
5
+ # description
6
+
7
+ Answers questions such as "Why can't this user see this record?". For each record, the command returns the user's access from UserRecordAccess (read, edit, delete, transfer, and full access), which includes sharing: the org-wide default, the role hierarchy, sharing rules, teams, and manual shares.
8
+
9
+ The result also contains the user's object permissions on each record's object, and notes that tell apart missing object permissions from missing sharing. Use userpermissions check to find out which profile or permission set grants an object permission.
10
+
11
+ You can check up to 200 records at a time.
12
+
13
+ The command only reads standard objects, so the RFLIB package doesn't need to be installed.
14
+
15
+ # flags.target-org.summary
16
+
17
+ Username or alias of the target org.
18
+
19
+ # flags.target-org.description
20
+
21
+ The username or alias of the Salesforce org that contains the records.
22
+
23
+ # flags.user.summary
24
+
25
+ User ID (15 or 18 characters) or username of the user to check.
26
+
27
+ # flags.user.description
28
+
29
+ The Salesforce User ID (15 or 18 characters) or the username of the user whose record access should be checked.
30
+
31
+ # flags.record-id.summary
32
+
33
+ ID of a record to check. Specify the flag multiple times to check several records.
34
+
35
+ # flags.record-id.description
36
+
37
+ The 15 or 18 character ID of a record to check. Specify --record-id up to 200 times.
38
+
39
+ # info.user
40
+
41
+ Record access for %s:
42
+
43
+ # info.notFound
44
+
45
+ Not found
46
+
47
+ # info.note
48
+
49
+ %s: %s
50
+
51
+ # examples
52
+
53
+ - Check a user's access to a record:
54
+
55
+ $ sf rflib debug recordaccess get --target-org myOrg --user jane@example.com --record-id 001XXXXXXXXXXXXXXX
56
+
57
+ - Check several records at once:
58
+
59
+ $ sf rflib debug recordaccess get --target-org myOrg --user 0057000000XXXXXX --record-id 001XXXXXXXXXXXXXXX --record-id 006XXXXXXXXXXXXXXX
@@ -0,0 +1,115 @@
1
+ # summary
2
+
3
+ Compare the permissions of two users and show only the differences.
4
+
5
+ # description
6
+
7
+ Finds out why something works for one user but not for another. The command combines each user's permissions across their profile, permission sets, and permission set groups, and returns only the permissions that one of the users has and the other doesn't.
8
+
9
+ Use --permission-type to choose what to compare (default: ALL) and --sobject-type to limit the object and field comparison to one object. ALL compares object and field access, Apex classes, Visualforce pages, custom permissions, and system permissions.
10
+
11
+ Field access only counts where the user also has the matching access on the object. Sharing and record-level access aren't compared.
12
+
13
+ The command only reads standard setup objects, so the RFLIB package doesn't need to be installed. The running user needs the View Setup and Configuration permission.
14
+
15
+ # flags.target-org.summary
16
+
17
+ Username or alias of the target org.
18
+
19
+ # flags.target-org.description
20
+
21
+ The username or alias of the Salesforce org to compare the users in.
22
+
23
+ # flags.user.summary
24
+
25
+ User ID (15 or 18 characters) or username of the first user.
26
+
27
+ # flags.user.description
28
+
29
+ The first user to compare, typically the user for whom something doesn't work.
30
+
31
+ # flags.other-user.summary
32
+
33
+ User ID (15 or 18 characters) or username of the second user.
34
+
35
+ # flags.other-user.description
36
+
37
+ The second user to compare, typically the user for whom it works.
38
+
39
+ # flags.permission-type.summary
40
+
41
+ Permissions to compare: FLS, OLS, APEX, or ALL. Default: ALL.
42
+
43
+ # flags.permission-type.description
44
+
45
+ Controls which permissions are compared:
46
+ - FLS: Field access
47
+ - OLS: Object access
48
+ - APEX: Apex class and Visualforce page access
49
+ - ALL: All of the above, plus custom permissions and system permissions
50
+
51
+ # flags.sobject-type.summary
52
+
53
+ Optional SObject API name to limit the object and field comparison to.
54
+
55
+ # flags.sobject-type.description
56
+
57
+ Limits the object and field comparison to one SObject type, e.g. Account. Recommended in large orgs, where the full field comparison can reach the query row limit.
58
+
59
+ # info.comparing
60
+
61
+ Comparing %s with %s
62
+
63
+ # info.identical
64
+
65
+ No differences found.
66
+
67
+ # info.section.objects
68
+
69
+ Objects:
70
+
71
+ # info.section.fields
72
+
73
+ Fields:
74
+
75
+ # info.section.apexClasses
76
+
77
+ Apex classes:
78
+
79
+ # info.section.apexPages
80
+
81
+ Visualforce pages:
82
+
83
+ # info.section.customPermissions
84
+
85
+ Custom permissions:
86
+
87
+ # info.section.systemPermissions
88
+
89
+ System permissions:
90
+
91
+ # info.accessDiff
92
+
93
+ %s: %s
94
+
95
+ # info.onlyUser
96
+
97
+ only %s has %s
98
+
99
+ # info.andMore
100
+
101
+ %s, and %s more (see --json for the full list)
102
+
103
+ # info.note
104
+
105
+ Note: %s
106
+
107
+ # examples
108
+
109
+ - Compare all permissions of two users:
110
+
111
+ $ sf rflib debug userpermissions compare --target-org myOrg --user jane@example.com --other-user bob@example.com
112
+
113
+ - Compare object and field access on Account:
114
+
115
+ $ sf rflib debug userpermissions compare --target-org myOrg --user jane@example.com --other-user bob@example.com --permission-type FLS --sobject-type Account
@@ -9,6 +9,8 @@ via the Salesforce REST API. Permissions are aggregated across the user's profil
9
9
 
10
10
  Use --sobject-type to narrow FLS or OLS results to a specific SObject.
11
11
 
12
+ Use --effective to get the user's combined permissions instead of the raw permission records: one entry per object with its access levels, one entry per field with read and edit (only where the user also has that access on the object), and the names of the accessible Apex classes and Visualforce pages. With --permission-type ALL, the result also lists the user's custom permissions and system permissions.
13
+
12
14
  Requires the RFLIB base package to be installed in the target org and the running user to be assigned the rflib_Ops_Center_Access permission set (or have equivalent read access to the relevant permission objects).
13
15
  For installation instructions, visit: https://github.com/j-fischer/rflib
14
16
 
@@ -48,6 +50,14 @@ Optional SObject API name to filter FLS or OLS results.
48
50
 
49
51
  Filters Field-Level Security or Object-Level Security results to a specific SObject type, e.g. Account, Contact, Opportunity.
50
52
 
53
+ # flags.effective.summary
54
+
55
+ Return the user's combined permissions instead of the raw permission records.
56
+
57
+ # flags.effective.description
58
+
59
+ Merges the permissions from the profile, permission sets, and permission set groups. Objects list their access levels (read, create, edit, delete, viewall, modifyall, viewallfields), fields list read and edit, and Apex classes, Visualforce pages, and custom permissions are listed by name. System permissions are included for --permission-type ALL. With --effective, --user-id also accepts a username.
60
+
51
61
  # examples
52
62
 
53
63
  - Check all permissions for a user:
@@ -61,3 +71,7 @@ Filters Field-Level Security or Object-Level Security results to a specific SObj
61
71
  - Check Apex access:
62
72
 
63
73
  $ sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX --permission-type APEX
74
+
75
+ - Get the combined permissions of a user, including custom and system permissions:
76
+
77
+ $ sf rflib debug userpermissions get --target-org myOrg --user-id 0057000000XXXXXX --permission-type ALL --effective
@@ -0,0 +1,132 @@
1
+ # summary
2
+
3
+ Find the users who have a specific permission, and what grants it.
4
+
5
+ # description
6
+
7
+ The reverse of userpermissions check. Answers questions such as "Who can edit Account.AnnualRevenue?" or "Who has Modify All Data?". The command finds every profile, permission set, and permission set group that grants the permission, and the users who are assigned to them.
8
+
9
+ Check exactly one of the following:
10
+ - An object permission (--object, with --access read, create, edit, delete, viewall, modifyall, or viewallfields)
11
+ - A field permission (--field, with --access read or edit)
12
+ - Access to an Apex class (--apex-class) or a Visualforce page (--apex-page)
13
+ - A custom permission (--custom-permission)
14
+ - A system permission (--system-permission), e.g. ModifyAllData or ViewSetup
15
+
16
+ The same permission rules as userpermissions check apply: for field checks, only users who also have the matching access on the object are included, and View All Fields grants Read on all fields. Apex class and Visualforce page checks include access granted by the Author Apex and Customize Application system permissions.
17
+
18
+ Inactive users are excluded unless you specify --include-inactive. The result lists up to --user-limit users; the total count is always returned.
19
+
20
+ The command only reads standard setup objects, so the RFLIB package doesn't need to be installed. The running user needs the View Setup and Configuration permission.
21
+
22
+ # flags.target-org.summary
23
+
24
+ Username or alias of the target org.
25
+
26
+ # flags.target-org.description
27
+
28
+ The username or alias of the Salesforce org to search.
29
+
30
+ # flags.object.summary
31
+
32
+ API name of the object to check object permissions for, e.g. Account.
33
+
34
+ # flags.object.description
35
+
36
+ Finds users with an object permission. Use --access to choose which one; the default is read.
37
+
38
+ # flags.field.summary
39
+
40
+ Field to check field-level security for, in the form Object.Field, e.g. Account.AnnualRevenue.
41
+
42
+ # flags.field.description
43
+
44
+ Finds users with access to a field. Use --access read (default) or --access edit.
45
+
46
+ # flags.access.summary
47
+
48
+ Access level to check for --object or --field. Default: read.
49
+
50
+ # flags.access.description
51
+
52
+ The access level to check:
53
+ - read, edit: for objects and fields
54
+ - create, delete, viewall (View All Records), modifyall (Modify All Records), viewallfields (View All Fields): for objects only
55
+
56
+ # flags.apex-class.summary
57
+
58
+ Name of the Apex class to check access for.
59
+
60
+ # flags.apex-class.description
61
+
62
+ Finds users who can access an Apex class. Use namespace__Name or namespace.Name for a class in a managed package.
63
+
64
+ # flags.apex-page.summary
65
+
66
+ Name of the Visualforce page to check access for.
67
+
68
+ # flags.apex-page.description
69
+
70
+ Finds users who can access a Visualforce page. Use namespace__Name for a page in a managed package.
71
+
72
+ # flags.custom-permission.summary
73
+
74
+ API name of the custom permission to check.
75
+
76
+ # flags.custom-permission.description
77
+
78
+ Finds users who have a custom permission. Use namespace__Name for a custom permission in a managed package.
79
+
80
+ # flags.system-permission.summary
81
+
82
+ API name of the system permission to check, e.g. ModifyAllData or ViewSetup.
83
+
84
+ # flags.system-permission.description
85
+
86
+ Finds users who have a system (user) permission. Use the name of the permission field on the PermissionSet object, with or without the "Permissions" prefix.
87
+
88
+ # flags.include-inactive.summary
89
+
90
+ Include inactive users.
91
+
92
+ # flags.include-inactive.description
93
+
94
+ By default, only active users are returned. Specify this flag to include inactive users as well.
95
+
96
+ # flags.user-limit.summary
97
+
98
+ Maximum number of users to return. Default: 200, maximum: 2000.
99
+
100
+ # flags.user-limit.description
101
+
102
+ Limits the number of users in the result. The total number of matching users is always returned in userCount.
103
+
104
+ # info.sources
105
+
106
+ Granted by:
107
+
108
+ # info.users
109
+
110
+ Users:
111
+
112
+ # info.usersTruncated
113
+
114
+ Showing %s of %s users. Use --user-limit to see more.
115
+
116
+ # info.note
117
+
118
+ Note: %s
119
+
120
+ # examples
121
+
122
+ - Find the users who can edit a field:
123
+
124
+ $ sf rflib debug userpermissions whohas --target-org myOrg --field Account.AnnualRevenue --access edit
125
+
126
+ - Find the users who have Modify All Data:
127
+
128
+ $ sf rflib debug userpermissions whohas --target-org myOrg --system-permission ModifyAllData
129
+
130
+ - Find the users who can access an Apex class, including inactive users:
131
+
132
+ $ sf rflib debug userpermissions whohas --target-org myOrg --apex-class OrderController --include-inactive