diff --git a/force-app/components/accountBadges/classes/AccountBadgesController.cls b/force-app/components/accountBadges/classes/AccountBadgesController.cls new file mode 100644 index 00000000..3b38f4e4 --- /dev/null +++ b/force-app/components/accountBadges/classes/AccountBadgesController.cls @@ -0,0 +1,46 @@ +public with sharing class AccountBadgesController { + private static final LoggerUtility logger = new LoggerUtility(); + @AuraEnabled(cacheable=true) + public static List createBadges(Id accountId) { + List accountBadges = new List(); + try { + Account account = [SELECT TAG_Partner_Status__c FROM Account WHERE Id = :accountId]; + addParterStatusBadge(accountBadges, account); + } catch (Exception e) { + logger.logMessage( + LoggerUtility.LogLevel.Error, + '', + accountId, + e.getMessage(), + e.getStackTraceString(), + null, + CRM_ApplicationDomain.Domain.POAB + ); + logger.publish(); + return new List(); + } + return accountBadges; + } + + private static void addParterStatusBadge(List accountBadges, Account account) { + if (AccessControlValidator.fieldIsAccessible('Account', 'TAG_Partner_Status__c')) { + if ( + account.TAG_Partner_Status__c == 'Strategisk Partner' || + account.TAG_Partner_Status__c == 'Samarbeidspartner' + ) { + accountBadges.add(new Badge(account.TAG_Partner_Status__c, 'Partner status')); + } + } + } + + public class Badge { + public Badge(String label, String helpText) { + this.label = label; + this.helpText = helpText; + } + @AuraEnabled + public String label; + @AuraEnabled + public String helpText; + } +} diff --git a/force-app/components/accountBadges/classes/AccountBadgesController.cls-meta.xml b/force-app/components/accountBadges/classes/AccountBadgesController.cls-meta.xml new file mode 100644 index 00000000..998805a8 --- /dev/null +++ b/force-app/components/accountBadges/classes/AccountBadgesController.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls b/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls new file mode 100644 index 00000000..259cbad4 --- /dev/null +++ b/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls @@ -0,0 +1,159 @@ +@isTest +private class AccountBadgesControllerTest { + @testSetup + private static void setup() { + Profile profile = [ + SELECT Id + FROM Profile + WHERE Name = 'System Administrator' + LIMIT 1 + ]; + + User thisUser = new User( + LastName = 'user', + Email = 'user@nav.apextest', + Username = 'user@nav.apextest', + Alias = 'usr', + LanguageLocaleKey = 'no', + LocaleSidKey = 'no_NO', + TimeZoneSidKey = 'Europe/Paris', + EmailEncodingKey = 'UTF-8', + ProfileId = profile.Id + ); + insert thisUser; + + System.runAs(thisUser) { + List testAccounts = new List(); + testAccounts.add( + new Account( + Name = 'TestAccount0', + INT_OrganizationNumber__c = '9000000001', + TAG_Partner_Status__c = 'Strategisk Partner' + ) + ); + testAccounts.add( + new Account( + Name = 'TestAccount1', + INT_OrganizationNumber__c = '9000000002', + TAG_Partner_Status__c = null + ) + ); + insert testAccounts; + + TAG_TestDataFactory.createUserWithPermset( + 'ARBEIDSGIVER USER', + new List{ + 'Arbeidsgiver_arenaActivity', + 'Arbeidsgiver_base', + 'Arbeidsgiver_contract', + 'Arbeidsgiver_opportunity', + 'Arbeidsgiver_IA' + } + ); + User user1 = [SELECT id FROM User WHERE LastName = 'Arbeidsgiver USER' LIMIT 1]; + User user2 = TAG_TestDataFactory.createStandardUser('USER WITHOUT PERMISSIONS'); + //Create account share records + insert new List{ + (new AccountShare( + AccountId = testAccounts[0].Id, + UserOrGroupId = user1.id, + AccountAccessLevel = 'Read', + OpportunityAccessLevel = 'None', + CaseAccessLevel = 'None', + RowCause = Schema.AccountShare.RowCause.Manual + )), + (new AccountShare( + AccountId = testAccounts[1].Id, + UserOrGroupId = user1.id, + AccountAccessLevel = 'Read', + OpportunityAccessLevel = 'None', + CaseAccessLevel = 'None', + RowCause = Schema.AccountShare.RowCause.Manual + )), + (new AccountShare( + AccountId = testAccounts[0].Id, + UserOrGroupId = user2.id, + AccountAccessLevel = 'Read', + OpportunityAccessLevel = 'None', + CaseAccessLevel = 'None', + RowCause = Schema.AccountShare.RowCause.Manual + )), + (new AccountShare( + AccountId = testAccounts[1].Id, + UserOrGroupId = user2.id, + AccountAccessLevel = 'Read', + OpportunityAccessLevel = 'None', + CaseAccessLevel = 'None', + RowCause = Schema.AccountShare.RowCause.Manual + )) + }; + } + + } + + @isTest + static void badges_Should_Be_Created_When_Account_Match_Criteria() { + Account testAccount = [ + SELECT Id, TAG_Partner_Status__c + FROM Account + WHERE TAG_Partner_Status__c = 'Strategisk Partner' + LIMIT 1 + ]; + User user = [SELECT id FROM User WHERE LastName = 'Arbeidsgiver USER' LIMIT 1]; + List accountBadges; + System.runAs(user) { + Test.startTest(); + accountBadges = AccountBadgesController.createBadges(testAccount.Id); + Test.stopTest(); + } + Assert.isNotNull(accountBadges, 'Badges should be returned'); + Assert.isTrue(accountBadges.size() == 1, 'Badges should be returned'); + Assert.areEqual( + testAccount.TAG_Partner_Status__c, + accountBadges[0].label, + 'Label should be same as account partner status' + ); + } + + @isTest + static void no_Badges_Should_Be_Created_When_Account_Match_No_Criteria() { + Account testAccount = [ + SELECT Id, TAG_Partner_Status__c + FROM Account + WHERE TAG_Partner_Status__c = NULL + LIMIT 1 + ]; + User user = [SELECT id FROM User WHERE LastName = 'Arbeidsgiver USER' LIMIT 1]; + List accountBadges; + System.runAs(user) { + Test.startTest(); + accountBadges = AccountBadgesController.createBadges(testAccount.Id); + Test.stopTest(); + } + Assert.isNotNull(accountBadges, 'Badges should be returned'); + Assert.isTrue(accountBadges.size() == 0, 'Badges should not have any items'); + } + + @isTest + static void badge_Should_Not_Be_Created_For_Non_Accessible_Fields() { + Account testAccount = [ + SELECT Id, TAG_Partner_Status__c + FROM Account + WHERE TAG_Partner_Status__c = 'Strategisk Partner' + LIMIT 1 + ]; + User user = [SELECT id FROM User WHERE LastName = 'USER WITHOUT PERMISSIONS' LIMIT 1]; + List accountBadges; + System.runAs(user) { + Assert.isTrue(AccessControlValidator.sObjectIsAccessible('Account')); + Assert.isFalse(AccessControlValidator.fieldIsAccessible('Account', 'TAG_Partner_Status__c')); + + Test.startTest(); + accountBadges = AccountBadgesController.createBadges(testAccount.Id); + Test.stopTest(); + } + + Assert.isNotNull(accountBadges, 'Badges should be returned'); + Assert.isTrue(accountBadges.size() == 0, 'Badges should not have any items'); + } +} diff --git a/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls-meta.xml b/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls-meta.xml new file mode 100644 index 00000000..998805a8 --- /dev/null +++ b/force-app/components/accountBadges/classes/AccountBadgesControllerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 62.0 + Active + diff --git a/force-app/components/accountBadges/lwc/accountBadges/accountBadges.css b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.css new file mode 100644 index 00000000..e55cbe9d --- /dev/null +++ b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.css @@ -0,0 +1,56 @@ +/* Set background for the container */ +.account_badges_container { + display: inline-flex; + flex-wrap: wrap; + background-color: white; +} + +.badge-item { + background-color: var(--slds-c-badge-color-background, transparent); +} +.account_badge { + color: var(--slds-c-badge-text-color, #23262a); + border-radius: var(--slds-c-badge-radius-border, 15rem); + background-color: var(--slds-c-badge-color-background, #fff); + border: 1px solid #7f8900; +} + +/* +text: Gray 900 #23262A + +border: Limegreen 400 #C1CB33 +surface: Limegreen 100 #F9FCCC +.style1 { + color: var(--slds-c-badge-text-color, #23262a); + border-radius: var(--slds-c-badge-radius-border, 15rem); + background-color: var(--slds-c-badge-color-background, #f9fccc); + border: 1px solid #c1cb33; +} + +border: Deepblue 500 #005B82 +surface: Deepblue 100 #CCE2F0 +.style2 { + color: var(--slds-c-badge-text-color, #23262a); + border-radius: var(--slds-c-badge-radius-border, 15rem); + background-color: var(--slds-c-badge-color-background, #cce2f0); + border: 1px solid #005b82; +} + +border: Deepblue 500 #003453 +.style3 { + color: var(--slds-c-badge-text-color, #23262a); + border-radius: var(--slds-c-badge-radius-border, 15rem); + background-color: var(--slds-c-badge-color-background, #fff); + border: 1px solid #003453; +} + +border: Limegreen 700 #7F8900 +.style4 { + color: var(--slds-c-badge-text-color, #23262a); + border-radius: var(--slds-c-badge-radius-border, 15rem); + background-color: var(--slds-c-badge-color-background, #fff); + border: 1px solid #7f8900; +} + + + */ diff --git a/force-app/components/accountBadges/lwc/accountBadges/accountBadges.html b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.html new file mode 100644 index 00000000..c8a86f7e --- /dev/null +++ b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.html @@ -0,0 +1,16 @@ + diff --git a/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js new file mode 100644 index 00000000..66b71e19 --- /dev/null +++ b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js @@ -0,0 +1,27 @@ +import { LightningElement, api, wire } from 'lwc'; +import createBadges from '@salesforce/apex/AccountBadgesController.createBadges'; + +export default class AccountBadges extends LightningElement { + @api recordId; // Automatically populated in record context + badges = []; + renderBadges = false; // Should be true if badges are returned, false if not + + // Wire service to fetch badges + @wire(createBadges, { accountId: '$recordId' }) + wiredBadges({ error, data }) { + if (!this.recordId) { + console.warn('recordId is null or undefined. Skipping Apex call.'); + this.renderBadges = false; // No badges to render + return; + } + if (data) { + this.badges = data; + this.renderBadges = this.badges.length > 0; // Check if badges array is empty + console.log('Badges:', JSON.stringify(this.badges)); + } else if (error) { + this.badges = []; + this.renderBadges = false; // No badges to render + console.error('Error fetching badges:', error); + } + } +} diff --git a/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js-meta.xml b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js-meta.xml new file mode 100644 index 00000000..8e18a0cc --- /dev/null +++ b/force-app/components/accountBadges/lwc/accountBadges/accountBadges.js-meta.xml @@ -0,0 +1,16 @@ + + + 62.0 + true + Account Badges + + lightning__RecordPage + + + + + Account + + + + \ No newline at end of file