-
Notifications
You must be signed in to change notification settings - Fork 521
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
#419 - implements a proposal for supporting native User Mode Database Operations introduced in Summer '22 #420
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3cf0788
#419 - implements a proposal for supporting native User Mode Database…
daveespo 4c180b1
Merge branch 'master' into 419-user-mode-proposal
ImJohnMDaniel 8cb7b05
#419 -- we should continue to enforce legacy behavior both for the LE…
daveespo 899c325
#419 - wasn't properly passing the passed in argument to the overload…
daveespo 8c30693
#419 - adds some rudimentary unit tests to cover User Mode and System…
daveespo 07cd4b5
Merge branch 'master' into 419-user-mode-proposal
daveespo 1341481
#419 - fixes bug with generation of SOQL when creating Selectors with…
daveespo e411f7c
#419 - whitespace and test method naming convention tchanges per requ…
daveespo 081a014
#419 - updates README to announce new feature and adds an overload of…
daveespo 958aca3
#419 - apparently my wiki syntax was wrong; updates the README further
daveespo e347715
#419 - apparently relative links don't work; changing to absolute
daveespo 3b4fa46
Merge branch 'master' into 419-user-mode-proposal
ImJohnMDaniel d04b6d7
#419 - updates README to call attention to UserModeDML and adds an op…
daveespo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
public abstract with sharing class fflib_SObjectSelector | ||
implements fflib_ISObjectSelector | ||
{ | ||
public enum DataAccess{LEGACY, USER_MODE, SYSTEM_MODE} | ||
|
||
/** | ||
* Indicates whether the sObject has the currency ISO code field for organisations which have multi-currency | ||
* enabled. | ||
|
@@ -64,6 +66,8 @@ public abstract with sharing class fflib_SObjectSelector | |
**/ | ||
private String m_orderBy; | ||
|
||
private DataAccess m_dataAccess = DataAccess.LEGACY; | ||
|
||
/** | ||
* Sort the query fields in the select statement (defaults to true, at the expense of performance). | ||
* Switch this off if you need more performant queries. | ||
|
@@ -111,11 +115,17 @@ public abstract with sharing class fflib_SObjectSelector | |
{ | ||
this(includeFieldSetFields, true, false); | ||
} | ||
|
||
|
||
public fflib_SObjectSelector(Boolean includeFieldSetFields, DataAccess dataAccess) | ||
{ | ||
this(includeFieldSetFields, false, false, false, dataAccess); | ||
} | ||
|
||
/** | ||
* Constructs the Selector | ||
* | ||
* @param includeFieldSetFields Set to true if the Selector queries are to include Fieldset fields as well | ||
* @param includeFieldSetFields Set to true if the Selector queries are to include Fieldset fields as well | ||
* @deprecated - consider using userMode for native platform enforcement of CRUD and FLS | ||
**/ | ||
public fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS) | ||
{ | ||
|
@@ -129,15 +139,23 @@ public abstract with sharing class fflib_SObjectSelector | |
* @param enforceCRUD Enforce CRUD security | ||
* @param enforceFLS Enforce Field Level Security | ||
* @param sortSelectFields Set to false if selecting many columns to skip sorting select fields and improve performance | ||
* @deprecated - consider using dataAccess for native platform enforcement of CRUD and FLS | ||
**/ | ||
public fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS, Boolean sortSelectFields) | ||
{ | ||
this(includeFieldSetFields,enforceCRUD,enforceFLS,sortSelectFields,DataAccess.LEGACY); | ||
} | ||
|
||
private fflib_SObjectSelector(Boolean includeFieldSetFields, Boolean enforceCRUD, Boolean enforceFLS, Boolean sortSelectFields, DataAccess dataAccess) | ||
{ | ||
m_includeFieldSetFields = includeFieldSetFields; | ||
m_enforceCRUD = enforceCRUD; | ||
m_enforceFLS = enforceFLS; | ||
m_sortSelectFields = sortSelectFields; | ||
m_DataAccess = dataAccess; | ||
} | ||
|
||
|
||
/** | ||
* Override this method to provide a list of Fieldsets that can optionally drive inclusion of additional fields in the base queries | ||
**/ | ||
|
@@ -179,6 +197,7 @@ public abstract with sharing class fflib_SObjectSelector | |
|
||
/** | ||
* @description Set the selector to enforce FLS Security | ||
* @deprecated -- consider using setDataAccess to enforce native Apex User Mode Operations instead | ||
**/ | ||
public fflib_SObjectSelector enforceFLS() | ||
{ | ||
|
@@ -211,6 +230,18 @@ public abstract with sharing class fflib_SObjectSelector | |
return this; | ||
} | ||
|
||
public fflib_SObjectSelector setDataAccess(DataAccess access){ | ||
this.m_dataAccess = access; | ||
|
||
//You can't mix and match the legacy enforceFls and assertCRUD with the SYSTEM_MODE or USER_MODE | ||
if(this.m_dataAccess != DataAccess.LEGACY){ | ||
ignoreCRUD(); | ||
m_enforceFLS = false; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Returns True if this Selector instance has been instructed by the caller to include Field Set fields | ||
**/ | ||
|
@@ -235,6 +266,10 @@ public abstract with sharing class fflib_SObjectSelector | |
return m_enforceCRUD; | ||
} | ||
|
||
public DataAccess getDataAccess(){ | ||
return m_dataAccess; | ||
} | ||
|
||
/** | ||
* Provides access to the builder containing the list of fields base queries are using, this is demand | ||
* created if one has not already been defined via setFieldListBuilder | ||
|
@@ -349,15 +384,15 @@ public abstract with sharing class fflib_SObjectSelector | |
**/ | ||
public fflib_QueryFactory newQueryFactory() | ||
{ | ||
return newQueryFactory(m_enforceCRUD, m_enforceFLS, true); | ||
return newQueryFactory(m_enforceCRUD, m_enforceFLS, true, m_DataAccess); | ||
} | ||
|
||
/** | ||
* Returns a QueryFactory configured with the Selectors object, fields, fieldsets and default order by | ||
**/ | ||
public fflib_QueryFactory newQueryFactory(Boolean includeSelectorFields) | ||
{ | ||
return newQueryFactory(m_enforceCRUD, m_enforceFLS, includeSelectorFields); | ||
return newQueryFactory(m_enforceCRUD, m_enforceFLS, includeSelectorFields, m_DataAccess); | ||
} | ||
|
||
/** | ||
|
@@ -367,9 +402,22 @@ public abstract with sharing class fflib_SObjectSelector | |
public fflib_QueryFactory newQueryFactory(Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields) | ||
{ | ||
// Construct QueryFactory around the given SObject | ||
return newQueryFactory( | ||
assertCRUD, | ||
enforceFLS, | ||
includeSelectorFields, | ||
DataAccess.LEGACY); | ||
} | ||
|
||
private fflib_QueryFactory newQueryFactory(Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields, DataAccess dataAccess) | ||
{ | ||
// Construct QueryFactory around the given SObject | ||
return configureQueryFactory( | ||
new fflib_QueryFactory(getSObjectType2()), | ||
assertCRUD, enforceFLS, includeSelectorFields); | ||
new fflib_QueryFactory(getSObjectType2()), | ||
assertCRUD, | ||
enforceFLS, | ||
includeSelectorFields, | ||
dataAccess); | ||
} | ||
|
||
/** | ||
|
@@ -408,7 +456,8 @@ public abstract with sharing class fflib_SObjectSelector | |
subSelectQueryFactory, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sync indent character. |
||
m_enforceCRUD, | ||
m_enforceFLS, | ||
includeSelectorFields); | ||
includeSelectorFields, | ||
m_dataAccess); | ||
} | ||
|
||
/** | ||
|
@@ -424,8 +473,8 @@ public abstract with sharing class fflib_SObjectSelector | |
**/ | ||
public fflib_QueryFactory addQueryFactorySubselect(fflib_QueryFactory parentQueryFactory, String relationshipName, Boolean includeSelectorFields) | ||
{ | ||
fflib_QueryFactory subSelectQueryFactory = parentQueryFactory.subselectQuery(relationshipName); | ||
return configureQueryFactory(subSelectQueryFactory, m_enforceCRUD, m_enforceFLS, includeSelectorFields); | ||
fflib_QueryFactory subSelectQueryFactory = parentQueryFactory.subselectQuery(relationshipName); | ||
return configureQueryFactory(subSelectQueryFactory, m_enforceCRUD, m_enforceFLS, includeSelectorFields, m_dataAccess); | ||
} | ||
|
||
/** | ||
|
@@ -439,9 +488,13 @@ public abstract with sharing class fflib_SObjectSelector | |
/** | ||
* Configures a QueryFactory instance according to the configuration of this selector | ||
**/ | ||
private fflib_QueryFactory configureQueryFactory(fflib_QueryFactory queryFactory, Boolean assertCRUD, Boolean enforceFLS, Boolean includeSelectorFields) | ||
private fflib_QueryFactory configureQueryFactory(fflib_QueryFactory queryFactory, | ||
Boolean assertCRUD, | ||
Boolean enforceFLS, | ||
Boolean includeSelectorFields, | ||
DataAccess access) | ||
{ | ||
// CRUD and FLS security required? | ||
// Legacy CRUD enforcement required? | ||
if (assertCRUD) | ||
{ | ||
try { | ||
|
@@ -453,7 +506,19 @@ public abstract with sharing class fflib_SObjectSelector | |
'Permission to access an ' + getSObjectType().getDescribe().getName() + ' denied.'); | ||
} | ||
} | ||
queryFactory.setEnforceFLS(enforceFLS); | ||
|
||
fflib_QueryFactory.FLSEnforcement fls = fflib_QueryFactory.FLSEnforcement.NONE; | ||
if(access == DataAccess.USER_MODE){ | ||
fls = fflib_QueryFactory.FLSEnforcement.USER_MODE; | ||
} | ||
else if(access == DataAccess.SYSTEM_MODE){ | ||
fls = fflib_QueryFactory.FLSEnforcement.SYSTEM_MODE; | ||
} | ||
else if(enforceFLS){ | ||
fls = fflib_QueryFactory.FLSEnforcement.LEGACY; | ||
} | ||
|
||
queryFactory.setEnforceFLS(fls); | ||
|
||
// Configure the QueryFactory with the Selector fields? | ||
if(includeSelectorFields) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly, indent characters are not standard throughout the framework, but since we're touching this function, let's ensure the indent characters are the same for these related functions.