forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default UoW now is secure - both FLS and CUD
Added class to allow for ability to specify different DML security for different SObject Types
- Loading branch information
1 parent
bdba10d
commit 7e057f4
Showing
8 changed files
with
135 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
framework/main/default/classes/PerSobjectTypeDmlConfiguration.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
public with sharing class PerSobjectTypeDmlConfiguration implements fflib_SobjectUnitOfWork.Idml | ||
{ | ||
fflib_SobjectUnitOfWork.Idml defaultIdml; | ||
Map<SobjectType,fflib_SobjectUnitOfWork.Idml> idmlBySobjectType; | ||
|
||
public PerSobjectTypeDmlConfiguration() | ||
{ | ||
idmlBySobjectType = new Map<SobjectType,fflib_SobjectUnitOfWork.Idml>(); | ||
} | ||
|
||
public PerSobjectTypeDmlConfiguration setDefault( fflib_SobjectUnitOfWork.Idml idml ) | ||
{ | ||
defaultIdml = idml; | ||
return this; | ||
} | ||
|
||
public PerSobjectTypeDmlConfiguration addIdml( SobjectType sobjectType, fflib_SobjectUnitOfWork.Idml idml ) | ||
{ | ||
idmlBySobjectType.put( sobjectType, idml ); | ||
return this; | ||
} | ||
|
||
public void dmlInsert( List<SObject> objList ) | ||
{ | ||
getIdmlForSobjectType( objList ).dmlInsert( objList ); | ||
} | ||
|
||
public void dmlUpdate( List<SObject> objList ) | ||
{ | ||
getIdmlForSobjectType( objList ).dmlUpdate( objList ); | ||
} | ||
|
||
public void dmlDelete( List<SObject> objList ) | ||
{ | ||
getIdmlForSobjectType( objList ).dmlDelete( objList ); | ||
} | ||
|
||
public void eventPublish( List<SObject> objList ) | ||
{ | ||
getIdmlForSobjectType( objList ).eventPublish( objList ); | ||
} | ||
|
||
public void emptyRecycleBin( List<SObject> objList ) | ||
{ | ||
getIdmlForSobjectType( objList ).emptyRecycleBin( objList ); | ||
} | ||
|
||
private fflib_SobjectUnitOfWork.Idml getIdmlForSobjectType( List<SObject> objList ) | ||
{ | ||
fflib_SobjectUnitOfWork.Idml idml; | ||
|
||
if ( !objList.isEmpty() ) | ||
{ | ||
idml = idmlBySobjectType.get( objList[0].getSObjectType() ); | ||
} | ||
|
||
if ( idml == null ) | ||
{ | ||
idml = defaultIdml; | ||
} | ||
return idml; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
framework/main/default/classes/PerSobjectTypeDmlConfiguration.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Class is a rename of FFLIB's SimpleDml to be clear about what it actually does - it provides Unsecure access to DML operations | ||
*/ | ||
public inherited sharing class UnsecureDml extends fflib_SobjectUnitOfWork.SimpleDML implements Idml {} // NOPMD: intentionally left blank |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>52.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |