Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RD2: Consolidate Payment Widget State into App State object #6855

Merged
merged 34 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
05bf55c
Adding Billing Address to RD2 Credit Card form
lparrott Feb 9, 2022
6ba055a
Merge remote-tracking branch 'origin/feature/238' into feature/238__r…
lparrott Feb 9, 2022
e0aa988
RD2 Credit Card Billing Address review feedback
lparrott Feb 10, 2022
3b6119a
Merge 482d4595a5df890d1df07b095e9c9b23cccb8899 into feature/238__rd2F…
salesforce-org-metaci[bot] Feb 10, 2022
1f94336
Initial WorldPay changes
voduyemi Feb 10, 2022
399ad20
Added geFormWidget changes
voduyemi Feb 10, 2022
865c714
RD2 Billing Address, adding Country field and button to fill with Don…
lparrott Feb 10, 2022
646f8b0
Adding Unit tests for Donor Address getter
lparrott Feb 11, 2022
9748d4c
Merge remote-tracking branch 'origin/feature/238__giftEntryWorldPayFi…
lparrott Feb 11, 2022
96cbc67
Merge 7a67597da8aab815b27bf8509d6a9c215f426b04 into feature/238__rd2F…
salesforce-org-metaci[bot] Feb 11, 2022
c017424
RD2 Credit Card Billing Address, updating UX based on feedback, revie…
lparrott Feb 11, 2022
f68d639
RD2 Credit Card Billing Address, design fixes, updating Labels
lparrott Feb 11, 2022
e4be68f
Merge branch 'feature/238__rd2FormBillingAddress' of https://github.c…
lparrott Feb 11, 2022
8581c56
RD2 - Fill in actions for changing record name, status, campaign, cha…
Feb 12, 2022
3a4d0c4
RD2 Credit Card form, adding mock permissions tests
lparrott Feb 12, 2022
d576675
RD2 tests - Ensure isElevateCustomer is true for tests requiring elev…
Feb 14, 2022
7d9b5b0
RD2 Credit Card Billing Address: Toggle Billing Address field buttons…
lparrott Feb 14, 2022
932ddc6
RD2 - Remove getRecurringSettings method, update tests.
Feb 15, 2022
e84a17a
Merge branch 'feature/238' of github.com:SalesforceFoundation/NPSP in…
Feb 15, 2022
83e597b
Merge b3e7f3e94fde3174ac024b76c84f150cb93ad914 into feature/238__rd2F…
salesforce-org-metaci[bot] Feb 15, 2022
b0bbf29
Merge 5b1b3e83c27f077ca2fa79d1681970e1f2a38ef9 into feature/238__rd2F…
salesforce-org-metaci[bot] Feb 15, 2022
eadaf9a
RD2 - Remove instanceOf comparisons.
Feb 15, 2022
6bf13af
Merge branch 'feature/238__rd2FormBillingAddress' of github.com:Sales…
Feb 15, 2022
239aaf2
RD2 - Move elevate widget evaluations into rd2Service, migrate consta…
Feb 15, 2022
daf2408
rd2Service - Remove unused/unreferenced functions.
Feb 16, 2022
aa1b861
RD2 - Prettier Formatting
Feb 16, 2022
f39bbec
RD2 Fix for Use Donor Address in Payment Info Modal
lparrott Feb 16, 2022
2f3baef
RD2 - When save process fails, loading spinner should hide.
Feb 16, 2022
616da16
RD2 Credit Card form, removing Billing Address when Payment method ch…
lparrott Feb 17, 2022
eda6d7b
Merge branch 'feature/238__rd2FormBillingAddress' of github.com:Sales…
Feb 17, 2022
77aa6a6
RD2 - Retrieve/track RD2 Name Field.
Feb 17, 2022
de148f1
RD2 Elevate Information Component - Test updates for compatibility wi…
Feb 17, 2022
3a0d6ff
RD2_EntryFormController - Use String.valueOf with field references t…
Feb 17, 2022
af4ea36
Merge 492a4c6410a00156c453075b0d41d102e9049d2a into feature/238__rd-p…
salesforce-org-metaci[bot] Feb 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 67 additions & 28 deletions force-app/main/default/classes/RD2_EntryFormController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public with sharing class RD2_EntryFormController {
set;
}

/***
* @description Permissions class used to determine if the running user has permissions
*/
@TestVisible
private static UTIL_Permissions permissions {
get {
if (permissions == null) {
permissions = new UTIL_Permissions();
}
return permissions;
}
set;
}

