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

Add Permissions Checks to HH_ManageHH_CTRL #7207

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
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
50 changes: 41 additions & 9 deletions force-app/main/default/classes/HH_ManageHH_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,28 @@ public with sharing class HH_ManageHH_CTRL {
* @return null
*/
public PageReference handleNewHousehold() {
if (hhId == null) {
hh = new npo02__Household__c();
hh.put('Name', Label.npo02.DefaultHouseholdName); // name will get fixed up when we update the contact
UTIL_DMLService.insertRecord(hh);
hhId = hh.Id;

if (contactId != null) {
Contact con = new Contact(Id = contactId, npo02__Household__c = hhId);
UTIL_DMLService.updateRecord(con);
try {
if (hhId == null) {
if (!UTIL_Permissions.canCreate('npo02__Household__c')) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
hh = new npo02__Household__c();
hh.put('Name', Label.npo02.DefaultHouseholdName); // name will get fixed up when we update the contact
UTIL_DMLService.insertRecord(hh);
hhId = hh.Id;

if (contactId != null) {
if (!UTIL_Permissions.canUpdate('npo02__Household__c','npo02__Household__c', false)) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
Contact con = new Contact(Id = contactId, npo02__Household__c = hhId);
UTIL_DMLService.updateRecord(con);
}
}
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, e.getMessage()));
}

return null;
}

Expand Down Expand Up @@ -164,10 +175,31 @@ public with sharing class HH_ManageHH_CTRL {
*/
public PageReference save() {
try {
if (!canUpdateHousehold()) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
UTIL_DMLService.updateRecord(hh);
} catch (Exception ex) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, ex.getMessage()));
}
return null;
}

private Boolean canUpdateHousehold() {
String accountToCheck = isHHAccount ? 'Account' : 'npo02__Household__c';
Set<String> fieldsToCheck = new Set<String>();
for (FieldSetMember fsMember : hhFieldSet) {
fieldsToCheck.add(fsMember.getFieldPath());
}
if (isHHAccount) {
fieldsToCheck.add('npo02__Household__c');
}
for (String fieldToCheck : fieldsToCheck) {
if (!UTIL_Permissions.canUpdate(accountToCheck, fieldToCheck, false)) {
return false;
}
}

return true;
}
}
Loading