From ba8bf84a6ec0fa1daf94109e96e01d34c2ac8860 Mon Sep 17 00:00:00 2001 From: Reede Stockton Date: Sat, 9 Dec 2023 09:11:01 -0800 Subject: [PATCH] Testing re-introducing HH_ManageHH_CTRL original changes (with !isHHAccount fix)... --- .../main/default/classes/HH_ManageHH_CTRL.cls | 48 +++++++++++++++---- force-app/main/default/pages/HH_ManageHH.page | 1 - 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/force-app/main/default/classes/HH_ManageHH_CTRL.cls b/force-app/main/default/classes/HH_ManageHH_CTRL.cls index 9070221ee8..4834531658 100644 --- a/force-app/main/default/classes/HH_ManageHH_CTRL.cls +++ b/force-app/main/default/classes/HH_ManageHH_CTRL.cls @@ -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; + 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) { - Contact con = new Contact(Id = contactId, npo02__Household__c = hhId); - UTIL_DMLService.updateRecord(con); + if (contactId != null) { + if (!UTIL_Permissions.canUpdate('Contact','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; } @@ -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 fieldsToCheck = new Set(); + 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; + } } \ No newline at end of file diff --git a/force-app/main/default/pages/HH_ManageHH.page b/force-app/main/default/pages/HH_ManageHH.page index e1b19d3375..ac7d543a72 100644 --- a/force-app/main/default/pages/HH_ManageHH.page +++ b/force-app/main/default/pages/HH_ManageHH.page @@ -41,7 +41,6 @@
-
This is HH_ManageHH