Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(backend:users): ensure default value for user secrets when null
johaven090eb6e61f49
diff --git a/backend/src/applications/users/services/users-manager.service.ts b/backend/src/applications/users/services/users-manager.service.tsindex 56cdaf5a..f1e4e7c5 100755--- a/backend/src/applications/users/services/users-manager.service.ts+++ b/backend/src/applications/users/services/users-manager.service.ts@@ -161,8 +161,8 @@ export class UsersManager {}async updateSecrets(userId: number, secrets: UserSecrets) {- const userProps = (await this.usersQueries.selectUserProperties(userId, ['secrets'])) as { secrets: UserSecrets }- const updatedSecrets = userProps['secrets'] ? { ...userProps['secrets'], ...secrets } : secrets+ const userSecrets = await this.usersQueries.getUserSecrets(userId)+ const updatedSecrets = { ...userSecrets, ...secrets }if (!(await this.usersQueries.updateUserOrGuest(userId, { secrets: updatedSecrets }))) {throw new HttpException('Unable to update secrets', HttpStatus.INTERNAL_SERVER_ERROR)}@@ -218,7 +218,7 @@ export class UsersManager {}async listAppPasswords(user: UserModel): Promise<Omit<UserAppPassword, 'password'>[]> {- const secrets = (await this.usersQueries.selectUserProperties(user.id, ['secrets'])).secrets as UserSecrets+ const secrets = await this.usersQueries.getUserSecrets(user.id)if (Array.isArray(secrets.appPasswords)) {// remove passwords from responsereturn secrets.appPasswords.map(({ password, ...rest }: UserAppPassword) => rest)@@ -227,7 +227,7 @@ export class UsersManager {}async generateAppPassword(user: UserModel, userAppPasswordDto: UserAppPasswordDto): Promise<UserAppPassword> {- const secrets = (await this.usersQueries.selectUserProperties(user.id, ['secrets'])).secrets as UserSecrets+ const secrets = await this.usersQueries.getUserSecrets(user.id)const slugName = createLightSlug(userAppPasswordDto.name)if (Array.isArray(secrets.appPasswords) && secrets.appPasswords.find((p: UserAppPassword) => p.name === slugName)) {throw new HttpException('Name already used', HttpStatus.BAD_REQUEST)@@ -254,7 +254,7 @@ export class UsersManager {}async deleteAppPassword(user: UserModel, passwordName: string): Promise<void> {- const secrets = (await this.usersQueries.selectUserProperties(user.id, ['secrets'])).secrets as UserSecrets+ const secrets = await this.usersQueries.getUserSecrets(user.id)if (!Array.isArray(secrets.appPasswords) || !secrets.appPasswords.find((p: UserAppPassword) => p.name === passwordName)) {throw new HttpException('App password not found', HttpStatus.NOT_FOUND)}@@ -266,7 +266,7 @@ export class UsersManager {async validateAppPassword(user: UserModel, password: string, ip: string, scope: AUTH_SCOPE): Promise<boolean> {if (!scope || !user.haveRole(USER_ROLE.USER)) return false- const secrets = (await this.usersQueries.selectUserProperties(user.id, ['secrets'])).secrets as UserSecrets+ const secrets = await this.usersQueries.getUserSecrets(user.id)if (!Array.isArray(secrets.appPasswords)) return falsefor (const p of secrets.appPasswords) {if (p.app !== scope) continuediff --git a/backend/src/applications/users/services/users-queries.service.ts b/backend/src/applications/users/services/users-queries.service.tsindex dbe94e5e..be8e9053 100644--- a/backend/src/applications/users/services/users-queries.service.ts+++ b/backend/src/applications/users/services/users-queries.service.ts@@ -29,6 +29,7 @@ import { SearchMembersDto } from '../dto/search-members.dto'import { GroupMember, GroupWithMembers } from '../interfaces/group-member'import { GuestUser } from '../interfaces/guest-user.interface'import { Member } from '../interfaces/member.interface'+import { UserSecrets } from '../interfaces/user-secrets.interface'import { UserOnline } from '../interfaces/websocket.interface'import { UserModel } from '../models/user.model'import { Group } from '../schemas/group.interface'@@ -132,6 +133,11 @@ export class UsersQueries {return user}+ async getUserSecrets(userId: number): Promise<UserSecrets> {+ const [r]: { secrets: UserSecrets }[] = await this.db.select({ secrets: users.secrets }).from(users).where(eq(users.id, userId)).limit(1)+ return r.secrets || {}+ }+selectUsers(fields: Partial<keyof User>[] = ['id', 'login', 'email'], where: SQL[]): Promise<Partial<User>[]> {const select: Record<keyof User, any> = convertToSelect(users, fields)return this.dbdiff --git a/frontend/src/app/applications/users/components/dialogs/user-auth-manage-app-passwords-dialog.component.html b/frontend/src/app/applications/users/components/dialogs/user-auth-manage-app-passwords-dialog.component.htmlindex 6873ed55..6b0df6ea 100644--- a/frontend/src/app/applications/users/components/dialogs/user-auth-manage-app-passwords-dialog.component.html+++ b/frontend/src/app/applications/users/components/dialogs/user-auth-manage-app-passwords-dialog.component.html@@ -87,7 +87,7 @@}<div class="d-flex"><strong l10nTranslate>Generated password</strong>: - <span class="font-monospace link-body-emphasis" (click)="clipBoardPassword()" role="button">+ <span class="font-monospace fw-bold link-body-emphasis" (click)="clipBoardPassword()" role="button"><fa-icon [icon]="icons.faCopy"></fa-icon><span>{{ generatedPassword.password }}</span></span>