Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ deploy-options.json
# LWC Jest coverage reports
coverage/

# Code Analyzer report output
CodeAnalyzerReport.*
CodeAnalyzer*.csv

# Logs
logs
*.log
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"**/node_modules": true,
"**/bower_components": true,
"**/.sfdx": true
}
},
"xml.preferences.showSchemaDocumentationType": "none"
}
102 changes: 68 additions & 34 deletions force-app/main/default/classes/lwcProfileEditorController.cls
Original file line number Diff line number Diff line change
@@ -1,43 +1,77 @@
public class lwcProfileEditorController {
public with sharing class lwcProfileEditorController {
@AuraEnabled(cacheable=true)
public static List<Map<String, String>> getSObjects() {
checkAccess();

@AuraEnabled(cacheable=true)
public static List<Map<String,String>> getSObjects() {
List<Map<String,String>> results = new List<Map<String,String>>();
Map<String, SObjectType> allTypes = Schema.getGlobalDescribe();
List<Map<String, String>> results = new List<Map<String, String>>();
Map<String, SObjectType> allTypes = Schema.getGlobalDescribe();

for (String objType : new List<String>(allTypes.keySet())) {
for (String objType : new List<String>(allTypes.keySet())) {
Schema.DescribeSObjectResult describeObject = allTypes.get(objType)
.getDescribe();
String objectType = describeObject.getName();
String objectLabel = describeObject.getLabel();
Boolean isCustom = describeObject.isCustom();
Boolean isCustomSetting = describeObject.isCustomSetting();
Boolean isCustomChangeEvent = objectType.endsWith('__ChangeEvent');
Boolean isPlatformEvent = objectType.endsWith('__e');
Boolean isCMDT = objectType.endsWith('__mdt');
Boolean isStdFeed = !isCustom && objectType.endsWith('Feed');
Boolean isStdHistory = !isCustom && objectType.endsWith('History');
Boolean isStdShare = !isCustom && objectType.endsWith('Share');
Boolean isStdChangeEvent =
!isCustom && objectType.endsWith('ChangeEvent');

Schema.DescribeSObjectResult describeObject = allTypes.get(objType).getDescribe();
String objectType = describeObject.getName();
String objectLabel = describeObject.getLabel();
Boolean isCustom = describeObject.isCustom();
Boolean isCustomSetting = describeObject.isCustomSetting();
Boolean isCustomChangeEvent = objectType.endsWith('__ChangeEvent');
Boolean isPlatformEvent = objectType.endsWith('__e');
Boolean isCMDT = objectType.endsWith('__mdt');
Boolean isStdFeed = !isCustom && objectType.endsWith('Feed');
Boolean isStdHistory = !isCustom && objectType.endsWith('History');
Boolean isStdShare = !isCustom && objectType.endsWith('Share');
Boolean isStdChangeEvent = !isCustom && objectType.endsWith('ChangeEvent');

if (!isCustomSetting && !isCustomChangeEvent && !isCMDT && !isPlatformEvent && !isStdFeed && !isStdChangeEvent && !isStdHistory && !isStdShare ) {
results.add(new Map<String,String>{'label' => objectLabel + ' (' + objectType + ')', 'value' => objectType});
}
if (
!isCustomSetting &&
!isCustomChangeEvent &&
!isCMDT &&
!isPlatformEvent &&
!isStdFeed &&
!isStdChangeEvent &&
!isStdHistory &&
!isStdShare
) {
results.add(
new Map<String, String>{
'label' => objectLabel +
' (' +
objectType +
')',
'value' => objectType
}
);
}
}

}
return results;
}

return results;
@AuraEnabled(cacheable=true)
public static string getDurableId(String qualifiedApiName) {
checkAccess();

List<EntityDefinition> eds = [
SELECT DurableId
FROM EntityDefinition
WHERE QualifiedApiName = :qualifiedApiName
WITH SYSTEM_MODE
LIMIT 1
];
if (eds.isEmpty()) {
return null;
}

@AuraEnabled(cacheable=true)
public static string getDurableId(String qualifiedApiName){
List<EntityDefinition> eds = [SELECT DurableId FROM EntityDefinition WHERE QualifiedApiName = :qualifiedAPiName LIMIT 1];
if(eds.isEmpty()){
return null;
}

return eds[0].DurableId;
}
return eds[0].DurableId;
}

}
private static void checkAccess() {
if (!FeatureManagement.checkPermission('Manage_Problem_Profiles')) {
AuraHandledException ex = new AuraHandledException(
'You do not have access to this feature.'
);
ex.setMessage('You do not have access to this feature.');
throw ex;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>63.0</apiVersion>
<apiVersion>67.0</apiVersion>
<status>Active</status>
</ApexClass>
102 changes: 82 additions & 20 deletions force-app/main/default/classes/lwcProfileEditorControllerTest.cls
Original file line number Diff line number Diff line change
@@ -1,35 +1,97 @@
@IsTest
private class lwcProfileEditorControllerTest {
private static User createTestUser(Boolean withAccess) {
Profile standardProfile = [
SELECT Id
FROM Profile
WHERE Name = 'Standard User'
LIMIT 1
];
User testUser = new User(
FirstName = 'Test',
LastName = 'ProblemProfileUser',
Email = 'problem.profile.test.user@example.com.invalid',
Username = 'problem.profile.test.user' +
Crypto.getRandomInteger() +
'@example.com.invalid',
Alias = 'ppuser',
TimeZoneSidKey = 'America/Los_Angeles',
LocaleSidKey = 'en_US',
EmailEncodingKey = 'UTF-8',
LanguageLocaleKey = 'en_US',
ProfileId = standardProfile.Id
);
insert testUser;

@IsTest
static void successfullyRetrieveObjectDescribe(){

List<Map<String,String>> objectValues = lwcProfileEditorController.getSObjects();
if (withAccess) {
PermissionSet accessPermSet = [
SELECT Id
FROM PermissionSet
WHERE Name = 'Problem_Profile_Editor_Access'
LIMIT 1
];
insert new PermissionSetAssignment(
AssigneeId = testUser.Id,
PermissionSetId = accessPermSet.Id
);
}

return testUser;
}

@IsTest
static void successfullyRetrieveObjectDescribe() {
User testUser = createTestUser(true);

List<Map<String, String>> objectValues;
System.runAs(testUser) {
objectValues = lwcProfileEditorController.getSObjects();
}

Assert.isFalse(objectValues.isEmpty());

Map<String, String> firstRecord = objectValues[0];
Assert.isNotNull(firstRecord.get('label'));
Assert.isNotNull(firstRecord.get('value'));
}

Assert.isFalse(objectValues.isEmpty());
@IsTest
static void successfullyRetrieveDurableId() {
User testUser = createTestUser(true);

Map<String,String> firstRecord = objectValues[0];
Assert.isNotNull(firstRecord.get('label'));
Assert.isNotNull(firstRecord.get('value'));

String durableId;
System.runAs(testUser) {
durableId = lwcProfileEditorController.getDurableId('Account');
}

@IsTest
static void successfullyRetrieveDurableId(){
Assert.areEqual('Account', durableId);
}

String durableId = lwcProfileEditorController.getDurableId('Account');
@IsTest
static void successfullyReturnNullForNoMatch() {
User testUser = createTestUser(true);

Assert.areEqual('Account', durableId);

String durableId;
System.runAs(testUser) {
durableId = lwcProfileEditorController.getDurableId('Account__test');
}

@IsTest
static void successfullyReturnNullForNoMatch(){
Assert.isNull(durableId);
}

String durableId = lwcProfileEditorController.getDurableId('Account__test');
@IsTest
static void throwsWhenUserLacksCustomPermission() {
User testUser = createTestUser(false);

Assert.isNull(durableId);

Boolean exceptionThrown = false;
System.runAs(testUser) {
try {
lwcProfileEditorController.getSObjects();
} catch (AuraHandledException e) {
exceptionThrown = true;
}
}

}
Assert.isTrue(exceptionThrown);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>63.0</apiVersion>
<apiVersion>67.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomPermission xmlns="http://soap.sforce.com/2006/04/metadata">
<description
>Grants access to the Problem Profile Editor tool, used to navigate to Setup pages for profiles that require Classic or URL-based access to edit.</description>
<isLicensed>false</isLicensed>
<label>Manage Problem Profiles</label>
</CustomPermission>
Loading