Skip to content

Commit

Permalink
Refactor and add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
npsp-reedestockton committed Nov 3, 2023
1 parent f66f970 commit 5335483
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
18 changes: 12 additions & 6 deletions force-app/main/default/classes/GE_GiftEntryController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -1190,19 +1194,17 @@ public with sharing class GE_GiftEntryController {
Set<String> fieldsToCheck = new Set<String>{
'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;
}
Expand Down Expand Up @@ -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()
Expand Down
21 changes: 0 additions & 21 deletions force-app/main/default/classes/GE_Template.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,22 +60,6 @@ public with sharing class GE_Template {
}
}

private static Boolean canCreateDefaultTemplate() {
Set<String> fieldNames = new Set<String>{
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.
*
Expand Down

0 comments on commit 5335483

Please sign in to comment.