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

Make minor development updates #135

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageVersion Include="ClosedXML" Version="0.104.1" />
<PackageVersion Include="Dapper" Version="2.1.35" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageVersion Include="GaEpd.AppLibrary" Version="5.3.1" />
<PackageVersion Include="GaEpd.AppLibrary" Version="5.4.0" />
<PackageVersion Include="GaEpd.EmailService" Version="1.0.0" />
<PackageVersion Include="GaEpd.FileService" Version="3.1.1" />
<PackageVersion Include="HtmlSanitizer" Version="8.1.870" />
Expand Down
16 changes: 7 additions & 9 deletions src/WebApp/Pages/Account/ExternalLogin.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
var user = await userManager.FindByIdAsync(staffId);
logger.LogInformation("Local user with ID {StaffId} signed in", staffId);

await signInManager.SignInAsync(user!, false);
user!.MostRecentLogin = DateTimeOffset.Now;
await userManager.UpdateAsync(user);
await signInManager.SignInAsync(user, false);
return LocalRedirectOrHome();
}

Expand Down Expand Up @@ -167,8 +169,8 @@
return await FailedLoginAsync(createUserResult, user);
}

logger.LogInformation("Created new user {Email} with object ID {ObjectId}", user.Email.MaskEmail(),
user.ObjectIdentifier);
logger.LogInformation("Created new user {Email} with object ID {ObjectId}",
user.Email.MaskEmail(), user.ObjectIdentifier);
Fixed Show fixed Hide fixed

// Add new user to application Roles if seeded in app settings or local admin user setting is enabled.
var seedAdminUsers = configuration.GetSection("SeedAdminUsers").Get<string[]>();
Expand Down Expand Up @@ -218,7 +220,6 @@
}

await userManager.UpdateAsync(user);

await signInManager.RefreshSignInAsync(user);
return LocalRedirectOrHome();
}
Expand Down Expand Up @@ -262,9 +263,6 @@
return Page();
}

private IActionResult LocalRedirectOrHome()
{
if (ReturnUrl is null) return RedirectToPage("/Staff/Index");
return LocalRedirect(ReturnUrl);
}
private IActionResult LocalRedirectOrHome() =>
ReturnUrl is null ? RedirectToPage("/Staff/Index") : LocalRedirect(ReturnUrl);
}
15 changes: 10 additions & 5 deletions src/WebApp/Platform/AppConfiguration/MigratorHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public async Task StartAsync(CancellationToken cancellationToken)
if (AppSettings.DevSettings.UseInMemoryData) return;

var migrationConnectionString = configuration.GetConnectionString("MigrationConnection");
var migrationOptions = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServer(migrationConnectionString, builder => builder.MigrationsAssembly("EfRepository")).Options;
var dbContextOptionsBuilder = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlServer(migrationConnectionString, builder => builder.MigrationsAssembly("EfRepository"));

await using var migrationContext = new AppDbContext(migrationOptions);
if (AppSettings.DevSettings.UseDevSettings)
{
dbContextOptionsBuilder
.LogTo(Console.WriteLine, [DbLoggerCategory.Database.Command.Name], LogLevel.Information);
}

await using var migrationContext = new AppDbContext(dbContextOptionsBuilder.Options);

if (AppSettings.DevSettings.UseEfMigrations)
{
Expand All @@ -31,8 +37,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
var roleManager = scope.ServiceProvider.GetRequiredService<RoleManager<IdentityRole>>();
foreach (var role in AppRole.AllRoles.Keys)
{
if (!await migrationContext.Roles.AnyAsync(identityRole => identityRole.Name == role,
cancellationToken))
if (!await migrationContext.Roles.AnyAsync(idRole => idRole.Name == role, cancellationToken))
{
await roleManager.CreateAsync(new IdentityRole(role));
}
Expand Down
9 changes: 6 additions & 3 deletions tests/EfRepositoryTests/RepositoryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GaEpd.AppLibrary.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using MyApp.Domain.Entities.EntryTypes;
using MyApp.Domain.Entities.Offices;
using MyApp.Domain.Entities.WorkEntries;
Expand All @@ -26,7 +27,7 @@ namespace EfRepositoryTests;
/// </summary>
public sealed class RepositoryHelper : IDisposable, IAsyncDisposable
{
private AppDbContext Context { get; set; } = default!;
private AppDbContext Context { get; set; } = null!;

private readonly DbContextOptions<AppDbContext> _options;
private readonly AppDbContext _context;
Expand All @@ -36,7 +37,8 @@ public sealed class RepositoryHelper : IDisposable, IAsyncDisposable
/// </summary>
private RepositoryHelper()
{
_options = SqliteInMemory.CreateOptions<AppDbContext>();
_options = SqliteInMemory.CreateOptions<AppDbContext>(builder =>
builder.LogTo(Console.WriteLine, events: [RelationalEventId.CommandExecuted]));
_context = new AppDbContext(_options);
_context.Database.EnsureCreated();
}
Expand All @@ -49,7 +51,8 @@ private RepositoryHelper()
private RepositoryHelper(object callingClass, string callingMember)
{
_options = callingClass.CreateUniqueMethodOptions<AppDbContext>(callingMember: callingMember,
builder: opts => opts.UseSqlServer());
builder: builder => builder.UseSqlServer()
.LogTo(Console.WriteLine, events: [RelationalEventId.CommandExecuted]));
_context = new AppDbContext(_options);
_context.Database.EnsureClean();
}
Expand Down
Loading