Skip to content
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

TOLK-2142 : Som tolk ønsker jeg å kunne laste opp fil til tolkebruker #2031

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d6dbf48
.
olsenrasmus Jul 11, 2024
f28d197
Forbedringer
olsenrasmus Jul 12, 2024
1190fb4
Merge branch 'master' into TOLK-2142
olsenrasmus Jul 17, 2024
2417c9d
Merge branch 'master' into TOLK-2142
olsenrasmus Aug 22, 2024
61bda1e
.
olsenrasmus Aug 22, 2024
4e220ea
ps
olsenrasmus Aug 22, 2024
2643593
.
olsenrasmus Aug 23, 2024
89f9b33
Merge branch 'master' into TOLK-2142
olsenrasmus Aug 26, 2024
ec9db41
Merge branch 'master' into TOLK-2142
olsenrasmus Aug 26, 2024
3e17942
merge main into TOLK 2142
AndreMarthinsen Oct 18, 2024
101cd23
legge til endringer i ny modal
AndreMarthinsen Oct 21, 2024
5bc5614
delvis refactor av modal
MathiBK Oct 21, 2024
33d1888
fikse wage claim modal bug
MathiBK Oct 22, 2024
6565ec8
midlertidige endrigner
MathiBK Oct 29, 2024
fe9ee88
legge til lightning modal funksjonalitet
MathiBK Oct 31, 2024
5e8c39c
legge til modal for wanted seervice appointment
MathiBK Nov 4, 2024
713ab56
Update settings.json
MathiBK Nov 4, 2024
b8361ef
fikse logs og unødvendig kode
MathiBK Nov 4, 2024
5923416
fjerne mer unødvendig kode
MathiBK Nov 4, 2024
ce84cb4
fjerne mer unødvendig kode
MathiBK Nov 4, 2024
7c73331
Merge pull request #2122 from navikt/TOLK-2142-bytte-til-lightning-modal
MathiBK Nov 5, 2024
487a935
Legge til klasse og flow for filopplasting mellom tolk og bruker + fi…
MathiBK Nov 21, 2024
b34421a
slette test som ikke fungerer
MathiBK Nov 27, 2024
f0d8976
legge til deletion av filer
MathiBK Nov 27, 2024
41bac2b
fikse feil med visning av opplastede filer
MathiBK Nov 28, 2024
f106253
filse slette policy feil
MathiBK Nov 28, 2024
12d7725
fikse ledige oppdrag modal feil
MathiBK Nov 28, 2024
75b6a2d
Merge branch 'master' into TOLK-2142
MathiBK Nov 28, 2024
d5a789b
fjerne litt comments
MathiBK Nov 28, 2024
bfb4576
fikse modal css og fjerne case feed perm
MathiBK Nov 28, 2024
2a3ab0d
Fikse feil hvor tolk ikke kunne se hva bruker hadde lastet opp
MathiBK Dec 5, 2024
d9c216f
Fjerne unødvendig permset
MathiBK Dec 6, 2024
21b7b8a
Oppdatere css
MathiBK Dec 6, 2024
838b33e
Merge branch 'master' into TOLK-2142
MathiBK Dec 6, 2024
b3e1227
legge til test for HOT_RecordFilesControllerWithSharing
MathiBK Dec 11, 2024
18f50fd
Merge branch 'master' into TOLK-2142
MathiBK Dec 11, 2024
ad2aa5c
Merge branch 'master' into TOLK-2142
MathiBK Jan 6, 2025
25c7699
Merge branch 'master' into TOLK-2142
MathiBK Jan 10, 2025
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"**/.sfdx": true,
"**/.vscode": true,
"**/.idea": true
}
},
"salesforce.einsteinForDevelopers.enableAutocompletions": false
}
55 changes: 55 additions & 0 deletions force-app/main/default/classes/HOT_HotFilesController.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
public with sharing class HOT_HotFilesController {
@AuraEnabled
public static Id getHotFileRecordId(Id serviceAppointmentId) {
List<HOT_File__c> hotFilesList = [
SELECT Id
FROM HOT_File__c
WHERE Service_Appointment__c = :serviceAppointmentId
LIMIT 1
];
System.debug('hotFilesList >>' + hotFilesList);
if (!hotFilesList.isEmpty()) {
return hotFilesList[0].Id;
}
return null;
}

@AuraEnabled
public static Id createHotFileRecord(Id serviceAppointmentId) {
Id existingId = getHotFileRecordId(serviceAppointmentId);
if (existingId != null) {
// Record already exists; return existing Id
return existingId;
}
ServiceAppointment serviceAppointment = [
SELECT Id, HOT_Account__c
FROM ServiceAppointment
WHERE Id = :serviceAppointmentId
LIMIT 1
];
// Create a new HOT_File__c record
HOT_File__c hotFilesRecord = new HOT_File__c(
Service_Appointment__c = serviceAppointmentId,
Account__c = serviceAppointment.HOT_Account__c
);
HOT_DatabaseOperations.insertRecords(hotFilesRecord);
return hotFilesRecord.Id;
}

@AuraEnabled
public static void shareWithUser(Id hotFileId, List<Id> contentDocumentIds) {
HOT_File__c hotFile = [SELECT Id, Account__c FROM HOT_File__c WHERE Id = :hotFileId LIMIT 1];

if (hotFile != null && hotFile.Account__c != null) {
List<ContentDocumentLink> cdls = new List<ContentDocumentLink>();
for (Id contentDocumentId : contentDocumentIds) {
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = contentDocumentId;
cdl.LinkedEntityId = hotFile.Account__c;
cdl.ShareType = 'V';
cdls.add(cdl);
}
HOT_DatabaseOperations.insertRecords(cdls);
}
}
}
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>
162 changes: 162 additions & 0 deletions force-app/main/default/classes/HOT_HotFilesControllerTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
@isTest
public class HOT_HotFilesControllerTest {
@testSetup
static void setupTestData() {
Person__c person = HOT_TestDataFactory.createPerson();
person.Name = '12015678999';
insert person;

Account personAccount = HOT_TestDataFactory.createAccount(true);
personAccount.INT_PersonIdent__c = '12015678999';
personAccount.CRM_Person__c = person.Id;
insert personAccount;

WorkType workType = HOT_TestDataFactory.createWorkType();
insert workType;

HOT_Request__c request = HOT_TestDataFactory.createRequest('TEST', workType);
insert request;

WorkOrder wo = HOT_TestDataFactory.createWorkOrder(request, workType);
insert wo;

WorkOrderLineItem woli = HOT_TestDataFactory.createWorkOrderLineItem(wo, workType);
insert woli;

ServiceAppointment sa = HOT_TestDataFactory.createServiceAppointment(woli);
sa.HOT_Account__c = personAccount.Id;
insert sa;

HOT_File__c hotFile = new HOT_File__c(Service_Appointment__c = sa.Id, Account__c = personAccount.Id);
insert hotFile;

ContentVersion contentVersion = new ContentVersion(
Title = 'Test File',
PathOnClient = 'TestFile.txt',
VersionData = Blob.valueOf('Test content')
);
insert contentVersion;
}

@isTest
static void testGetHotFileRecordId() {
Person__c person = HOT_TestDataFactory.createPerson();
person.Name = '12015678999';
insert person;

Account personAccount = HOT_TestDataFactory.createAccount(true);
personAccount.INT_PersonIdent__c = '12015678999';
personAccount.CRM_Person__c = person.Id;
insert personAccount;

WorkType workType = HOT_TestDataFactory.createWorkType();
insert workType;

HOT_Request__c request = HOT_TestDataFactory.createRequest('TEST', workType);
insert request;

WorkOrder wo = HOT_TestDataFactory.createWorkOrder(request, workType);
insert wo;

WorkOrderLineItem woli = HOT_TestDataFactory.createWorkOrderLineItem(wo, workType);
insert woli;

ServiceAppointment sa = HOT_TestDataFactory.createServiceAppointment(woli);
sa.HOT_Account__c = personAccount.Id;
insert sa;

HOT_File__c hotFile = new HOT_File__c(Service_Appointment__c = sa.Id, Account__c = personAccount.Id);
insert hotFile;

Test.startTest();
Id hotFileId = HOT_HotFilesController.getHotFileRecordId(sa.Id);
Test.stopTest();

System.assertNotEquals(null, hotFileId, 'HotFileId should not be null');
}

@isTest
static void testCreateHotFileRecord_New() {
Person__c newPerson = HOT_TestDataFactory.createPerson();
newPerson.Name = '13015678999';
insert newPerson;

Account newPersonAccount = HOT_TestDataFactory.createAccount(true);
newPersonAccount.INT_PersonIdent__c = '13015678999';
newPersonAccount.CRM_Person__c = newPerson.Id;
insert newPersonAccount;

WorkType workType = HOT_TestDataFactory.createWorkType();
insert workType;

HOT_Request__c request = HOT_TestDataFactory.createRequest('TEST_NEW', workType);
insert request;

WorkOrder wo = HOT_TestDataFactory.createWorkOrder(request, workType);
insert wo;

WorkOrderLineItem woli = HOT_TestDataFactory.createWorkOrderLineItem(wo, workType);
insert woli;

ServiceAppointment sa = HOT_TestDataFactory.createServiceAppointment(woli);
sa.HOT_Account__c = newPersonAccount.Id;
insert sa;

Test.startTest();
Id hotFileId = HOT_HotFilesController.createHotFileRecord(sa.Id);
Test.stopTest();

HOT_File__c hotFile = [SELECT Id, Service_Appointment__c, Account__c FROM HOT_File__c WHERE Id = :hotFileId];
System.assertNotEquals(null, hotFile, 'HotFile record should not be null');
System.assertEquals(sa.Id, hotFile.Service_Appointment__c, 'Service Appointment IDs should match');
System.assertEquals(newPersonAccount.Id, hotFile.Account__c, 'Account IDs should match');
}

@isTest
static void testCreateHotFileRecord_Existing() {
ServiceAppointment sa = [SELECT Id FROM ServiceAppointment LIMIT 1];

Test.startTest();
Id hotFileId1 = HOT_HotFilesController.createHotFileRecord(sa.Id);
Id hotFileId2 = HOT_HotFilesController.createHotFileRecord(sa.Id);
Test.stopTest();

System.assertEquals(hotFileId1, hotFileId2, 'HotFile IDs should be the same for existing records');
}

@isTest
static void testShareWithUser() {
HOT_File__c hotFile = [SELECT Id, Account__c FROM HOT_File__c LIMIT 1];
ContentVersion contentVersion = [SELECT Id, ContentDocumentId FROM ContentVersion LIMIT 1];

List<Id> contentDocumentIds = new List<Id>{ contentVersion.ContentDocumentId };

Test.startTest();
HOT_HotFilesController.shareWithUser(hotFile.Id, contentDocumentIds);
Test.stopTest();

// Verify that a ContentDocumentLink has been created
List<ContentDocumentLink> cdls = [
SELECT Id, ContentDocumentId, LinkedEntityId, ShareType
FROM ContentDocumentLink
WHERE LinkedEntityId = :hotFile.Account__c AND ContentDocumentId = :contentVersion.ContentDocumentId
];

System.assertNotEquals(0, cdls.size(), 'ContentDocumentLink should be created');
System.assertEquals('V', cdls[0].ShareType, 'ShareType should be View (V)');
}

@isTest
static void testShareWithUser_NullAccount() {
HOT_File__c hotFile = new HOT_File__c();
insert hotFile;

List<Id> contentDocumentIds = new List<Id>();

Test.startTest();
HOT_HotFilesController.shareWithUser(hotFile.Id, contentDocumentIds);
Test.stopTest();

// No exception should be thrown, and no action taken
}
}
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,72 @@
public with sharing class HOT_RecordFilesControllerWithSharing {
@TestVisible
private static Id getWorkorderFromSa(String saId) {
ServiceAppointment[] sa = [
SELECT Id, HOT_WorkOrderLineItem__r.WorkOrderId
FROM ServiceAppointment
WHERE Id = :saId
];
if (!sa.isEmpty()) {
return sa[0].HOT_WorkOrderLineItem__r.WorkOrderId;
}
return null;
}
@AuraEnabled(cacheable=true)
public static List<ContentDocument> getContentDocuments(String recordId, Boolean isGetAll) {
if (recordId == null) {
return new List<ContentDocument>{};
}
String serviceAppointmentPrefix = '08p';
if (recordId != null && String.valueOf(recordId).startsWith(serviceAppointmentPrefix)) {
recordId = getWorkorderFromSa(recordId);
}

Set<Id> requestId = new Set<Id>();
List<WorkOrder> workOrder = [SELECT Id, HOT_Request__c FROM WorkOrder WHERE Id = :recordId];
for (WorkOrder wo : workOrder) {
requestId.add(wo.HOT_Request__c);
}

List<ServiceAppointment> serviceAppointments = [
SELECT Id
FROM ServiceAppointment
WHERE HOT_WorkOrderLineItem__r.WorkOrderId = :recordId
];
Set<Id> saIds = new Set<Id>();
for (ServiceAppointment sa : serviceAppointments) {
saIds.add(sa.Id);
}

List<HOT_File__c> hotFiles = [SELECT Id FROM HOT_File__c WHERE Service_Appointment__c = :saIds];
Set<Id> hotFileIds = new Set<Id>();
for (HOT_File__c hf : hotFiles) {
hotFileIds.add(hf.Id);
}

List<ContentDocumentLink> contentDocumentLinks = [
SELECT ContentDocumentId
FROM ContentDocumentLink
WHERE
LinkedEntityId = :recordId
OR LinkedEntityId IN :saIds
OR LinkedEntityId IN :requestId
OR LinkedEntityId IN :hotFileIds
];

List<Id> contentDocumentIds = new List<Id>();
for (ContentDocumentLink contentDocumentLink : contentDocumentLinks) {
contentDocumentIds.add(contentDocumentLink.ContentDocumentId);
}

if (!isGetAll) {
contentDocumentIds = RecordFilesControllerWithSharing.getOnlyMyContentDocuments(contentDocumentIds);
}

List<ContentDocument> contentDocuments = [
SELECT Id, FileType, CreatedDate, Title, LatestPublishedVersionId
FROM ContentDocument
WHERE Id IN :contentDocumentIds AND ContentAssetId = NULL
];
return contentDocuments;
}
}
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>56.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading
Loading