forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20bface
commit 118f8d6
Showing
8 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
...k/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public interface IPermissionsService | ||
{ | ||
Boolean hasAccessToCorePlatformCache(); | ||
} |
5 changes: 5 additions & 0 deletions
5
.../ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
20 changes: 20 additions & 0 deletions
20
...rk/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Provides the ability to check if the current user has particular permissions. | ||
*/ | ||
public with sharing class PermissionsService { | ||
|
||
/** | ||
* States if the user has rights to access the core platform cache | ||
* | ||
* @return Boolean Does the current user have the stated permission. | ||
*/ | ||
public static Boolean hasAccessToCorePlatformCache() | ||
{ | ||
return service().hasAccessToCorePlatformCache(); | ||
} | ||
|
||
private static IPermissionsService service() | ||
{ | ||
return (IPermissionsService)Application.SERVICE.newInstance( IPermissionsService.class ); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...t/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
45 changes: 45 additions & 0 deletions
45
...efault/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
public with sharing class PermissionsServiceImpl implements IPermissionsService | ||
{ | ||
/** | ||
* States if the user has the custom permission required to acces the core platform cache | ||
* | ||
* @return Boolean Does the current user have the platform cache | ||
*/ | ||
public Boolean hasAccessToCorePlatformCache() | ||
{ | ||
Boolean hasAccessToCorePlatformCache = false; | ||
|
||
try | ||
{ | ||
hasAccessToCorePlatformCache = hasCustomPermission( 'ProcessesCanAccessCache' ); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
ServiceUtils.logAndRethrow( e ); | ||
} | ||
|
||
return hasAccessToCorePlatformCache; | ||
} | ||
|
||
/** | ||
* States if the user has the custom permission with the given API name. | ||
* | ||
* @param String The API name of the custom permission to check the assignment of. | ||
* @return Boolean Does the current user have the stated permission. | ||
*/ | ||
private Boolean hasCustomPermission( String customPermissionName ) | ||
{ | ||
Boolean hasCustomPermission = false; | ||
|
||
try | ||
{ | ||
hasCustomPermission = FeatureManagement.checkPermission( customPermissionName ); | ||
} | ||
catch ( Exception e ) | ||
{ | ||
ServiceUtils.logAndRethrow( e ); | ||
} | ||
|
||
return hasCustomPermission; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...too-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
13 changes: 13 additions & 0 deletions
13
...oo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@isTest | ||
private with sharing class PermissionsServiceImplTest | ||
{ | ||
@isTest | ||
private static void hasAccessToCorePlatformCache_doesNotThrowAnException() // NOPMD: test method format | ||
{ | ||
PermissionsServiceImpl permissionsService = new PermissionsServiceImpl(); | ||
|
||
Boolean hasPermission = permissionsService.hasAccessToCorePlatformCache(); | ||
|
||
System.assertNotEquals( null, hasPermission, 'hasAccessToCorePlatformCache, does not throw an exception, and returns a value' ); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...efault/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |