From 9e5cf66be7ad897e106f283bee73a165c72e74de Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 28 Oct 2022 16:15:04 +0200 Subject: Breaking API: Consistency with role id/label --- client/src/app/+admin/overview/users/user-edit/user-edit.ts | 2 +- .../+admin/overview/users/user-edit/user-update.component.ts | 2 +- .../+admin/overview/users/user-list/user-list.component.html | 4 ++-- client/src/app/app.component.ts | 4 ++-- client/src/app/core/auth/auth-user.model.ts | 6 +++--- client/src/app/core/users/user-local-storage.service.ts | 11 ++++++++--- client/src/app/core/users/user.model.ts | 10 ++++++---- client/src/app/shared/shared-users/user-admin.service.ts | 5 ++++- 8 files changed, 27 insertions(+), 17 deletions(-) (limited to 'client/src') diff --git a/client/src/app/+admin/overview/users/user-edit/user-edit.ts b/client/src/app/+admin/overview/users/user-edit/user-edit.ts index 5428f6ce9..1edca7fbf 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-edit.ts +++ b/client/src/app/+admin/overview/users/user-edit/user-edit.ts @@ -49,7 +49,7 @@ export abstract class UserEdit extends FormReactive implements OnInit { buildRoles () { const authUser = this.auth.getUser() - if (authUser.role === UserRole.ADMINISTRATOR) { + if (authUser.role.id === UserRole.ADMINISTRATOR) { this.roles = Object.keys(USER_ROLE_LABELS) .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) return diff --git a/client/src/app/+admin/overview/users/user-edit/user-update.component.ts b/client/src/app/+admin/overview/users/user-edit/user-update.component.ts index 71212b19c..25d02f000 100644 --- a/client/src/app/+admin/overview/users/user-edit/user-update.component.ts +++ b/client/src/app/+admin/overview/users/user-edit/user-update.component.ts @@ -144,7 +144,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy { this.form.patchValue({ email: userJson.email, - role: userJson.role.toString(), + role: userJson.role.id.toString(), videoQuota: userJson.videoQuota, videoQuotaDaily: userJson.videoQuotaDaily, pluginAuth: userJson.pluginAuth, diff --git a/client/src/app/+admin/overview/users/user-list/user-list.component.html b/client/src/app/+admin/overview/users/user-list/user-list.component.html index c7af7dfae..a96ce561c 100644 --- a/client/src/app/+admin/overview/users/user-list/user-list.component.html +++ b/client/src/app/+admin/overview/users/user-list/user-list.component.html @@ -106,8 +106,8 @@ - {{ user.roleLabel }} - {{ user.roleLabel }} + {{ user.role.label }} + {{ user.role.label }} diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index a2ad4806c..f2488aa59 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts @@ -247,12 +247,12 @@ export class AppComponent implements OnInit, AfterViewInit { // Admin modal userSub.pipe( - filter(user => user.role === UserRole.ADMINISTRATOR) + filter(user => user.role.id === UserRole.ADMINISTRATOR) ).subscribe(user => this.openAdminModalsIfNeeded(user)) // Account modal userSub.pipe( - filter(user => user.role !== UserRole.ADMINISTRATOR) + filter(user => user.role.id !== UserRole.ADMINISTRATOR) ).subscribe(user => this.openAccountModalsIfNeeded(user)) } diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index a12325421..226075265 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -43,16 +43,16 @@ export class AuthUser extends User implements ServerMyUserModel { } hasRight (right: UserRight) { - return hasUserRight(this.role, right) + return hasUserRight(this.role.id, right) } canManage (user: ServerUserModel) { - const myRole = this.role + const myRole = this.role.id if (myRole === UserRole.ADMINISTRATOR) return true // I'm a moderator: I can only manage users - return user.role === UserRole.USER + return user.role.id === UserRole.USER } computeCanSeeVideosLink (quotaObservable: Observable): Observable { diff --git a/client/src/app/core/users/user-local-storage.service.ts b/client/src/app/core/users/user-local-storage.service.ts index f1588bdd2..a047efe8e 100644 --- a/client/src/app/core/users/user-local-storage.service.ts +++ b/client/src/app/core/users/user-local-storage.service.ts @@ -59,7 +59,10 @@ export class UserLocalStorageService { id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ID), 10), username: this.localStorageService.getItem(UserLocalStorageKeys.USERNAME), email: this.localStorageService.getItem(UserLocalStorageKeys.EMAIL), - role: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ROLE), 10) as UserRole, + role: { + id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ROLE), 10) as UserRole, + label: '' + }, ...this.getUserInfo() } @@ -69,12 +72,14 @@ export class UserLocalStorageService { id: number username: string email: string - role: UserRole + role: { + id: UserRole + } }) { this.localStorageService.setItem(UserLocalStorageKeys.ID, user.id.toString()) this.localStorageService.setItem(UserLocalStorageKeys.USERNAME, user.username) this.localStorageService.setItem(UserLocalStorageKeys.EMAIL, user.email) - this.localStorageService.setItem(UserLocalStorageKeys.ROLE, user.role.toString()) + this.localStorageService.setItem(UserLocalStorageKeys.ROLE, user.role.id.toString()) } flushLoggedInUser () { diff --git a/client/src/app/core/users/user.model.ts b/client/src/app/core/users/user.model.ts index 8385a4012..5534bca33 100644 --- a/client/src/app/core/users/user.model.ts +++ b/client/src/app/core/users/user.model.ts @@ -34,8 +34,10 @@ export class User implements UserServerModel { videosHistoryEnabled: boolean videoLanguages: string[] - role: UserRole - roleLabel: string + role: { + id: UserRole + label: string + } videoQuota: number videoQuotaDaily: number @@ -123,7 +125,7 @@ export class User implements UserServerModel { } hasRight (right: UserRight) { - return hasUserRight(this.role, right) + return hasUserRight(this.role.id, right) } patch (obj: UserServerModel) { @@ -148,6 +150,6 @@ export class User implements UserServerModel { isAutoBlocked (serverConfig: HTMLServerConfig) { if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false - return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST + return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST } } diff --git a/client/src/app/shared/shared-users/user-admin.service.ts b/client/src/app/shared/shared-users/user-admin.service.ts index 4128358dc..0b04023a3 100644 --- a/client/src/app/shared/shared-users/user-admin.service.ts +++ b/client/src/app/shared/shared-users/user-admin.service.ts @@ -125,7 +125,10 @@ export class UserAdminService { } return Object.assign(user, { - roleLabel: roleLabels[user.role], + role: { + id: user.role.id, + label: roleLabels[user.role.id] + }, videoQuota, videoQuotaUsed, rawVideoQuota: user.videoQuota, -- cgit v1.2.3