/***
* @description Retrieves the record type id for the household account record type
*/
Expand All @@ -87,6 +101,13 @@ public with sharing class RD2_EntryFormController {
@AuraEnabled
public static RD2AppView getInitialView(Id parentId, Id recordId) {
RD2AppView view = new RD2AppView();

view.hasRequiredPermissions = hasRequiredFieldPermissions();
if(!view.hasRequiredPermissions) {
return view;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What were your thoughts here regarding returning an empty view instead of an AuraHandledException like we do in other AuraEnabled methods in this class?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, it was closer to the original behavior of the component. I think we could do that here too and have that be our standard. Any AuraEnabled function that a user does not have the correct level of permissions for would throw an exception.

}


view.isAutoNamingEnabled = RD2_NamingService.isAutomaticNamingEnabled;
view.isMultiCurrencyEnabled = UserInfo.isMultiCurrencyOrganization();
view.parentSObjectType = (parentId == null) ? null : UTIL_Describe.objectNameFromId(parentId);
Expand Down Expand Up @@ -133,35 +154,50 @@ public with sharing class RD2_EntryFormController {
return UTIL_Describe.getLightningSelectOptions('npe03__Recurring_Donation__c','npe03__Installment_Period__c');
}


/**
* @description Gather the org, object and environment setting for Recurring Donation Entry/Edit Form
* @param parentId The parentId of the new RD
* @return Map<String, Object>
* @description Retrieve the donor address given an Account or Contact Id
* @param donorId Id of donor, Account or Contact
* @return Address__c of the Account's BillingAddress or Contact's MailingAddress
*/
@AuraEnabled(Cacheable=true)
public static Map<String, Object> getRecurringSettings(Id parentId) {
String parentSObjectType = (parentId == null)
? null
: parentId.getSobjectType().getDescribe().getName();

String defaultRecurringType = UTIL_Describe.getDefaultSelectOption(
'npe03__Recurring_Donation__c', String.valueOf(npe03__Recurring_Donation__c.RecurringType__c)
);
@AuraEnabled
public static Address__c getDonorAddress(Id donorId) {
if (donorId == null) {
return null;
}

return new Map<String, Object> {
'isAutoNamingEnabled' => RD2_NamingService.isAutomaticNamingEnabled,
'isMultiCurrencyEnabled' => UserInfo.isMultiCurrencyOrganization(),
'parentSObjectType' => parentSObjectType,
'InstallmentPeriodPermissions' => getFieldPermissionsMap('npe03__Installment_Period__c'),
'InstallmentFrequencyPermissions' => getFieldPermissionsMap(UTIL_Namespace.StrTokenNSPrefix('InstallmentFrequency__c')),
'customFieldSets' => getCustomFieldSectionFields(),
'isElevateCustomer' => RD2_ElevateIntegrationService.isIntegrationEnabled(),
'isChangeLogEnabled' => RD2_ChangeLogService.isChangeLogEnabled,
'periodToYearlyFrequencyMap' => RD2_Constants.PERIOD_TO_YEARLY_FREQUENCY,
'closedStatusValues' => RD2_StatusMapper.getInstance().getClosedStatusValues(),
'defaultRecurringType' => defaultRecurringType
};
SObjectType donorObjectType = donorId.getSobjectType();
if (!hasDonorAddressPermissions(donorObjectType)) {
AuraHandledException ex = new AuraHandledException(Label.commonPermissionErrorMessage);
ex.setMessage(Label.commonPermissionErrorMessage);
throw ex;
}

NPSP_Address donorAddress = new NPSP_Address(new Address__c());
if(donorObjectType == Account.SObjectType) {
Account donorAccount;
Map<Id, Account> accounts = Addresses.getAccountsByIds(new Set<Id>{donorId});
if (accounts != null) {
donorAddress.copyFromSObject(accounts.get(donorId), 'Billing', null);
}
} else if(donorObjectType == Contact.SObjectType) {
List<Contact> contacts = ContactSelector.getContactAddressFieldsForContactsIn(new Set<Id>{donorId});
if (contacts != null) {
donorAddress.copyFromSObject(contacts[0], 'Mailing', null);
}
}

Address__c address = donorAddress.getRecord();
return address;
}

private static Boolean hasDonorAddressPermissions(SObjectType donorObjectType) {
Boolean hasAccess = false;
if (donorObjectType == Account.SObjectType) {
hasAccess = permissions.canRead(Account.SObjectType, new Set<SObjectField>{Account.BillingAddress});
} else if(donorObjectType == Contact.SObjectType) {
hasAccess = permissions.canRead(Contact.SObjectType, new Set<SObjectField>{Contact.MailingAddress});
}
return hasAccess;
}

private static String getDonorType(npe03__Recurring_Donation__c rd) {
Expand All @@ -188,8 +224,8 @@ public with sharing class RD2_EntryFormController {
* false, the custom UI will display a warning message at the top of the page.
* @return True if the User has Read access to all required fields in the UI
*/
@AuraEnabled(Cacheable=true)
public static Boolean hasRequiredFieldPermissions() {
@TestVisible
private static Boolean hasRequiredFieldPermissions() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the collection of fields here, could we use String.valueOf(SObject.FieldName)? That way with other fields are added in the future that are not in the underlying packages, we don't have to worry about including namespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed this over!

Set<String> requiredFields = new Set<String>{
'npe03__Amount__c',
'npe03__Contact__c',
Expand Down Expand Up @@ -531,6 +567,7 @@ public with sharing class RD2_EntryFormController {
@AuraEnabled public String cardLastFour;
@AuraEnabled public String cardExpirationMonth;
@AuraEnabled public String cardExpirationYear;
@AuraEnabled public String paymentMethod;
@AuraEnabled public Map<String, Object> customFieldValues;

public RD2RecordView() {
Expand All @@ -556,6 +593,7 @@ public with sharing class RD2_EntryFormController {
this.dayOfMonth = record.Day_of_Month__c;
this.plannedInstallments = record.npe03__Installments__c?.intValue();
this.paidInstallments = record.npe03__Total_Paid_Installments__c?.intValue();
this.paymentMethod = record.PaymentMethod__c;
this.recurringType = record.RecurringType__c;
this.commitmentId = record.CommitmentId__c;
this.achLastFour = record.ACH_Last_4__c;
Expand Down Expand Up @@ -584,6 +622,7 @@ public with sharing class RD2_EntryFormController {
@AuraEnabled public String defaultInstallmentPeriod;
@AuraEnabled public List<Map<String, String>> installmentPeriodOptions;
@AuraEnabled public Id parentId;
@AuraEnabled public Boolean hasRequiredPermissions;

@AuraEnabled public RD2RecordView record;

Expand Down
Loading