-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from 33 commits
05bf55c
6ba055a
e0aa988
3b6119a
1f94336
399ad20
865c714
646f8b0
9748d4c
96cbc67
c017424
f68d639
e4be68f
8581c56
3a4d0c4
d576675
7d9b5b0
932ddc6
e84a17a
83e597b
b0bbf29
eadaf9a
6bf13af
239aaf2
daf2408
aa1b861
f39bbec
2f3baef
616da16
eda6d7b
77aa6a6
de148f1
3a0d6ff
af4ea36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
*/ | ||
|
@@ -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; | ||
} | ||
|
||
|
||
view.isAutoNamingEnabled = RD2_NamingService.isAutomaticNamingEnabled; | ||
view.isMultiCurrencyEnabled = UserInfo.isMultiCurrencyOrganization(); | ||
view.parentSObjectType = (parentId == null) ? null : UTIL_Describe.objectNameFromId(parentId); | ||
|
@@ -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) { | ||
|
@@ -188,16 +224,16 @@ 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the collection of fields here, could we use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
'npe03__Installment_Period__c', | ||
'npe03__Date_Established__c', | ||
UTIL_Namespace.StrTokenNSPrefix('InstallmentFrequency__c'), | ||
UTIL_Namespace.StrTokenNSPrefix('Day_of_Month__c'), | ||
UTIL_Namespace.StrTokenNSPrefix('StartDate__c') | ||
String.valueOf(npe03__Recurring_Donation__c.npe03__Amount__c), | ||
String.valueOf(npe03__Recurring_Donation__c.npe03__Contact__c), | ||
String.valueOf(npe03__Recurring_Donation__c.npe03__Installment_Period__c), | ||
String.valueOf(npe03__Recurring_Donation__c.npe03__Date_Established__c), | ||
String.valueOf(npe03__Recurring_Donation__c.InstallmentFrequency__c), | ||
String.valueOf(npe03__Recurring_Donation__c.Day_of_Month__c), | ||
String.valueOf(npe03__Recurring_Donation__c.StartDate__c) | ||
}; | ||
|
||
Boolean hasPermissions = true; | ||
|
@@ -510,6 +546,7 @@ public with sharing class RD2_EntryFormController { | |
|
||
public class RD2RecordView { | ||
@AuraEnabled public Id recordId; | ||
@AuraEnabled public String recordName; | ||
@AuraEnabled public String recurringStatus; | ||
@AuraEnabled public Id contactId; | ||
@AuraEnabled public Id accountId; | ||
|
@@ -531,6 +568,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() { | ||
|
@@ -546,6 +584,7 @@ public with sharing class RD2_EntryFormController { | |
this.contactId = record.npe03__Contact__c; | ||
this.accountId = record.npe03__Organization__c; | ||
this.recurringStatus = record.Status__c; | ||
this.recordName = record.Name; | ||
this.donorType = getDonorType(record); | ||
this.dateEstablished = record.npe03__Date_Established__c; | ||
this.donationValue = record.npe03__Amount__c; | ||
|
@@ -556,6 +595,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; | ||
|
@@ -584,6 +624,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; | ||
|
||
|
There was a problem hiding this comment.
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 otherAuraEnabled
methods in this class?There was a problem hiding this comment.
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.