Skip to content

Commit

Permalink
Remove read access security check for realtime calculations
Browse files Browse the repository at this point in the history
See
#1
62. Also updated to latest Apex Enterprise Patterns library (fflib) and
made some updates to the Selector classes. Removed unwanted ‘with
sharing’ declarations (this is driven by the service/controller/batch
class).
  • Loading branch information
afawcettffdc committed Jul 6, 2015
1 parent cc99e48 commit aad3948
Show file tree
Hide file tree
Showing 76 changed files with 6,853 additions and 1,085 deletions.
13 changes: 6 additions & 7 deletions rolluptool/src/classes/ApexClassesSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Performs various queries on the ApexClass object
**/
public with sharing class ApexClassesSelector extends SObjectSelector
public class ApexClassesSelector extends fflib_SObjectSelector
{
public List<Schema.SObjectField> getSObjectFieldList()
{
Expand Down Expand Up @@ -59,12 +59,11 @@ public with sharing class ApexClassesSelector extends SObjectSelector
**/
public Map<String, ApexClass> selectByName(Set<String> names)
{
assertIsAccessible();
List<ApexClass> apexClasses = Database.query(String.format(
'select {0} from {1} where Name in :names order by {2}',
new List<String>{getFieldListString(),
getSObjectName(),
getOrderBy()}));
List<ApexClass> apexClasses =
Database.query(
newQueryFactory().
setCondition('Name in :names').
toSOQL());
Map<String, ApexClass> mapByName = new Map<String, ApexClass>();
for(ApexClass apexClass : apexClasses)
mapByName.put(apexClass.Name, apexClass);
Expand Down
13 changes: 6 additions & 7 deletions rolluptool/src/classes/ApexTriggersSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Performs various queries on the ApexTrigger object
**/
public with sharing class ApexTriggersSelector extends SObjectSelector
public class ApexTriggersSelector extends fflib_SObjectSelector
{
public List<Schema.SObjectField> getSObjectFieldList()
{
Expand Down Expand Up @@ -68,12 +68,11 @@ public with sharing class ApexTriggersSelector extends SObjectSelector
**/
public Map<String, ApexTrigger> selectByName(Set<String> names)
{
assertIsAccessible();
List<ApexTrigger> apexTriggers = Database.query(String.format(
'select {0} from {1} where Name in :names order by {2}',
new List<String>{getFieldListString(),
getSObjectName(),
getOrderBy()}));
List<ApexTrigger> apexTriggers =
Database.query(
newQueryFactory().
setCondition('Name in :names').
toSOQL());
Map<String, ApexTrigger> mapByName = new Map<String, ApexTrigger>();
for(ApexTrigger apexTrigger : apexTriggers)
mapByName.put(apexTrigger.Name, apexTrigger);
Expand Down
23 changes: 11 additions & 12 deletions rolluptool/src/classes/AsyncApexJobsSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/

public with sharing class AsyncApexJobsSelector extends SObjectSelector
{
public override String getOrderBy()
{
return 'CreatedDate';
}

public class AsyncApexJobsSelector extends fflib_SObjectSelector
{
List<Schema.SObjectField> getSObjectFieldList()
{
return new List<Schema.SObjectField> {
Expand All @@ -49,6 +44,11 @@ public with sharing class AsyncApexJobsSelector extends SObjectSelector
{
return AsyncApexJob.sObjectType;
}

public override String getOrderBy()
{
return 'CreatedDate';
}

public List<AsyncApexJob> selectById(Set<ID> idSet)
{
Expand All @@ -63,12 +63,11 @@ public with sharing class AsyncApexJobsSelector extends SObjectSelector
Set<String> statuses = new Set<String> { 'Queued', 'Processing', 'Preparing' };
String jobType = 'BatchApex';
String query =
String.format(
'select {0} from {1} ' +
'where JobType = :jobType And ' +
newQueryFactory().
setCondition(
'JobType = :jobType And ' +
'ApexClass.Name in :classNames And ' +
'Status in :statuses',
new List<String>{getFieldListString(),getSObjectName()});
'Status in :statuses').toSOQL();
List<AsyncApexJob> jobs = (List<AsyncApexJob>)
Database.query(query);
return jobs.size()>0;
Expand Down
2 changes: 1 addition & 1 deletion rolluptool/src/classes/RollupControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
**/

@IsTest
private with sharing class RollupControllerTest
private class RollupControllerTest
{
private testmethod static void testDeployedStatus()
{
Expand Down
2 changes: 1 addition & 1 deletion rolluptool/src/classes/RollupJobTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
**/

@IsTest
private with sharing class RollupJobTest
private class RollupJobTest
{

}
2 changes: 1 addition & 1 deletion rolluptool/src/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ global with sharing class RollupService
// Query applicable lookup definitions
Schema.DescribeSObjectResult childRecordDescribe = childObjectType.getDescribe();
List<LookupRollupSummary__c> lookups =
new RollupSummariesSelector().selectActiveByChildObject(
new RollupSummariesSelector(false).selectActiveByChildObject(
new List<RollupSummaries.CalculationMode> { RollupSummaries.CalculationMode.Realtime, RollupSummaries.CalculationMode.Scheduled },
new Set<String> { childRecordDescribe.getName() });
return lookups;
Expand Down
6 changes: 3 additions & 3 deletions rolluptool/src/classes/RollupSummaries.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Validation and other behaviour for the Lookup Rollup Summary custom object
**/
public with sharing class RollupSummaries extends SObjectDomain
public class RollupSummaries extends fflib_SObjectDomain
{
private static final Integer APEXTRIGGER_NAME_LENGTH = 40; // ApexTrigger.Name.getDescribe().getLength(); gives 255?

Expand Down Expand Up @@ -221,9 +221,9 @@ public with sharing class RollupSummaries extends SObjectDomain

private static final String MSG_INVALID_CRITERIA = 'Relationship Criteria \'\'{0}\'\' is not valid, see SOQL documentation http://www.salesforce.com/us/developer/docs/soql_sosl/Content/sforce_api_calls_soql_select_conditionexpression.htm, error is \'\'{1}\'\'';

public class Constructor implements SObjectDomain.IConstructable
public class Constructor implements fflib_SObjectDomain.IConstructable
{
public SObjectDomain construct(List<SObject> sObjectList)
public fflib_SObjectDomain construct(List<SObject> sObjectList)
{
return new RollupSummaries(sObjectList);
}
Expand Down
35 changes: 21 additions & 14 deletions rolluptool/src/classes/RollupSummariesSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@
/**
* Various queries for the Lookup Rollup Summary custom object
**/
public with sharing class RollupSummariesSelector extends SObjectSelector
public class RollupSummariesSelector extends fflib_SObjectSelector
{
public RollupSummariesSelector() {
super();
}

public RollupSummariesSelector(boolean enforceSecurity) {
super(false, enforceSecurity, enforceSecurity);
}

public List<Schema.SObjectField> getSObjectFieldList()
{
return new List<Schema.SObjectField> {
Expand Down Expand Up @@ -73,28 +81,27 @@ public with sharing class RollupSummariesSelector extends SObjectSelector
**/
public List<LookupRollupSummary__c> selectActiveByChildObject(List<RollupSummaries.CalculationMode> calculationModes, Set<String> childObjectNames)
{
assertIsAccessible();
List<String> calculationModeNames = new List<String>();
for(RollupSummaries.CalculationMode calculationMode : calculationModes)
calculationModeNames.add(calculationMode.name());
return Database.query(String.format(
'select {0} from {1} where CalculationMode__c in :calculationModeNames and ChildObject__c in :childObjectNames and Active__c = true order by ParentObject__c, RelationshipField__c',
new List<String>{getFieldListString(),
getSObjectName(),
getOrderBy()}));
return Database.query(
newQueryFactory().
setCondition('CalculationMode__c in :calculationModeNames and ChildObject__c in :childObjectNames and Active__c = true').
addOrdering(LookupRollupSummary__c.ParentObject__c, fflib_QueryFactory.SortOrder.ASCENDING).
addOrdering(LookupRollupSummary__c.RelationshipField__c, fflib_QueryFactory.SortOrder.ASCENDING).
toSOQL());
}

/**
* Returns active lookup rollup summary definitions for the given rollup unique names
**/
public List<LookupRollupSummary__c> selectActiveByUniqueName(Set<String> uniqueNames)
{
assertIsAccessible();
return Database.query(String.format(
'select {0} from {1} where UniqueName__c in :uniqueNames and Active__c = true order by ParentObject__c, RelationshipField__c',
new List<String>{getFieldListString(),
getSObjectName(),
getOrderBy()}));

return Database.query(
newQueryFactory().
setCondition('UniqueName__c in :uniqueNames and Active__c = true').
addOrdering(LookupRollupSummary__c.ParentObject__c, fflib_QueryFactory.SortOrder.ASCENDING).
addOrdering(LookupRollupSummary__c.RelationshipField__c, fflib_QueryFactory.SortOrder.ASCENDING).
toSOQL());
}
}
Loading

0 comments on commit aad3948

Please sign in to comment.