From cfab91a29b721cc212da3f43ac357d6b999e9333 Mon Sep 17 00:00:00 2001
From: Amelia <77553571+Fesaa@users.noreply.github.com>
Date: Thu, 29 May 2025 23:25:35 +0200
Subject: [PATCH] Ensure default reading profile is created when creating a
user
---
API/Controllers/AccountController.cs | 15 +++++++++++++++
API/Entities/AppUserPreferences.cs | 1 +
API/Helpers/Builders/AppUserBuilder.cs | 5 +++--
.../manage-reading-profiles.component.ts | 7 ++++++-
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/API/Controllers/AccountController.cs b/API/Controllers/AccountController.cs
index c504e1ce7..5501bb338 100644
--- a/API/Controllers/AccountController.cs
+++ b/API/Controllers/AccountController.cs
@@ -153,6 +153,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
+ // Assign default reading profile
+ AddDefaultReadingProfileToUser(user);
+
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
if (string.IsNullOrEmpty(token)) return BadRequest(await _localizationService.Get("en", "confirm-token-gen"));
if (!await ConfirmEmailToken(token, user)) return BadRequest(await _localizationService.Get("en", "validate-email", token));
@@ -669,6 +672,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
+ // Assign default reading profile
+ AddDefaultReadingProfileToUser(user);
+
// Assign Roles
var roles = dto.Roles;
var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);
@@ -779,6 +785,15 @@ public class AccountController : BaseApiController
}
}
+ private void AddDefaultReadingProfileToUser(AppUser user)
+ {
+ var profile = new AppUserReadingProfileBuilder(user.Id)
+ .WithName("Default Profile")
+ .Build();
+ user.UserPreferences.ReadingProfiles.Add(profile);
+ user.UserPreferences.DefaultReadingProfile = profile;
+ }
+
///
/// Last step in authentication flow, confirms the email token for email
///
diff --git a/API/Entities/AppUserPreferences.cs b/API/Entities/AppUserPreferences.cs
index 9545f190b..d38b68bad 100644
--- a/API/Entities/AppUserPreferences.cs
+++ b/API/Entities/AppUserPreferences.cs
@@ -12,6 +12,7 @@ public class AppUserPreferences
#region ReadingProfiles
public int DefaultReadingProfileId { get; set; }
+ public AppUserReadingProfile DefaultReadingProfile { get; set; }
public ICollection ReadingProfiles { get; set; } = null!;
diff --git a/API/Helpers/Builders/AppUserBuilder.cs b/API/Helpers/Builders/AppUserBuilder.cs
index 282361e41..382e4b35b 100644
--- a/API/Helpers/Builders/AppUserBuilder.cs
+++ b/API/Helpers/Builders/AppUserBuilder.cs
@@ -21,7 +21,8 @@ public class AppUserBuilder : IEntityBuilder
ApiKey = HashUtil.ApiKey(),
UserPreferences = new AppUserPreferences
{
- Theme = theme ?? Seed.DefaultThemes.First()
+ Theme = theme ?? Seed.DefaultThemes.First(),
+ ReadingProfiles = [],
},
ReadingLists = new List(),
Bookmarks = new List(),
@@ -31,7 +32,7 @@ public class AppUserBuilder : IEntityBuilder
Devices = new List(),
Id = 0,
DashboardStreams = new List(),
- SideNavStreams = new List()
+ SideNavStreams = new List(),
};
}
diff --git a/UI/Web/src/app/user-settings/manage-reading-profiles/manage-reading-profiles.component.ts b/UI/Web/src/app/user-settings/manage-reading-profiles/manage-reading-profiles.component.ts
index 416b1b2e4..ad5709790 100644
--- a/UI/Web/src/app/user-settings/manage-reading-profiles/manage-reading-profiles.component.ts
+++ b/UI/Web/src/app/user-settings/manage-reading-profiles/manage-reading-profiles.component.ts
@@ -45,6 +45,7 @@ import {filter} from "rxjs";
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {LoadingComponent} from "../../shared/loading/loading.component";
import {ReadingProfileLibrarySelectionComponent} from "./_components/library-selection/reading-profile-library-selection.component";
+import {ToastrService} from "ngx-toastr";
enum TabId {
ImageReader = "image-reader",
@@ -114,6 +115,7 @@ export class ManageReadingProfilesComponent implements OnInit {
private accountService: AccountService,
private bookService: BookService,
private destroyRef: DestroyRef,
+ private toastr: ToastrService,
) {
this.fontFamilies = this.bookService.getFontFamilies().map(f => f.title);
this.cdRef.markForCheck();
@@ -222,6 +224,7 @@ export class ManageReadingProfilesComponent implements OnInit {
},
error: err => {
console.log(err);
+ this.toastr.error(err.message);
}
})
} else {
@@ -236,6 +239,7 @@ export class ManageReadingProfilesComponent implements OnInit {
},
error: err => {
console.log(err);
+ this.toastr.error(err.message);
}
})
}
@@ -246,8 +250,9 @@ export class ManageReadingProfilesComponent implements OnInit {
private packData(): ReadingProfile {
const data: ReadingProfile = this.readingProfileForm!.getRawValue();
data.id = this.selectedProfile!.id;
- // Hack around readerMode being sent as a string otherwise
+ // Hack around readerMode being sent as a string otherwise ????
data.readerMode = parseInt(data.readerMode as unknown as string);
+ data.bookReaderLayoutMode = parseInt(data.bookReaderLayoutMode as unknown as string);
return data;
}