From 9d09a6ea73687c3dd6590e401f65e46a5953ac03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Thu, 11 Sep 2025 19:15:29 +0200 Subject: [PATCH 01/13] Fixing broken validation of names and email. --- .../BackendConfigurationAssignmentWorkerServiceHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 9e19d22e..e49c7812 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -511,7 +511,7 @@ public static async Task> CreateDeviceUser(DeviceUserMo var siteName = deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName; var sdkDbContext = core.DbContextHelper.GetDbContext(); - var site = await sdkDbContext.Sites.SingleOrDefaultAsync(x => x.Name == deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName && x.WorkflowState != Constants.WorkflowStates.Removed); + var site = await sdkDbContext.Sites.AsNoTracking().SingleOrDefaultAsync(x => x.Name == deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName && x.WorkflowState != Constants.WorkflowStates.Removed); if (site != null) { @@ -525,7 +525,7 @@ public static async Task> CreateDeviceUser(DeviceUserMo var worker = await sdkDbContext.Workers.SingleAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); - if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid)) + if (sdkDbContext.Workers.AsNoTracking().Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid && x.WorkflowState != Constants.WorkflowStates.Removed)) { // this email is already in use return new OperationDataResult(false, "EmailIsAlreadyInUse"); From 3b5ae7c8b8fafea7645f1fdd53a54dccf8b97df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Fri, 12 Sep 2025 06:37:32 +0200 Subject: [PATCH 02/13] Code cleanup, so we use the principal of fail fast. --- ...kendConfigurationAssignmentWorkerServiceHelper.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index e49c7812..822d85fd 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -280,13 +280,12 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic var sdkDbContext = core.DbContextHelper.GetDbContext(); var language = sdkDbContext.Languages.Single(x => x.LanguageCode == deviceUserModel.LanguageCode); var siteDto = await core.SiteRead(deviceUserModel.SiteMicrotingUid).ConfigureAwait(false); - if (siteDto.WorkerUid != null) + if (siteDto.WorkerUid == null) return new OperationResult(false, "DeviceUserNotFound"); { // var workerDto = await core.Advanced_WorkerRead((int)siteDto.WorkerUid); var worker = await sdkDbContext.Workers.SingleOrDefaultAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); - if (worker != null) + if (worker == null) return new OperationResult(false, "DeviceUserCouldNotBeObtained"); { - if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid)) { // this email is already in use @@ -479,21 +478,14 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti } } } - // { - // Site site = await db.Sites.SingleAsync(x => x.MicrotingUid == deviceUserModel.Id); - // site.LanguageId = language.Id; - // await site.Update(db); - // } return isUpdated ? new OperationResult(true, "DeviceUserUpdatedSuccessfully") : new OperationResult(false, "DeviceUserParamCouldNotBeUpdated"); } - return new OperationResult(false, "DeviceUserCouldNotBeObtained"); } - return new OperationResult(false, "DeviceUserNotFound"); } catch (Exception ex) { From e08982c08984d3bc280d5df90e49076db60ec3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Fri, 12 Sep 2025 06:49:50 +0200 Subject: [PATCH 03/13] More code cleanup. --- ...figurationAssignmentWorkerServiceHelper.cs | 76 ++----------------- 1 file changed, 5 insertions(+), 71 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 822d85fd..485e98b8 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -374,85 +374,19 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti foreach (var assignmentForDelete in assignmentForDeletes) { - await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false); - if (assignmentForDelete.CaseMicrotingUid != null) - { - await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false); - } - } - var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false); - - foreach (var planRegistration in planRegistrations) - { - try - { - if (planRegistration.StatusCaseId != 0) - { - await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false); - } - } - catch (Exception e) - { - Console.WriteLine(e); - //throw; - } + assignmentForDelete.Resigned = true; + assignmentForDelete.ResignedAtDate = DateTime.UtcNow; + await assignmentForDelete.Update(timePlanningDbContext).ConfigureAwait(false); } } else { if (deviceUserModel.TimeRegistrationEnabled == true) { - var registrationDevices = await timePlanningDbContext.RegistrationDevices - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - - if (registrationDevices.Any()) - { - var assignmentForDeletes = await timePlanningDbContext.AssignedSites.Where(x => - x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - - foreach (var assignmentForDelete in assignmentForDeletes) - { - //await assignmentForDelete.Delete(timePlanningDbContext).ConfigureAwait(false); - if (assignmentForDelete.CaseMicrotingUid != null) - { - await core.CaseDelete((int) assignmentForDelete.CaseMicrotingUid).ConfigureAwait(false); - } - } - - var planRegistrations = await timePlanningDbContext.PlanRegistrations.Where(x => x.SdkSitId == siteDto.SiteId).ToListAsync().ConfigureAwait(false); - - foreach (var planRegistration in planRegistrations) - { - if (planRegistration.StatusCaseId != 0) - { - await core.CaseDelete(planRegistration.StatusCaseId).ConfigureAwait(false); - } - } - - var assignments1 = await timePlanningDbContext.AssignedSites.Where(x => - x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - - if (assignments1.Any()) - { - return new OperationDataResult(true, siteDto.SiteId); - } - - var assignmentSite = new AssignedSite - { - SiteId = siteDto.SiteId, - CreatedByUserId = userId, - UpdatedByUserId = userId - }; - await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false); - await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); - return new OperationDataResult(true, siteDto.SiteId); - } - var assignments = await timePlanningDbContext.AssignedSites.Where(x => x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed).ToListAsync().ConfigureAwait(false); - if (assignments.Any()) + if (assignments.Count != 0) { await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); return new OperationDataResult(true, siteDto.SiteId); @@ -467,7 +401,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti UpdatedByUserId = userId }; await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false); - + await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); return new OperationDataResult(true, siteDto.SiteId); } catch (Exception e) From 3ef50aad8fac700b3ae62ecb8d75831b885d38c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Fri, 12 Sep 2025 10:20:14 +0200 Subject: [PATCH 04/13] Adding changes to handle updating of first and last name of a user in google sheet if that is enabled. --- ...figurationAssignmentWorkerServiceHelper.cs | 5 +-- .../Helpers/GoogleSheetHelper.cs | 34 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 485e98b8..641448ad 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -280,6 +280,7 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic var sdkDbContext = core.DbContextHelper.GetDbContext(); var language = sdkDbContext.Languages.Single(x => x.LanguageCode == deviceUserModel.LanguageCode); var siteDto = await core.SiteRead(deviceUserModel.SiteMicrotingUid).ConfigureAwait(false); + var oldSiteName = siteDto.SiteName; if (siteDto.WorkerUid == null) return new OperationResult(false, "DeviceUserNotFound"); { // var workerDto = await core.Advanced_WorkerRead((int)siteDto.WorkerUid); @@ -388,7 +389,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti if (assignments.Count != 0) { - await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); + await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger, oldSiteName, fullName).ConfigureAwait(false); return new OperationDataResult(true, siteDto.SiteId); } @@ -401,7 +402,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti UpdatedByUserId = userId }; await assignmentSite.Create(timePlanningDbContext).ConfigureAwait(false); - await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger); + await GoogleSheetHelper.PushToGoogleSheet(core, timePlanningDbContext, logger, oldSiteName, fullName).ConfigureAwait(false); return new OperationDataResult(true, siteDto.SiteId); } catch (Exception e) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs index f3e38b79..4cc4a171 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/GoogleSheetHelper.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; @@ -16,7 +17,7 @@ namespace BackendConfiguration.Pn.Infrastructure.Helpers; public class GoogleSheetHelper { - public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext dbContext, ILogger logger) + public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext dbContext, ILogger logger, string? oldSiteName = null, string? newSiteName = null) { var privateKeyId = Environment.GetEnvironmentVariable("PRIVATE_KEY_ID"); var googleSheetId = dbContext.PluginConfigurationValues @@ -85,6 +86,11 @@ public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext db { var timerHeader = $"{siteName} - timer"; var textHeader = $"{siteName} - tekst"; + if (newSiteName == siteName) + { + timerHeader = $"{oldSiteName} - tekst"; + textHeader = $"{oldSiteName} - timer"; + } if (!newHeaders.Contains(timerHeader)) { newHeaders.Add(timerHeader); @@ -117,6 +123,32 @@ public static async Task PushToGoogleSheet(Core core, TimePlanningPnDbContext db logger.LogInformation("Headers updated successfully."); } + // loop through all the existing headers and find the oldSiteName and rename it to newSiteName + if (!string.IsNullOrEmpty(oldSiteName) && !string.IsNullOrEmpty(newSiteName) && newSiteName != oldSiteName) + { + for (int i = 0; i < existingHeaders.Count; i++) + { + if (existingHeaders[i].ToString() == $"{oldSiteName} - timer") + { + existingHeaders[i] = $"{newSiteName} - timer"; + } + else if (existingHeaders[i].ToString() == $"{oldSiteName} - tekst") + { + existingHeaders[i] = $"{newSiteName} - tekst"; + } + } + var updateRequest = new ValueRange + { + Values = new List> { existingHeaders } + }; + var columnLetter = GetColumnLetter(existingHeaders.Count); + var updateHeaderRequest = + service.Spreadsheets.Values.Update(updateRequest, googleSheetId, $"{sheetName}!A1:{columnLetter}1"); + updateHeaderRequest.ValueInputOption = + SpreadsheetsResource.ValuesResource.UpdateRequest.ValueInputOptionEnum.RAW; + await updateHeaderRequest.ExecuteAsync(); + } + AutoAdjustColumnWidths(service, googleSheetId, sheetName, logger); try From a9c0cb5302ff6e80ec6d0678466a1f5d84d3c3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Fri, 12 Sep 2025 10:30:06 +0200 Subject: [PATCH 05/13] Fixing the test so we validate that a deleted user gets resigned and not removed, since that is what we want it to be. --- ...BackendConfigurationAssignmentWorkerServiceHelperTest.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs index 41e76d68..3ef880a0 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs @@ -399,7 +399,11 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU // Assert timeregistrationSiteAssignments Assert.That(timeregistrationSiteAssignments.Count, Is.EqualTo(1)); Assert.That(timeregistrationSiteAssignments[0].SiteId, Is.EqualTo(sites[2].MicrotingUid)); - Assert.That(timeregistrationSiteAssignments[0].WorkflowState, Is.EqualTo(Constants.WorkflowStates.Removed)); + Assert.That(timeregistrationSiteAssignments[0].WorkflowState, Is.EqualTo(Constants.WorkflowStates.Created)); + Assert.That(timeregistrationSiteAssignments[0].Resigned, Is.True); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Year, Is.EqualTo(DateTime.Now.Year)); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Month, Is.EqualTo(DateTime.Now.Month)); + Assert.That(timeregistrationSiteAssignments[0].ResignedAtDate.Day, Is.EqualTo(DateTime.Now.Day)); // Assert propertyWorkers Assert.That(propertyWorkers.Count, Is.EqualTo(0)); From 5b8a53b94d17a2accb796a56859fe226c83f8afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Fri, 12 Sep 2025 16:37:37 +0200 Subject: [PATCH 06/13] Fixing task management and time registration attributes from modal. --- .../property-worker-create-edit-modal.component.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts index a7748ae1..73de8264 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-create-edit-modal/property-worker-create-edit-modal.component.ts @@ -220,8 +220,10 @@ export class PropertyWorkerCreateEditModalComponent implements OnInit, OnDestroy .assignPropertiesToWorker({ siteId, assignments: this.assignments, - timeRegistrationEnabled: this.form.value.timeRegistrationEnabled, - taskManagementEnabled: this.form.value.taskManagementEnabled + // eslint-disable-next-line max-len + timeRegistrationEnabled: this.form.value.timeRegistrationEnabled === undefined ? this.selectedDeviceUser.timeRegistrationEnabled : this.form.value.timeRegistrationEnabled, + // eslint-disable-next-line max-len + taskManagementEnabled: this.form.value.taskManagementEnabled === undefined ? this.selectedDeviceUser.taskManagementEnabled : this.form.value.taskManagementEnabled, }) .subscribe((operation) => { if (operation && operation.success) { @@ -235,8 +237,10 @@ export class PropertyWorkerCreateEditModalComponent implements OnInit, OnDestroy .updateAssignPropertiesToWorker({ siteId: this.selectedDeviceUser.normalId, assignments: this.assignments, - timeRegistrationEnabled: this.form.value.timeRegistrationEnabled, - taskManagementEnabled: this.form.value.taskManagementEnabled, + // eslint-disable-next-line max-len + timeRegistrationEnabled: this.form.value.timeRegistrationEnabled === undefined ? this.selectedDeviceUser.timeRegistrationEnabled : this.form.value.timeRegistrationEnabled, + // eslint-disable-next-line max-len + taskManagementEnabled: this.form.value.taskManagementEnabled === undefined ? this.selectedDeviceUser.taskManagementEnabled : this.form.value.taskManagementEnabled, }) .subscribe((operation) => { if (operation && operation.success) { From f999b00760926df42dbc5a40273c1dcc949f0414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Sat, 13 Sep 2025 07:27:19 +0200 Subject: [PATCH 07/13] Code cleanup. Fixing the renaming for already collected cases. --- ...rationAssignmentWorkerServiceHelperTest.cs | 6 +-- ...figurationAssignmentWorkerServiceHelper.cs | 45 ++++++++++++------- ...endConfigurationAssignmentWorkerService.cs | 2 +- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs index 3ef880a0..83609c92 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs @@ -180,7 +180,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU // Act var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); @@ -273,7 +273,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); @@ -367,7 +367,7 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, BackendConfigurationPnDbContext, - TimePlanningPnDbContext, logger); + TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); // Assert var sites = await MicrotingDbContext!.Sites.AsNoTracking().ToListAsync(); diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 641448ad..5329c847 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -193,20 +193,6 @@ await core.EntityItemUpdate(entity.Id, entity.Name, entity.Description, { await WorkOrderHelper.RetractEform(assignmentsForDelete, true, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false); await WorkOrderHelper.RetractEform(assignmentsForDelete, false, core, userService.UserId, backendConfigurationPnDbContext).ConfigureAwait(false); - - // foreach (var propertyWorker in assignmentsForDelete) - // { - // var documentSites = await caseTemplatePnDbContext.DocumentSites.Where(x => x.PropertyId == propertyWorker.PropertyId - // && x.SdkSiteId == propertyWorker.WorkerId).ToListAsync(); - // foreach (var documentSite in documentSites) - // { - // if (documentSite.SdkCaseId != 0) - // { - // await core.CaseDelete(documentSite.SdkCaseId); - // } - // } - // } - } foreach (var documentId in documentIds) @@ -267,7 +253,10 @@ await WorkOrderHelper.WorkorderFlowDeployEform(propertyWorkers, core, userServic public static async Task UpdateDeviceUser(DeviceUserModel deviceUserModel, Core core, int userId, - BackendConfigurationPnDbContext backendConfigurationPnDbContext, TimePlanningPnDbContext timePlanningDbContext, ILogger logger) + BackendConfigurationPnDbContext backendConfigurationPnDbContext, + TimePlanningPnDbContext timePlanningDbContext, + ILogger logger, + ItemsPlanningPnDbContext itemsPlanningPnDbContext) { deviceUserModel.UserFirstName = deviceUserModel.UserFirstName.Trim(); deviceUserModel.UserLastName = deviceUserModel.UserLastName.Trim(); @@ -367,6 +356,31 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti } } } + + // find all PlanningCases where the DoneByUserId is the same as the worker.Id and update the DoneByUserName to the new name + var planningCases = await itemsPlanningPnDbContext.PlanningCases + .Where(x => x.DoneByUserId == worker.Id) + .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + .Where(x => x.Status == 100) + .ToListAsync().ConfigureAwait(false); + foreach (var planningCase in planningCases) + { + planningCase.DoneByUserName = fullName; + await planningCase.Update(itemsPlanningPnDbContext).ConfigureAwait(false); + } + + // find all PlanningCaseSites where the DoneByUserId is the same as the SiteId and update the DoneByUserName to the new name + var planningCaseSites = await itemsPlanningPnDbContext.PlanningCaseSites + .Where(x => x.DoneByUserId == worker.Id) + .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + .Where(x => x.Status == 100) + .ToListAsync().ConfigureAwait(false); + foreach (var planningCaseSite in planningCaseSites) + { + planningCaseSite.DoneByUserName = fullName; + await planningCaseSite.Update(itemsPlanningPnDbContext).ConfigureAwait(false); + } + //var siteId = await sdkDbContext.Sites.Where(x => x.MicrotingUid == siteDto.SiteId).Select(x => x.Id).FirstAsync(); if (deviceUserModel.TimeRegistrationEnabled == false && timePlanningDbContext.AssignedSites.Any(x => x.SiteId == siteDto.SiteId && x.WorkflowState != Constants.WorkflowStates.Removed)) { @@ -413,6 +427,7 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti } } } + return isUpdated ? new OperationResult(true, "DeviceUserUpdatedSuccessfully") : new OperationResult(false, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs index 606a1ae2..d01570b1 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs @@ -527,7 +527,7 @@ public async Task UpdateDeviceUser(DeviceUserModel deviceUserMo var core = await coreHelper.GetCore().ConfigureAwait(false); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(deviceUserModel, core, userService.UserId, backendConfigurationPnDbContext, - timePlanningDbContext, logger); + timePlanningDbContext, logger, itemsPlanningPnDbContext); return new OperationResult(result.Success, backendConfigurationLocalizationService.GetString(result.Message)); } From 7dac683ef92c8afc9ed0c633a43caa28bd38d44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 15 Sep 2025 10:00:40 +0200 Subject: [PATCH 08/13] Fixing reporting worker lookup. --- .../BackendConfigurationReportService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs index 213871bf..3a694864 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationReportService/BackendConfigurationReportService.cs @@ -749,7 +749,7 @@ await backendConfigurationPnDbContext.AreaRulePlannings.FirstOrDefaultAsync(x => var dbCase = await sdkDbContext.Cases.FirstOrDefaultAsync(x => x.Id == planningCase.MicrotingSdkCaseId); - var workerId = sdkDbContext.SiteWorkers.First(x => x.Id == dbCase.SiteId).WorkerId; + var workerId = sdkDbContext.SiteWorkers.First(x => x.SiteId == dbCase.SiteId).WorkerId; var worker = await sdkDbContext.Workers.FirstOrDefaultAsync(x => x.Id == workerId); if (dbCase == null) From c6c972b2c532acc7a5038ffa67f0377d11dc7610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 15 Sep 2025 10:57:15 +0200 Subject: [PATCH 09/13] Adding changes to show CreatedAt/UpdatedAt for admin. Adding changes to fix user email/first and last name. --- ...ConfigurationAssignmentWorkerServiceHelper.cs | 15 +++++++++++++++ .../Infrastructure/Models/DeviceUserModel.cs | 5 +++-- ...ackendConfigurationAssignmentWorkerService.cs | 16 ++++++++-------- .../property-worker-table.component.html | 12 +++++++++++- .../property-worker-table.component.ts | 14 +++++++++++++- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index 5329c847..d053b417 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -9,6 +9,7 @@ using BackendConfiguration.Pn.Services.BackendConfigurationLocalizationService; using eFormCore; using JetBrains.Annotations; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microting.eForm.Infrastructure; using Microting.eForm.Infrastructure.Constants; @@ -23,6 +24,7 @@ using Microting.TimePlanningBase.Infrastructure.Data.Entities; using Rebus.Bus; using Microsoft.Extensions.Logging; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; namespace BackendConfiguration.Pn.Infrastructure.Helpers; @@ -253,6 +255,8 @@ await WorkOrderHelper.WorkorderFlowDeployEform(propertyWorkers, core, userServic public static async Task UpdateDeviceUser(DeviceUserModel deviceUserModel, Core core, int userId, + IUserService userService, + UserManager userManager, BackendConfigurationPnDbContext backendConfigurationPnDbContext, TimePlanningPnDbContext timePlanningDbContext, ILogger logger, @@ -276,6 +280,7 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic var worker = await sdkDbContext.Workers.SingleOrDefaultAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); if (worker == null) return new OperationResult(false, "DeviceUserCouldNotBeObtained"); { + var oldEmail = worker.Email; if (sdkDbContext.Workers.Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid)) { // this email is already in use @@ -293,6 +298,16 @@ public static async Task UpdateDeviceUser(DeviceUserModel devic worker.PhoneNumber = deviceUserModel.PhoneNumber; await worker.Update(sdkDbContext).ConfigureAwait(false); + var user = await userService.GetByUsernameAsync(oldEmail).ConfigureAwait(false); + if (user != null) + { + user.Email = deviceUserModel.WorkerEmail; + user.FirstName = deviceUserModel.UserFirstName; + user.LastName = deviceUserModel.UserLastName; + user.Locale = language.LanguageCode; + var result = await userManager.UpdateAsync(user); + } + if (isUpdated) { if (deviceUserModel.TaskManagementEnabled == true) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs index a8cea2f7..787585fb 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Models/DeviceUserModel.cs @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #nullable enable +using System; using System.Collections.Generic; namespace BackendConfiguration.Pn.Infrastructure.Models; @@ -92,9 +93,7 @@ public class DeviceUserModel public bool IsLocked { get; set; } public bool IsBackendUser { get; set; } public bool HasWorkOrdersAssigned { get; set; } - public string Manufacturer { get; set; } - public string Model { get; set; } public string Os { get; set; } public string OsVersion { get; set; } @@ -107,6 +106,8 @@ public class DeviceUserModel public string? WorkerEmail { get; set; } public string? PhoneNumber { get; set; } + public DateTime? CreatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } public static implicit operator DeviceUserModel(Microting.EformAngularFrontendBase.Infrastructure.Data.Models.DeviceUserModel model) { diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs index d01570b1..778c4934 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/BackendConfigurationAssignmentWorkerService/BackendConfigurationAssignmentWorkerService.cs @@ -25,7 +25,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using BackendConfiguration.Pn.Infrastructure.Helpers; using BackendConfiguration.Pn.Infrastructure.Models; using BackendConfiguration.Pn.Services.RebusService; +using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; using Microting.EformBackendConfigurationBase.Infrastructure.Enum; using Microting.eFormCaseTemplateBase.Infrastructure.Data; using Microting.ItemsPlanningBase.Infrastructure.Data; @@ -51,6 +53,7 @@ namespace BackendConfiguration.Pn.Services.BackendConfigurationAssignmentWorkerS public class BackendConfigurationAssignmentWorkerService( IEFormCoreService coreHelper, + UserManager userManager, IUserService userService, BackendConfigurationPnDbContext backendConfigurationPnDbContext, IBackendConfigurationLocalizationService backendConfigurationLocalizationService, @@ -364,6 +367,8 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id site.WorkflowState, WorkerEmail = worker.Email, worker.PhoneNumber, + site.CreatedAt, + site.UpdatedAt }; sitesQuery = sitesQuery.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed); @@ -371,6 +376,8 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id var deviceUsers = await sitesQuery .Select(x => new DeviceUserModel { + CreatedAt = x.CreatedAt, + UpdatedAt = x.UpdatedAt, UserFirstName = x.UserFirstName, UserLastName = x.UserLastName, EmployeeNo = x.EmployeeNo, @@ -490,13 +497,6 @@ join worker in sdkDbContext.Workers on siteWorker.WorkerId equals worker.Id // Convert deviceUsers to IQueryable var deviceUsersQuery = deviceUsers.AsQueryable(); - var tempList = deviceUsersQuery.ToList(); - - foreach (var deviceUserModel in tempList) - { - Console.WriteLine("Device user: " + deviceUserModel.SiteName + " with workerEmail: " + deviceUserModel.WorkerEmail + " and phone number: " + deviceUserModel.PhoneNumber); - } - try { deviceUsersQuery = QueryHelper.AddFilterAndSortToQuery(deviceUsersQuery, requestModel, new List { "SiteName", "WorkerEmail", "PhoneNumber", "EmployeeNo" }); @@ -526,7 +526,7 @@ public async Task UpdateDeviceUser(DeviceUserModel deviceUserMo { var core = await coreHelper.GetCore().ConfigureAwait(false); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(deviceUserModel, core, - userService.UserId, backendConfigurationPnDbContext, + userService.UserId, userService, userManager, backendConfigurationPnDbContext, timePlanningDbContext, logger, itemsPlanningPnDbContext); return new OperationResult(result.Success, backendConfigurationLocalizationService.GetString(result.Message)); diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html index 94a4e675..69113996 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.html @@ -46,8 +46,18 @@ + + + + -
{{row.siteId}}
+
+ + {{row.siteId}} ({{getFormattedDate(row.createdAt)}} / {{getFormattedDate(row.updatedAt)}}) + + + {{row.siteId}} +
diff --git a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts index d805f75d..5e9eb07e 100644 --- a/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts +++ b/eform-client/src/app/plugins/modules/backend-configuration-pn/modules/property-workers/components/property-worker-table/property-worker-table.component.ts @@ -18,12 +18,18 @@ import { } from '../'; import {dialogConfigHelper} from 'src/app/common/helpers'; import {Store} from '@ngrx/store'; -import {selectCurrentUserClaimsDeviceUsersDelete, selectCurrentUserClaimsDeviceUsersUpdate} from 'src/app/state'; +import { + selectAuthIsAdmin, + selectCurrentUserClaimsDeviceUsersDelete, + selectCurrentUserClaimsDeviceUsersUpdate +} from 'src/app/state'; import { selectPropertyWorkersNameFilters, selectPropertyWorkersPaginationIsSortDsc, selectPropertyWorkersPaginationSort } from '../../../../state'; +import {format} from "date-fns"; +import {AuthStateService} from "src/app/common/store"; @AutoUnsubscribe() @Component({ @@ -49,6 +55,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { public selectPropertyWorkersPaginationSort$ = this.store.select(selectPropertyWorkersPaginationSort); public selectPropertyWorkersPaginationIsSortDsc$ = this.store.select(selectPropertyWorkersPaginationIsSortDsc); public selectPropertyWorkersNameFilters$ = this.store.select(selectPropertyWorkersNameFilters); + public selectAuthIsAdmin$ = this.store.select(selectAuthIsAdmin); get TaskWizardStatusesEnum() { return TaskWizardStatusesEnum; @@ -57,6 +64,7 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { constructor( private store: Store, private translateService: TranslateService, + private authStateService: AuthStateService, public propertyWorkersStateService: PropertyWorkersStateService, private dialog: MatDialog, private overlay: Overlay,) { @@ -299,4 +307,8 @@ export class PropertyWorkerTableComponent implements OnInit, OnDestroy { ngOnDestroy(): void { } + + getFormattedDate(date: Date) { + return format(date, 'P', {locale: this.authStateService.dateFnsLocale}); + } } From 6466349c07d82098b4ea176025686c5866fe2a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 15 Sep 2025 11:11:37 +0200 Subject: [PATCH 10/13] Moving the validation to the top of CreateDevice user, so we fail fast. --- ...ConfigurationAssignmentWorkerServiceHelper.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs index d053b417..e4887ca1 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/BackendConfigurationAssignmentWorkerServiceHelper.cs @@ -462,12 +462,20 @@ await core.EntityItemUpdate(entityItem.Id, entityItem.Name, entityItem.Descripti public static async Task> CreateDeviceUser(DeviceUserModel deviceUserModel, Core core, int userId, TimePlanningPnDbContext timePlanningDbContext) { + + var sdkDbContext = core.DbContextHelper.GetDbContext(); + + if (sdkDbContext.Workers.AsNoTracking().Any(x => x.Email == deviceUserModel.WorkerEmail && x.WorkflowState != Constants.WorkflowStates.Removed)) + { + // this email is already in use + return new OperationDataResult(false, "EmailIsAlreadyInUse"); + } + deviceUserModel.UserFirstName = deviceUserModel.UserFirstName.Trim(); deviceUserModel.UserLastName = deviceUserModel.UserLastName.Trim(); // var result = await _deviceUsersService.Create(deviceUserModel); var siteName = deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName; - var sdkDbContext = core.DbContextHelper.GetDbContext(); var site = await sdkDbContext.Sites.AsNoTracking().SingleOrDefaultAsync(x => x.Name == deviceUserModel.UserFirstName + " " + deviceUserModel.UserLastName && x.WorkflowState != Constants.WorkflowStates.Removed); if (site != null) @@ -482,12 +490,6 @@ public static async Task> CreateDeviceUser(DeviceUserMo var worker = await sdkDbContext.Workers.SingleAsync(x => x.MicrotingUid == siteDto.WorkerUid).ConfigureAwait(false); - if (sdkDbContext.Workers.AsNoTracking().Any(x => x.Email == deviceUserModel.WorkerEmail && x.MicrotingUid != siteDto.WorkerUid && x.WorkflowState != Constants.WorkflowStates.Removed)) - { - // this email is already in use - return new OperationDataResult(false, "EmailIsAlreadyInUse"); - } - worker.EmployeeNo = deviceUserModel.EmployeeNo; worker.PinCode = deviceUserModel.PinCode; worker.Email = deviceUserModel.WorkerEmail; From 2642ace8d267d718704c6f2187f4fbddbe2bbcec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 15 Sep 2025 11:17:28 +0200 Subject: [PATCH 11/13] Updating tests to have substitutes for userService and userManger. --- ...aRulePlanningsServiceHelperTestLogBooks.cs | 21 ++++++---- ...erviceHelperTestLogBooksCustomStartDate.cs | 21 ++++++---- ...lanningsServiceHelperTestLogBooksMonths.cs | 42 ++++++++++++------- ...rviceHelperTestLogBooksMonthsCustomDate.cs | 42 ++++++++++++------- ...RulePlanningsServiceHelperTestTailBites.cs | 9 ++-- ...rationAssignmentWorkerServiceHelperTest.cs | 31 ++++++++++++-- 6 files changed, 117 insertions(+), 49 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs index f2d8d9f4..c4ba57c2 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooks.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleDays2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -454,7 +455,8 @@ public async Task UpdatePlanning_AreaRuleWeeks1Monday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -858,7 +860,8 @@ public async Task UpdatePlanning_AreaRuleWeeks2Wednesday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1262,7 +1265,8 @@ public async Task UpdatePlanning_AreaRuleDays0_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1688,7 +1692,8 @@ public async Task UpdatePlanning_AreaRuleDays0FillAndAdd_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1817,7 +1822,8 @@ await BackendConfigurationAreaRulePlanningsServiceHelper.UpdatePlanning(areaRule LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel2, core, 1, @@ -2159,7 +2165,8 @@ public async Task UpdatePlanning_AreaRuleDays4DisableReenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs index d49169b1..8f59e5bf 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksCustomStartDate.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleDays2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -457,7 +458,8 @@ public async Task UpdatePlanning_AreaRuleWeeks1Monday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -874,7 +876,8 @@ public async Task UpdatePlanning_AreaRuleWeeks2Wednesday_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1281,7 +1284,8 @@ public async Task UpdatePlanning_AreaRuleDays0_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1676,7 +1680,8 @@ public async Task UpdatePlanning_AreaRuleDays0FillAndAdd_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1808,7 +1813,8 @@ await BackendConfigurationAreaRulePlanningsServiceHelper.UpdatePlanning(areaRule LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel2, core, 1, @@ -2151,7 +2157,8 @@ public async Task UpdatePlanning_AreaRuleDays4DisableReenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs index 745caf6f..36ca6f11 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonths.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleMonths1_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -454,7 +455,8 @@ public async Task UpdatePlanning_AreaRuleMonths2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -855,7 +857,8 @@ public async Task UpdatePlanning_AreaRuleMonths3_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1257,7 +1260,8 @@ public async Task UpdatePlanning_AreaRuleMonths6_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1659,7 +1663,8 @@ public async Task UpdatePlanning_AreaRuleMonths12_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2056,7 +2061,8 @@ public async Task UpdatePlanning_AreaRuleMonths24_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2453,7 +2459,8 @@ public async Task UpdatePlanning_AreaRuleMonths36_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2850,7 +2857,8 @@ public async Task UpdatePlanning_AreaRuleMonths48_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3247,7 +3255,8 @@ public async Task UpdatePlanning_AreaRuleMonths60_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3644,7 +3653,8 @@ public async Task UpdatePlanning_AreaRuleMonths72_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4041,7 +4051,8 @@ public async Task UpdatePlanning_AreaRuleMonths84_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4438,7 +4449,8 @@ public async Task UpdatePlanning_AreaRuleMonths96_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4835,7 +4847,8 @@ public async Task UpdatePlanning_AreaRuleMonths108_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -5232,7 +5245,8 @@ public async Task UpdatePlanning_AreaRuleMonths120_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs index f7111d23..5734cfb7 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestLogBooksMonthsCustomDate.cs @@ -53,7 +53,8 @@ public async Task UpdatePlanning_AreaRuleMonths1_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -457,7 +458,8 @@ public async Task UpdatePlanning_AreaRuleMonths2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -860,7 +862,8 @@ public async Task UpdatePlanning_AreaRuleMonths3_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1263,7 +1266,8 @@ public async Task UpdatePlanning_AreaRuleMonths6_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -1667,7 +1671,8 @@ public async Task UpdatePlanning_AreaRuleMonths12_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2071,7 +2076,8 @@ public async Task UpdatePlanning_AreaRuleMonths24_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2474,7 +2480,8 @@ public async Task UpdatePlanning_AreaRuleMonths36_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -2877,7 +2884,8 @@ public async Task UpdatePlanning_AreaRuleMonths48_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3280,7 +3288,8 @@ public async Task UpdatePlanning_AreaRuleMonths60_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -3683,7 +3692,8 @@ public async Task UpdatePlanning_AreaRuleMonths72_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4086,7 +4096,8 @@ public async Task UpdatePlanning_AreaRuleMonths84_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4489,7 +4500,8 @@ public async Task UpdatePlanning_AreaRuleMonths96_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -4892,7 +4904,8 @@ public async Task UpdatePlanning_AreaRuleMonths108_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -5295,7 +5308,8 @@ public async Task UpdatePlanning_AreaRuleMonths120_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs index 85d2470e..48f92863 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAreaRulePlanningsServiceHelperTestTailBites.cs @@ -46,7 +46,8 @@ public async Task UpdatePlanning_AreaRule0Days2_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -392,7 +393,8 @@ public async Task UpdatePlanning_AreaRule0Days2Disable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -763,7 +765,8 @@ public async Task UpdatePlanning_AreaRule0Days2DisableRenable_ReturnsSuccess() LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs index 83609c92..8b786b17 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn.Integration.Test/BackendConfigurationAssignmentWorkerServiceHelperTest.cs @@ -4,10 +4,12 @@ using BackendConfiguration.Pn.Infrastructure.Models.Properties; using BackendConfiguration.Pn.Services.BackendConfigurationLocalizationService; using eFormCore; +using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microting.eForm.Infrastructure.Constants; using Microting.eFormApi.BasePn.Abstractions; +using Microting.eFormApi.BasePn.Infrastructure.Database.Entities; using NSubstitute; namespace BackendConfiguration.Pn.Integration.Test; @@ -32,7 +34,8 @@ public async Task BackendConfigurationAssignmentWorkerServiceHelper_CreateDevice LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; // Act @@ -178,7 +181,12 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, userManager, BackendConfigurationPnDbContext, TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); @@ -270,8 +278,14 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, + userManager, BackendConfigurationPnDbContext, TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); @@ -364,8 +378,14 @@ await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceU }; // Act + var userService = Substitute.For(); + var userManager = Substitute.For>( + Substitute.For>(), + null, null, null, null, null, null, null, null); var result = await BackendConfigurationAssignmentWorkerServiceHelper.UpdateDeviceUser(newDeviceUserModel, core, 1, + userService, + userManager, BackendConfigurationPnDbContext, TimePlanningPnDbContext, logger, ItemsPlanningPnDbContext); @@ -441,7 +461,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel, co LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; /*var result = */await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -536,7 +557,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel, co LanguageCode = "da", TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), - UserLastName = Guid.NewGuid().ToString() + UserLastName = Guid.NewGuid().ToString(), + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; /*var result = */await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, @@ -803,7 +825,8 @@ await BackendConfigurationPropertiesServiceHelper.Create(propertyCreateModel2, c TimeRegistrationEnabled = false, UserFirstName = Guid.NewGuid().ToString(), UserLastName = Guid.NewGuid().ToString(), - TaskManagementEnabled = true + TaskManagementEnabled = true, + WorkerEmail = $"{Guid.NewGuid()}@test.com" }; await BackendConfigurationAssignmentWorkerServiceHelper.CreateDeviceUser(deviceUserModel, core, 1, From ef7cbf3561194147e8caa0beddb8756da6f8202c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 15 Sep 2025 12:24:12 +0200 Subject: [PATCH 12/13] Commenting the risky code for now. --- .../Infrastructure/Helpers/WorkOrderHelper.cs | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs index 377439f6..ce0b27fc 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Infrastructure/Helpers/WorkOrderHelper.cs @@ -150,55 +150,55 @@ public static async Task DeployEform(PropertyWorker propertyWorker, int eformId && x.CaseStatusesEnum == CaseStatusesEnum.NewTask && x.WorkflowState != Constants.WorkflowStates.Removed)) { - // find all cases that are not removed and assignedTo is equal to site.name and update them with the new name - var workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.AssignedToSdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } - - workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.CreatedBySdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - if(workorderCase.AssignedToSdkSiteId == null) - { - continue; - } - - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } - - workorderCases = await backendConfigurationPnDbContext.WorkorderCases - .Where(x => x.UpdatedBySdkSiteId == propertyWorker.WorkerId) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) - .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) - .Where(x => x.LeadingCase == true) - .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) - .ToListAsync().ConfigureAwait(false); - foreach (var workorderCase in workorderCases) - { - if(workorderCase.AssignedToSdkSiteId == null) - { - continue; - } - - await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, - localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); - } + // // find all cases that are not removed and assignedTo is equal to site.name and update them with the new name + // var workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.AssignedToSdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } + // + // workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.CreatedBySdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // if(workorderCase.AssignedToSdkSiteId == null) + // { + // continue; + // } + // + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } + // + // workorderCases = await backendConfigurationPnDbContext.WorkorderCases + // .Where(x => x.UpdatedBySdkSiteId == propertyWorker.WorkerId) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.NewTask) + // .Where(x => x.CaseStatusesEnum != CaseStatusesEnum.Completed) + // .Where(x => x.LeadingCase == true) + // .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed) + // .ToListAsync().ConfigureAwait(false); + // foreach (var workorderCase in workorderCases) + // { + // if(workorderCase.AssignedToSdkSiteId == null) + // { + // continue; + // } + // + // await BackendConfigurationTaskManagementHelper.UpdateTask(new WorkOrderCaseUpdateModel() {Id = workorderCase.Id, AssignedSiteId = (int) workorderCase.AssignedToSdkSiteId!, Description = workorderCase.Description, Priority = int.Parse(workorderCase.Priority)}, + // localizationService, core, userService, backendConfigurationPnDbContext, bus, useGetCurrentUserFullName).ConfigureAwait(false); + // } return; From 74308ca46e4b2c1be41046cacfa2034d5a636c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Schultz=20Madsen?= Date: Mon, 22 Sep 2025 12:31:19 +0200 Subject: [PATCH 13/13] Making sure to remove / as it's a reserved char. --- .../Services/ExcelService/ExcelService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs index 4a852624..7a7e576b 100644 --- a/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs +++ b/eFormAPI/Plugins/BackendConfiguration.Pn/BackendConfiguration.Pn/Services/ExcelService/ExcelService.cs @@ -58,7 +58,7 @@ public async Task GenerateWorkOrderCaseReport(TaskManagementFiltersModel Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "results")); var filePath = Path.Combine(Path.GetTempPath(), "results", - $"{propertyName}_{filtersModel.AreaName}.xlsx"); + $"{propertyName.Replace("/", "")}_{filtersModel.AreaName}.xlsx"); using (var document = SpreadsheetDocument.Create(filePath, SpreadsheetDocumentType.Workbook))