diff --git a/force-app/main/default/classes/HH_CampaignDedupeBTN_CTRL.cls b/force-app/main/default/classes/HH_CampaignDedupeBTN_CTRL.cls index eadce8cb670..2f8b4b5933b 100644 --- a/force-app/main/default/classes/HH_CampaignDedupeBTN_CTRL.cls +++ b/force-app/main/default/classes/HH_CampaignDedupeBTN_CTRL.cls @@ -57,6 +57,29 @@ public without sharing class HH_CampaignDedupeBTN_CTRL { //so we inform our action method to perform the update private boolean updateSettingsWithID = false; + @TestVisible + public Boolean hasAccess { + get { + if (hasAccess == null) { + hasAccess = getCurrentUserHasAccess(); + } + return hasAccess; + } + private set; + } + + @TestVisible + private UTIL_Permissions perms { + get { + if (perms == null) { + perms = new UTIL_Permissions(); + } + + return perms; + } + set; + } + /******************************************************************************************************* * @description Constructor * @param controller StandardController to a Campaign @@ -98,6 +121,10 @@ public without sharing class HH_CampaignDedupeBTN_CTRL { public PageReference RunReport(){ Savepoint sp = Database.setSavepoint(); try { + if (!hasAccess) { + throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); + } + string ActiveID = campaign.id; ActiveID = ActiveID.substring(0,15); string newPageUrl = ''; @@ -193,8 +220,6 @@ public without sharing class HH_CampaignDedupeBTN_CTRL { ********************************************************************************************************/ public static integer MarkDuplicatesFromList(ID campaignId, list listCM) { - validateAccessPermissions(); - final String DUPE_STATUS_SUFFIX = System.Label.hhCmpDedupeStatus; //check for the Household Duplicate status values we need @@ -293,23 +318,23 @@ public without sharing class HH_CampaignDedupeBTN_CTRL { return returnsize; } - private static void validateAccessPermissions() { - if (!UTIL_Permissions.canUpdate('CampaignMember', 'Status', false)) { - throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); - } - - Set cmsFields = new Set{ - 'CampaignId', - 'Label', - 'HasResponded', - 'SortOrder' - }; - for (String cmsField : cmsFields) { - if (!(UTIL_Permissions.canRead('CampaignMemberStatus', cmsField, false) && - UTIL_Permissions.canCreate('CampaignMemberStatus', cmsField, false))) { - throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage); + private Boolean getCurrentUserHasAccess() { + Boolean accessOK = false; + + if (UTIL_Permissions.canUpdate('CampaignMember', 'Status', false)) { + Set cmsFields = new Set{ + CampaignMemberStatus.fields.CampaignId, + CampaignMemberStatus.fields.Label, + CampaignMemberStatus.fields.HasResponded, + CampaignMemberStatus.fields.SortOrder + }; + if ((perms.canRead(CampaignMemberStatus.getSObjectType(), cmsFields) && + perms.canCreate(CampaignMemberStatus.getSObjectType(), cmsFields))) { + accessOK = true; } } + + return accessOK; } /******************************************************************************************************* diff --git a/force-app/main/default/classes/HH_CampaignDedupeBTN_TEST.cls b/force-app/main/default/classes/HH_CampaignDedupeBTN_TEST.cls index ca87c4b7fd6..1c12e74f693 100644 --- a/force-app/main/default/classes/HH_CampaignDedupeBTN_TEST.cls +++ b/force-app/main/default/classes/HH_CampaignDedupeBTN_TEST.cls @@ -150,6 +150,7 @@ private class HH_CampaignDedupeBTN_TEST { Test.startTest(); ApexPages.StandardController sc = new ApexPages.StandardController(camp); HH_CampaignDedupeBTN_CTRL deduper = new HH_CampaignDedupeBTN_CTRL(sc); + deduper.hasAccess = true; deduper.RunReport(); Test.stopTest();