Skip to content

Commit

Permalink
Check for standard Level__c field creation permission
Browse files Browse the repository at this point in the history
  • Loading branch information
npsp-reedestockton committed Nov 10, 2023
1 parent 81f86c3 commit a3b24f2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
47 changes: 46 additions & 1 deletion force-app/main/default/classes/LVL_LevelEdit_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,28 @@ public with sharing class LVL_LevelEdit_CTRL {
/** @description holds the Level currently being edited by the page */
public Level__c lvl {get; set;}
private List<String> requiredFieldSetFields;


public Boolean hasAccess {
get {
if (hasAccess == null) {
hasAccess = canWriteLevel();
}
return hasAccess;
}
private set;
}

private UTIL_Permissions perms {
get {
if (perms == null) {
perms = new UTIL_Permissions();
}

return perms;
}
set;
}

/*******************************************************************************************************
* @description constructor for the page
* @param controller the StandardController for the page
Expand Down Expand Up @@ -158,6 +179,9 @@ public with sharing class LVL_LevelEdit_CTRL {
if (reportFieldSetErrors()) {
return null;
}
if (!canWriteLevel()) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
upsert lvl;
// now fixup lvl to be the new next level
lvl.Id = null;
Expand All @@ -181,6 +205,9 @@ public with sharing class LVL_LevelEdit_CTRL {
if (reportFieldSetErrors()) {
return null;
}
if (!canWriteLevel()) {
throw new UTIL_Permissions.InsufficientPermissionException(System.Label.commonAccessErrorMessage);
}
upsert lvl;
return new PageReference('/' + lvl.Id);
} catch (Exception ex) {
Expand All @@ -204,4 +231,22 @@ public with sharing class LVL_LevelEdit_CTRL {
return hasError;
}

private Boolean canWriteLevel() {
Set<SObjectField> sObjectFieldsCreate = new Set<SObjectField>{
Level__c.fields.Active__c,
Level__c.fields.Level_Field__c,
Level__c.fields.Maximum_Amount__c,
Level__c.fields.Minimum_Amount__c,
Level__c.fields.Name,
Level__c.fields.Previous_Level_Field__c,
Level__c.fields.Source_Field__c,
Level__c.fields.Target__c
};

if (!perms.canCreate(Level__c.SObjectType, sObjectFieldsCreate)) {
return false;
}

return true;
}
}
6 changes: 5 additions & 1 deletion force-app/main/default/pages/LVL_LevelEdit.page
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
lightningStylesheets="true"
title="{!$ObjectType.Level__c.labelPlural}">

<apex:outputPanel rendered="{!NOT(hasAccess)}">
<c:InsufficientPermissions />
</apex:outputPanel>

<apex:slds />
<apex:stylesheet value="{!URLFOR($Resource.CumulusStaticResources, '/npsp-slds/npsp-common.css')}" />

Expand All @@ -26,7 +30,7 @@
$ObjectType.Level__c.fields.Previous_Level_Field__c.updateable,
$ObjectType.Level__c.fields.Source_Field__c.updateable,
$ObjectType.Level__c.Fields.Target__c.updateable)}" />
<apex:form >
<apex:form rendered="{!(hasAccess)}">
<div class="slds-scope slds-wcag">

<c:UTIL_PageHeader headerLabel="{!$ObjectType.Level__c.Label}" header="{!Level__c.Name}" icon="custom11" iconCategory="custom"
Expand Down

0 comments on commit a3b24f2

Please sign in to comment.