From 118f8d69c86ba37e57e3567e6f0083a5dc485abc Mon Sep 17 00:00:00 2001 From: Robert Baillie Date: Thu, 21 Apr 2022 14:12:36 +0100 Subject: [PATCH] Added back the permissions service --- .../IPermissionsService.cls | 4 ++ .../IPermissionsService.cls-meta.xml | 5 +++ .../PermissionsService.cls | 20 +++++++++ .../PermissionsService.cls-meta.xml | 5 +++ .../PermissionsServiceImpl.cls | 45 +++++++++++++++++++ .../PermissionsServiceImpl.cls-meta.xml | 5 +++ .../tests/PermissionsServiceImplTest.cls | 13 ++++++ .../PermissionsServiceImplTest.cls-meta.xml | 5 +++ 8 files changed, 102 insertions(+) create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls-meta.xml create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls-meta.xml create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls-meta.xml create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls create mode 100644 framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls-meta.xml diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls b/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls new file mode 100644 index 00000000000..857226e21fe --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls @@ -0,0 +1,4 @@ +public interface IPermissionsService +{ + Boolean hasAccessToCorePlatformCache(); +} \ No newline at end of file diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls-meta.xml b/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls-meta.xml new file mode 100644 index 00000000000..dd61d1f917e --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/IPermissionsService.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active + diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls new file mode 100644 index 00000000000..b432ec7268e --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls @@ -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 ); + } +} diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls-meta.xml b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls-meta.xml new file mode 100644 index 00000000000..dd61d1f917e --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsService.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active + diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls new file mode 100644 index 00000000000..e4ff0706eb9 --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls @@ -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; + } +} \ No newline at end of file diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls-meta.xml b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls-meta.xml new file mode 100644 index 00000000000..dd61d1f917e --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/PermissionsServiceImpl.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active + diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls b/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls new file mode 100644 index 00000000000..5b6109936b7 --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls @@ -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' ); + } +} \ No newline at end of file diff --git a/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls-meta.xml b/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls-meta.xml new file mode 100644 index 00000000000..dd61d1f917e --- /dev/null +++ b/framework/default/ortoo-core/default/classes/services/permissions-service/tests/PermissionsServiceImplTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 52.0 + Active +