Skip to content

Commit

Permalink
Merge 703c340 into feature/248
Browse files Browse the repository at this point in the history
  • Loading branch information
salesforce-org-metaci[bot] authored Nov 21, 2023
2 parents 879ccdb + 703c340 commit 295de0a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 28 deletions.
59 changes: 42 additions & 17 deletions force-app/main/default/classes/HH_CampaignDedupeBTN_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down Expand Up @@ -193,8 +220,6 @@ public without sharing class HH_CampaignDedupeBTN_CTRL {
********************************************************************************************************/
public static integer MarkDuplicatesFromList(ID campaignId, list<CampaignMember> listCM) {

validateAccessPermissions();

final String DUPE_STATUS_SUFFIX = System.Label.hhCmpDedupeStatus;

//check for the Household Duplicate status values we need
Expand Down Expand Up @@ -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<String> cmsFields = new Set<String>{
'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<SObjectField> cmsFields = new Set<SObjectField>{
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;
}

/*******************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
44 changes: 33 additions & 11 deletions force-app/main/default/classes/PotentialDuplicates_TEST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,53 @@ private with sharing class PotentialDuplicates_TEST {
private static void shouldReturnNullWhenNoDuplicatesAreFound() {
Id recordId = UTIL_UnitTestData_TEST.mockId(Contact.getSObjectType());
Map<String, Object> data = PotentialDuplicates.getDuplicates(recordId);
System.assertEquals('', data.get('setOfMatches'),
'There should be no duplicates');
String setOfMatches = (String) data.get('setOfMatches');

List<DuplicateRule> activeContactRules = [
SELECT Id
from DuplicateRule
WHERE SObjectType = 'Contact'
AND isActive = TRUE
];

if (activeContactRules.isEmpty()) {
System.assertEquals(null, setOfMatches,
'PotentialDuplicates.getDuplicates() should return null if there are no active Duplicate Rules for Contact');
} else {
System.assertEquals('', setOfMatches, 'There should be no duplicates');
}
}

@IsTest
private static void shouldReturnIdsWhenDuplicatesAreFound() {
List<Contact> contactList = UTIL_UnitTestData_TEST.getContacts(3);
for(Contact c : contactList) {
for (Contact c : contactList) {
c.FirstName = 'Test';
c.LastName = 'LastName';
c.Email = '[email protected]';
}
insert contactList;

List<DuplicateRule> activeContactRules = [
SELECT Id
from DuplicateRule
WHERE SObjectType = 'Contact'
AND isActive = TRUE
];

Map<String, Object> data = PotentialDuplicates.getDuplicates(contactList[0].Id);
String setOfMatches = (String)data.get('setOfMatches');
Integer numberOfMatches = setOfMatches.split(',').size();
String setOfMatches = (String) data.get('setOfMatches');

// Duplicates will not be found if encryption is enabled
if (sObjectType.Contact.fields.Name.isEncrypted()) {
if (activeContactRules.isEmpty()) {
System.assertEquals(null, setOfMatches,
'PotentialDuplicates.getDuplicates() should return null if there are no active Duplicate Rules for Contact');
} else if (sObjectType.Contact.fields.Name.isEncrypted()) {
// Duplicates will not be found if encryption is enabled / standard rules deactivated
System.assertEquals('', setOfMatches, 'No duplicate Ids should be returned if encryption is enabled');
System.assertEquals(0, numberOfMatches, 'There should be 0 duplicates returned if encryption is enabled');
}
else {
} else {
Integer numberOfMatches = setOfMatches.split(',').size();
System.assertNotEquals('', setOfMatches, 'Duplicate Ids should be returned');
System.assertEquals(2, numberOfMatches, 'There should be 2 duplicates returned'); }
System.assertEquals(2, numberOfMatches, 'There should be 2 duplicates returned');
}
}
}

0 comments on commit 295de0a

Please sign in to comment.