Skip to content

Commit

Permalink
Merge pull request #173 from navikt/Person-highlight-panel
Browse files Browse the repository at this point in the history
Person highlight panel
  • Loading branch information
olsenrasmus authored Feb 4, 2025
2 parents 20212c0 + d7a8748 commit afddcff
Show file tree
Hide file tree
Showing 24 changed files with 1,158 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
public without sharing class HOT_PersonAccessBadgesController {
/**
* @description Get an apex type holding all the data we need for showing badges.
*/
@AuraEnabled(cacheable=true)
public static List<AccessBadge> getPersonAccessBadges(String field, String parentObject, String parentRecordId) {
Id personId = getPersonId(field, parentObject, parentRecordId);

if (String.isBlank(personId)) {
return new List<AccessBadge>();
}

Person__c person = getPerson(personId);
return createAccessBadgeList(person);
}

private static List<AccessBadge> createAccessBadgeList(Person__c person) {
List<AccessBadge> accessBadgeList = new List<AccessBadge>();
// Add INT_IsNavEmployee__c
if (person.INT_IsNavEmployee__c) {
accessBadgeList.add(new AccessBadge('isNavEmployee', 'Skjermet person (Nav Ansatt)'));
}

// Add INT_Confidential__c
// prettier-ignore
if (true == person.INT_Confidential__c.equalsIgnoreCase('FORTROLIG')) {
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - fortrolig'));
} else if (true == person.INT_Confidential__c.equalsIgnoreCase('STRENGT_FORTROLIG')) {
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - strengt fortrolig'));
} else if (
true == person.INT_Confidential__c.equalsIgnoreCase('STRENGT_FORTROLIG_UTLAND')
) {
accessBadgeList.add(new AccessBadge('isConfidential', 'Skjermet adresse - strengt fortrolig'));
}
return accessBadgeList;
}

/**
* @description Dynamically find the person ID
* *Example
* - field = 'Account.CRM_Person__c';
* - objString = 'Case';
* - recordId = '5001X000007xMSuQAM';
* - relation = 'Id';
*/
private static Id getPersonId(String field, String parentObject, String parentRecordId) {
Id personId = null;
String queryString = 'SELECT ' + field + ' FROM ' + parentObject + ' WHERE Id = :parentRecordId LIMIT 1';
List<SObject> objList = Database.query(String.escapeSingleQuotes(queryString));

if (false == objList.isEmpty()) {
personId = (Id) getFieldValue(objList[0], field);
}

return personId;
}

/**
* @description recursive method for collecting the value of a field on a sObject
*/
private static Object getFieldValue(SObject obj, String fieldName) {
if (obj == null) {
return null;
}
List<String> fieldNameList = fieldName.split('\\.');

if (1 < fieldNameList.size()) {
return getFieldValue(obj.getSObject(fieldNameList.remove(0)), String.join(fieldNameList, '.'));
}

return obj.get(fieldNameList[0]);
}

private static Person__c getPerson(Id personId) {
List<Person__c> personList = [
SELECT Id, INT_Confidential__c, INT_IsNavEmployee__c
FROM Person__c
WHERE Id = :personId
];

return personList.isEmpty() ? null : personList[0];
}

public class AccessBadge {
@AuraEnabled
public String name;
@AuraEnabled
public String label;

public AccessBadge(String name, String label) {
this.name = name;
this.label = label;
}
}
}
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>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
@IsTest
private inherited sharing class HOT_PersonAccessBadgesControllerTest {
@IsTest
static void getPersonAccessBadgesNavEmployee() {
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord(
new Person__c(
INT_ActorId__c = '100003000120',
INT_Confidential__c = 'UGRADERT',
INT_FirstName__c = 'Harry',
INT_IsNavEmployee__c = true,
INT_LastName__c = 'Potter'
),
true
);

p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id];

List<HOT_PersonAccessBadgesController.AccessBadge> result;

Test.startTest();
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c);
Test.stopTest();

System.assertEquals(1, result.size(), 'Expected one result');
}

@IsTest
static void getPersonAccessBadgesFORTROLIG() {
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord(
new Person__c(
INT_ActorId__c = '100003000120',
INT_Confidential__c = 'FORTROLIG',
INT_FirstName__c = 'Harry',
INT_IsNavEmployee__c = false,
INT_LastName__c = 'Potter'
),
true
);

p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id];

List<HOT_PersonAccessBadgesController.AccessBadge> result;

Test.startTest();
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c);
Test.stopTest();

System.assertEquals(1, result.size(), 'Expected one result');
System.assertEquals('Skjermet adresse - fortrolig', result[0].label, 'Expected Skjermet adresse - fortrolig');
}

@IsTest
static void getPersonAccessBadgesSTRENGT_FORTROLIG() {
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord(
new Person__c(
INT_ActorId__c = '100003000120',
INT_Confidential__c = 'STRENGT_FORTROLIG',
INT_FirstName__c = 'Harry',
INT_IsNavEmployee__c = false,
INT_LastName__c = 'Potter'
),
true
);

p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id];

List<HOT_PersonAccessBadgesController.AccessBadge> result;

Test.startTest();
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c);
Test.stopTest();

System.assertEquals(1, result.size(), 'Expected one result');
System.assertEquals(
'Skjermet adresse - strengt fortrolig',
result[0].label,
'Expected Skjermet adresse - strengt fortrolig'
);
}

