From 53354830e79c9481ba7caa6a3f739e1f7efa212f Mon Sep 17 00:00:00 2001 From: Reede Stockton Date: Fri, 3 Nov 2023 11:56:43 -0700 Subject: [PATCH] Refactor and add comments. --- .../classes/GE_GiftEntryController.cls | 18 ++++++++++------ .../main/default/classes/GE_Template.cls | 21 ------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/force-app/main/default/classes/GE_GiftEntryController.cls b/force-app/main/default/classes/GE_GiftEntryController.cls index b8365ce2e62..b4742718479 100644 --- a/force-app/main/default/classes/GE_GiftEntryController.cls +++ b/force-app/main/default/classes/GE_GiftEntryController.cls @@ -426,6 +426,10 @@ public with sharing class GE_GiftEntryController { DataImport__c dataImportObject = (DataImport__c)JSON.deserialize(dataImport, DataImport__c.class); try { + // As currently implemented, Gift Entry already checks everything checked in canUpsertDataImport() before + // allowing access. As a result, canUpsertDataImport() should never return false. It is implemented solely + // as a defense against future modifications since it is an AuraEnabled method that could be used outside + // of the currently implemented flow. if (!canUpsertDataImport(dataImportObject)) { throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); } @@ -1190,19 +1194,17 @@ public with sharing class GE_GiftEntryController { Set fieldsToCheck = new Set{ 'Name', 'Description__c', - 'Template_JSON__c', - 'Format_Version__c' + 'Template_JSON__c' }; if (!canUpsertFormTemplate(fieldsToCheck)) { - UTIL_AuraEnabledCommon.throwAuraHandledException(System.Label.commonAccessErrorMessage); + throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); } if (templateJSON != null) { Form_Template__c templateObj = new Form_Template__c(Id = id, Name = name, Description__c = description, - Template_JSON__c = templateJSON, - Format_Version__c = formatVersion); + Template_JSON__c = templateJSON); upsert templateObj; return templateObj.Id; } @@ -1396,8 +1398,12 @@ public with sharing class GE_GiftEntryController { } private static String retrieveBatchCurrencyIsoCode (Id batchId) { + // As currently implemented, Gift Entry already verifies edit access to DataImportBatch__c before allowing + // access. As a result, a permission error should never be encountered here. It is implemented solely as a + // defense against future modifications since it is called by an AuraEnabled method that could be used + // outside of the currently implemented flow. if (!UTIL_Permissions.canRead(UTIL_Namespace.StrAllNSPrefix('DataImportBatch__c'), false)) { - UTIL_AuraEnabledCommon.throwAuraHandledException(System.Label.commonAccessErrorMessage); + throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); } String query = new UTIL_Query() diff --git a/force-app/main/default/classes/GE_Template.cls b/force-app/main/default/classes/GE_Template.cls index 8dfd844c950..f37d2be2916 100644 --- a/force-app/main/default/classes/GE_Template.cls +++ b/force-app/main/default/classes/GE_Template.cls @@ -49,11 +49,6 @@ public with sharing class GE_Template { public static void createDefaultTemplateIfNecessary() { // TODO: Should also block template creation if Advanced Mapping is not enabled if (giftEntryIsEnabled() && !hasDefaultTemplate()) { - - if (!canCreateDefaultTemplate()) { - UTIL_AuraEnabledCommon.throwAuraHandledException(System.Label.commonAccessErrorMessage); - } - Form_Template__c newDefaultTemplate = buildDefaultTemplate(); insert newDefaultTemplate; @@ -65,22 +60,6 @@ public with sharing class GE_Template { } } - private static Boolean canCreateDefaultTemplate() { - Set fieldNames = new Set{ - UTIL_Namespace.StrTokenNSPrefix('Description__c'), - UTIL_Namespace.StrTokenNSPrefix('Template_JSON__c'), - UTIL_Namespace.StrTokenNSPrefix('Format_Version__c') - }; - - for (String fieldName:fieldNames) { - if (!UTIL_Permissions.canCreate(UTIL_Namespace.StrAllNSPrefix('Form_Template__c'), - fieldName, false)) { - return false; - } - } - return true; - } - /** * @description This method determines if there is an existing default template. *