Skip to content

Commit d792352

Browse files
committed
Adding linking fix for the startup, should be removed after some time.
1 parent 1b6a566 commit d792352

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

eFormAPI/eFormAPI.Web/Startup.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
395395
app.UseEFormPlugins(Program.EnabledPlugins);
396396
// Route all unknown requests to app root
397397
app.UseAngularMiddleware(env);
398+
FixUserToWorkerLinks();
398399
}
399400

400401

@@ -471,4 +472,34 @@ private ICollection<PluginPermissionModel> GetPluginsPermissions()
471472

472473
return permissions;
473474
}
475+
476+
// TODO remove, when we are sure that all users have been fixed.
477+
// This method is only needed for a short period of time to fix the users that already exist.
478+
// It matches users to workers based on First and Last name, and updates the email on the worker.
479+
// It is not a perfect solution, but it is the best we can do without having a direct link between the two.
480+
// It is assumed that users have unique First and Last names.
481+
// If there are multiple workers with the same name, only the first one found will be updated.
482+
// If a worker already has an email, it will be overwritten.
483+
// After a while this method should be removed again.
484+
private void FixUserToWorkerLinks()
485+
{
486+
if (Configuration.MyConnectionString() == "...") return;
487+
var contextFactory = new BaseDbContextFactory();
488+
using var dbContext = contextFactory.CreateDbContext([Configuration.MyConnectionString()]);
489+
490+
var sdkDbContextFactory = new MicrotingDbContextFactory();
491+
using var sdkDbContext =
492+
sdkDbContextFactory.CreateDbContext([Configuration.MyConnectionString().Replace("Angular", "SDK")]);
493+
494+
var users = dbContext.Users.AsNoTracking().ToList();
495+
foreach (var user in users)
496+
{
497+
var fullName = (user.FirstName + user.LastName).Trim().ToLower().Replace(" ", "");
498+
var worker = sdkDbContext.Workers.FirstOrDefault(x =>
499+
(x.FirstName + x.LastName).Trim().ToLower().Replace(" ", "") == fullName && x.WorkflowState != "removed");
500+
if (worker == null) continue;
501+
worker.Email = user.Email;
502+
worker.Update(sdkDbContext).GetAwaiter().GetResult();
503+
}
504+
}
474505
}

0 commit comments

Comments
 (0)