@IsTest
static void getPersonAccessBadgesSTRENGT_FORTROLIG_UTLAND() {
Person__c p = (Person__c) HOT_ST_TestDataFactory.createRecord(
new Person__c(
INT_ActorId__c = '100003000120',
INT_Confidential__c = 'STRENGT_FORTROLIG_UTLAND',
INT_FirstName__c = 'Harry',
INT_IsNavEmployee__c = false,
INT_LastName__c = 'Potter'
),
true
);

p = [SELECT Id, CRM_Account__c FROM Person__c WHERE Id = :p.Id];

List<HOT_PersonAccessBadgesController.AccessBadge> result;

Test.startTest();
result = HOT_PersonAccessBadgesController.getPersonAccessBadges('CRM_Person__c', 'Account', p.CRM_Account__c);
Test.stopTest();

System.assertEquals(1, result.size(), 'Expected one result');
System.assertEquals(
'Skjermet adresse - strengt fortrolig',
result[0].label,
'Expected Skjermet adresse - strengt fortrolig'
);
}
}
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>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Original file line number Diff line number Diff line change
@@ -1,64 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<FlexiPage xmlns="http://soap.sforce.com/2006/04/metadata">
<flexiPageRegions>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>readonly</value>
</fieldInstanceProperties>
<fieldItem>Record.AccountId</fieldItem>
<identifier>RecordAccountIdField</identifier>
</fieldInstance>
</itemInstances>
<name>Facet-9addd4a4-f259-4ff0-9eeb-223ecc4b1373</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<fieldInstance>
<fieldItem>Record.Account.CRM_Person__r.CRM_FullName__c</fieldItem>
<identifier>RecordAccountCRM_Person_rCRM_FullName_cField2</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldItem>Record.Account.CRM_Person__r.Name</fieldItem>
<identifier>RecordAccountCRM_Person_rNameField2</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldItem>Record.Account.CRM_Person__r.INT_KrrMobilePhone__c</fieldItem>
<identifier>RecordAccountCRM_Person_rINT_KrrMobilePhone_cField2</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldItem>Record.Account.CRM_Person__r.INT_Citizenships__c</fieldItem>
<identifier>RecordAccountCRM_Person_rINT_Citizenships_cField2</identifier>
</fieldInstance>
</itemInstances>
<name>Facet-8b7f4184-4878-4340-81a6-7628f7769a46</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>numVisibleActions</name>
<value>3</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>primaryField</name>
<value>Facet-9addd4a4-f259-4ff0-9eeb-223ecc4b1373</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>secondaryFields</name>
<value>Facet-8b7f4184-4878-4340-81a6-7628f7769a46</value>
<name>relationshipField</name>
<value>Account.CRM_Person__c</value>
</componentInstanceProperties>
<componentName>record_flexipage:dynamicHighlights</componentName>
<identifier>record_flexipage_dynamicHighlights</identifier>
<componentName>hot_personHighlightPanel</componentName>
<identifier>c_hot_personHighlightPanel</identifier>
</componentInstance>
</itemInstances>
<name>header</name>
Expand Down Expand Up @@ -625,16 +575,6 @@
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>relationshipField</name>
<value>Account.CRM_Person__c</value>
</componentInstanceProperties>
<componentName>hot_personBadgePanel</componentName>
<identifier>c_hot_personBadgePanel</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<FlexiPage xmlns="http://soap.sforce.com/2006/04/metadata">
<flexiPageRegions>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>required</value>
</fieldInstanceProperties>
<fieldItem>Record.Name</fieldItem>
<identifier>RecordNameField</identifier>
</fieldInstance>
</itemInstances>
<name>Facet-0c4e474f-a696-4095-a67a-6f86c697fdce</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>required</value>
</fieldInstanceProperties>
<fieldItem>Record.Name</fieldItem>
<identifier>RecordNameField2</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldItem>Record.CRM_Person__r.INT_KrrMobilePhone__c</fieldItem>
<identifier>RecordCRM_Person_rINT_KrrMobilePhone_cField2</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldInstanceProperties>
<name>uiBehavior</name>
<value>none</value>
</fieldInstanceProperties>
<fieldItem>Record.INT_PersonIdent__c</fieldItem>
<identifier>RecordINT_PersonIdent_cField</identifier>
</fieldInstance>
</itemInstances>
<itemInstances>
<fieldInstance>
<fieldItem>Record.CRM_Person__r.INT_Citizenships__c</fieldItem>
<identifier>RecordCRM_Person_rINT_Citizenships_cField2</identifier>
</fieldInstance>
</itemInstances>
<name>Facet-4d871b21-856c-4623-94ac-49b03439058d</name>
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>numVisibleActions</name>
<value>3</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>primaryField</name>
<value>Facet-0c4e474f-a696-4095-a67a-6f86c697fdce</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>secondaryFields</name>
<value>Facet-4d871b21-856c-4623-94ac-49b03439058d</value>
<name>relationshipField</name>
<value>CRM_Person__c</value>
</componentInstanceProperties>
<componentName>record_flexipage:dynamicHighlights</componentName>
<identifier>record_flexipage_dynamicHighlights</identifier>
<componentName>hot_personHighlightPanel</componentName>
<identifier>c_hot_personHighlightPanel</identifier>
</componentInstance>
</itemInstances>
<mode>Replace</mode>
Expand Down Expand Up @@ -210,16 +152,6 @@
<type>Facet</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>relationshipField</name>
<value>CRM_Person__c</value>
</componentInstanceProperties>
<componentName>hot_personBadgePanel</componentName>
<identifier>c_hot_personBadgePanel</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
Expand Down
Loading

0 comments on commit afddcff

Please sign in to comment.