Skip to content

Commit

Permalink
Moved literal strings in SecureDml over to labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Dec 9, 2021
1 parent 3d11521 commit aabf774
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,60 @@
<shortDescription>Message when validation errors caught by the SObject Validator structures occur.</shortDescription>
<value>Validation Errors Occurred</value>
</labels>
<labels>
<fullName>ortoo_core_insert</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>The word 'insert'.</shortDescription>
<value>insert</value>
</labels>
<labels>
<fullName>ortoo_core_update</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>The word 'update'.</shortDescription>
<value>update</value>
</labels>
<labels>
<fullName>ortoo_core_upsert</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>The word 'upsert'.</shortDescription>
<value>upsert</value>
</labels>
<labels>
<fullName>ortoo_core_fls_violation</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Message when FLS violation occurs on a DML operation.</shortDescription>
<value>Attempted to {0} {1} with fields that are not accessible: {2}</value>
</labels>
<labels>
<fullName>ortoo_core_crud_insert_violation</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Message when CRUD violation occurs on an insert. {0} is the name of the SObject.</shortDescription>
<value>Attempted to insert {0} records without the required permission</value>
</labels>
<labels>
<fullName>ortoo_core_crud_update_violation</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Message when CRUD violation occurs on an update. {0} is the name of the SObject.</shortDescription>
<value>Attempted to update {0} records without the required permission</value>
</labels>
<labels>
<fullName>ortoo_core_crud_delete_violation</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Message when CRUD violation occurs on a delete. {0} is the name of the SObject.</shortDescription>
<value>Attempted to delete {0} records without the required permission</value>
</labels>
<labels>
<fullName>ortoo_core_crud_publish_violation</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>Message when CRUD violation occurs on a publish. {0} is the name of the Event.</shortDescription>
<value>Attempted to publish {0} events without the required permission</value>
</labels>
</CustomLabels>
18 changes: 8 additions & 10 deletions framework/main/default/classes/SecureDml.cls
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// TODO: test
// TODO: error codes
// TODO: labels
/**
* Is an implementation of the IDml interface used to manage the DML operations in an SObject Unit of Work.
*
Expand Down Expand Up @@ -433,7 +431,7 @@ public inherited sharing class SecureDml extends fflib_SobjectUnitOfWork.SimpleD
*/
public void handleUnableToInsertRecords( List<SObject> objList )
{
throwUnableException( FrameworkErrorCodes.DML_INSERT_NOT_ALLOWED, 'Attempted to insert {0} records without the required permission', objList ); // TODO: label
throwUnableException( FrameworkErrorCodes.DML_INSERT_NOT_ALLOWED, Label.ortoo_core_crud_insert_violation, objList );
}

/**
Expand All @@ -443,7 +441,7 @@ public inherited sharing class SecureDml extends fflib_SobjectUnitOfWork.SimpleD
*/
public void handleUnableToUpdateRecords( List<SObject> objList )
{
throwUnableException( FrameworkErrorCodes.DML_UPDATE_NOT_ALLOWED, 'Attempted to update {0} records without the required permission', objList ); // TODO: label
throwUnableException( FrameworkErrorCodes.DML_UPDATE_NOT_ALLOWED, Label.ortoo_core_crud_update_violation, objList );
}

/**
Expand All @@ -453,7 +451,7 @@ public inherited sharing class SecureDml extends fflib_SobjectUnitOfWork.SimpleD
*/
public void handleUnableToDeleteRecords( List<SObject> objList )
{
throwUnableException( FrameworkErrorCodes.DML_DELETE_NOT_ALLOWED, 'Attempted to delete {0} records without the required permission', objList ); // TODO: label
throwUnableException( FrameworkErrorCodes.DML_DELETE_NOT_ALLOWED, Label.ortoo_core_crud_delete_violation, objList );
}

/**
Expand All @@ -463,7 +461,7 @@ public inherited sharing class SecureDml extends fflib_SobjectUnitOfWork.SimpleD
*/
public void handleUnableToPublishEvents( List<SObject> objList )
{
throwUnableException( FrameworkErrorCodes.DML_PUBLISH_NOT_ALLOWED, 'Attempted to publish {0} events without the required permission', objList ); // TODO: label
throwUnableException( FrameworkErrorCodes.DML_PUBLISH_NOT_ALLOWED, Label.ortoo_core_crud_publish_violation, objList );
}

private void throwUnableException( String errorCode, String label, List<SObject> objList )
Expand Down Expand Up @@ -492,12 +490,12 @@ public inherited sharing class SecureDml extends fflib_SobjectUnitOfWork.SimpleD
public void handleInaccessibleFields( AccessType mode, SobjectType sobjectType, Set<String> fieldsInViolation )
{
Map<AccessType,String> descriptionByMode = new Map<AccessType,String>{
AccessType.CREATABLE => 'insert', // TODO: label
AccessType.UPDATABLE => 'update', // TODO: label
AccessType.UPSERTABLE => 'upsert' // TODO: label
AccessType.CREATABLE => Label.ortoo_core_insert,
AccessType.UPDATABLE => Label.ortoo_core_update,
AccessType.UPSERTABLE => Label.ortoo_core_upsert
};

String label = 'Attempted to {0} {1} with fields that are not accessible: {2}'; // TODO: label
String label = Label.ortoo_core_fls_violation;
String modeDescription = descriptionByMode.get( mode );
String sobjectTypeName = SobjectUtils.getSobjectName( sobjectType );

Expand Down

0 comments on commit aabf774

Please sign in to comment.