Skip to content

Commit 5789bbd

Browse files
authored
Fix permission namespace handling and update package versioning (#217)
1 parent dbd8400 commit 5789bbd

File tree

5 files changed

+65
-7
lines changed

5 files changed

+65
-7
lines changed

cirrus.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ deploy = "sf project deploy start"
88
assign-perms = "sf org assign permset -n Expression_Admin"
99
test = "sf apex test run --test-level RunLocalTests --wait 20"
1010
docs = "apexdocs markdown"
11-
generate-library-docs = "node scripts/generate-library-docs.mjs"
12-
prep-package = "node scripts/prepare-for-packaging.mjs"
11+
generate-library-docs = "bun scripts/generate-library-docs.mjs"
12+
prep-package = "bun scripts/prepare-for-packaging.mjs"
1313
package = "cirrus package -p Expression -t minor -x -c --promote -w 60"
14-
post-package = "node scripts/post-packaging.mjs"
14+
post-package = "bun scripts/post-packaging.mjs"
1515

1616
[flow.start-dev]
1717
description = "Starts a new development environment"

docs/public/packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packageId": "04tRb000003NrEnIAK",
2+
"packageId": "04tRb000003UxfFIAS",
33
"componentPackageId": "04tRb0000012Mv8IAE"
44
}

docs/src/app/docs/referencing-org-data/page.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,23 @@ Available references are:
9595

9696
## Permission
9797

98+
{% callout type="warning" %}
99+
Due to limitations with calling `FeatureManagement.checkPermission` from within a managed package, Expression
100+
checks permissions by querying the `CustomPermission` and `SetupEntityAccess` objects.
101+
102+
This means that each permission check will consume 2 SOQL queries the first time it is evaluated (checks are
103+
cached afterwards).
104+
{% /callout %}
105+
98106
Allows you to reference information about the current user’s custom permission access.
99107

100108
```
101109
$Permission.MyCustomPermissionName # Returns true if the user has access to the custom permission, false otherwise.
102110
```
111+
112+
To reference a custom permission that has a namespace, separate the namespace and the permission name with double
113+
underscores (`__`):
114+
115+
```
116+
$Permission.namespace__MyCustomPermissionName # Returns true if the user has access to the custom permission, false otherwise.
117+
```
Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
public with sharing class PermissionVariableResolver implements IGlobalVariableResolver {
2+
private static final Map<String, Boolean> permissionCache = new Map<String, Boolean>();
23
public Object get(String referenceName, List<Object> args) {
3-
return FeatureManagement.checkPermission(referenceName);
4+
if (permissionCache.containsKey(referenceName)) {
5+
return permissionCache.get(referenceName);
6+
}
7+
8+
List<String> namespacePermissionParts = referenceName.split('__');
9+
10+
String permissionName = referenceName;
11+
String namespacePrefix = '';
12+
// Custom permission name can come in 2 flavors, namespace__PermissionName or just PermissionName.
13+
if (namespacePermissionParts.size() > 1) {
14+
namespacePrefix = namespacePermissionParts[0];
15+
permissionName = namespacePermissionParts[1];
16+
}
17+
18+
List<CustomPermission> customPermissions = [
19+
SELECT Id, DeveloperName
20+
FROM CustomPermission
21+
WHERE DeveloperName = :permissionName
22+
AND NamespacePrefix = :namespacePrefix
23+
];
24+
25+
if (customPermissions.size() != 1) {
26+
permissionCache.put(referenceName, false);
27+
return false;
28+
}
29+
30+
Map<Id, CustomPermission> customPermissionNamesById = new Map<Id, CustomPermission>(customPermissions);
31+
32+
List<SetupEntityAccess> setupEntities = [
33+
SELECT SetupEntityId
34+
FROM SetupEntityAccess
35+
WHERE SetupEntityId IN :customPermissionNamesById.keySet() AND
36+
ParentId IN (
37+
SELECT PermissionSetId
38+
FROM PermissionSetAssignment
39+
WHERE AssigneeId = :UserInfo.getUserId()
40+
)
41+
];
42+
43+
Boolean result = !setupEntities.isEmpty();
44+
permissionCache.put(referenceName, result);
45+
return result;
446
}
547
}

sfdx-project_packaging.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"path": "expression-src",
55
"package": "Expression",
66
"versionName": "Version 1.36",
7-
"versionNumber": "1.39.0.NEXT",
7+
"versionNumber": "1.40.0.NEXT",
88
"default": false,
99
"versionDescription": "Expression core language",
1010
"ancestorVersion": "HIGHEST"
@@ -68,6 +68,7 @@
6868
"Expression@1.36.0-1": "04tRb000003NrEnIAK",
6969
"Expression@1.37.0-3": "04tRb000003OmWPIA0",
7070
"Expression@1.38.0-1": "04tRb000003R4nNIAS",
71-
"Expression@1.39.0-1": "04tRb000003R51tIAC"
71+
"Expression@1.39.0-1": "04tRb000003R51tIAC",
72+
"Expression@1.40.0-1": "04tRb000003UxfFIAS"
7273
}
7374
}

0 commit comments

Comments
 (0)