aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-10-28 16:15:04 +0200
committerChocobozzz <me@florianbigard.com>2022-10-28 16:34:08 +0200
commit9e5cf66be7ad897e106f283bee73a165c72e74de (patch)
tree16de6f775c412281236b8f99be8e5118e5a6ff71 /client/src/app
parent3f9decbd01d25f1b1805e2764dff4beae7d36c19 (diff)
downloadPeerTube-9e5cf66be7ad897e106f283bee73a165c72e74de.tar.gz
PeerTube-9e5cf66be7ad897e106f283bee73a165c72e74de.tar.zst
PeerTube-9e5cf66be7ad897e106f283bee73a165c72e74de.zip
Breaking API: Consistency with role id/label
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-edit.ts2
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-update.component.ts2
-rw-r--r--client/src/app/+admin/overview/users/user-list/user-list.component.html4
-rw-r--r--client/src/app/app.component.ts4
-rw-r--r--client/src/app/core/auth/auth-user.model.ts6
-rw-r--r--client/src/app/core/users/user-local-storage.service.ts11
-rw-r--r--client/src/app/core/users/user.model.ts10
-rw-r--r--client/src/app/shared/shared-users/user-admin.service.ts5
8 files changed, 27 insertions, 17 deletions
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 {
49 buildRoles () { 49 buildRoles () {
50 const authUser = this.auth.getUser() 50 const authUser = this.auth.getUser()
51 51
52 if (authUser.role === UserRole.ADMINISTRATOR) { 52 if (authUser.role.id === UserRole.ADMINISTRATOR) {
53 this.roles = Object.keys(USER_ROLE_LABELS) 53 this.roles = Object.keys(USER_ROLE_LABELS)
54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) 54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
55 return 55 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 {
144 144
145 this.form.patchValue({ 145 this.form.patchValue({
146 email: userJson.email, 146 email: userJson.email,
147 role: userJson.role.toString(), 147 role: userJson.role.id.toString(),
148 videoQuota: userJson.videoQuota, 148 videoQuota: userJson.videoQuota,
149 videoQuotaDaily: userJson.videoQuotaDaily, 149 videoQuotaDaily: userJson.videoQuotaDaily,
150 pluginAuth: userJson.pluginAuth, 150 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 @@
106 </td> 106 </td>
107 107
108 <td *ngIf="isSelected('role')"> 108 <td *ngIf="isSelected('role')">
109 <span *ngIf="user.blocked" class="pt-badge badge-banned" i18n-title title="The user was banned">{{ user.roleLabel }}</span> 109 <span *ngIf="user.blocked" class="pt-badge badge-banned" i18n-title title="The user was banned">{{ user.role.label }}</span>
110 <span *ngIf="!user.blocked" class="pt-badge" [ngClass]="getRoleClass(user.role)">{{ user.roleLabel }}</span> 110 <span *ngIf="!user.blocked" class="pt-badge" [ngClass]="getRoleClass(user.role.id)">{{ user.role.label }}</span>
111 </td> 111 </td>
112 112
113 <td *ngIf="isSelected('email')" [title]="user.email"> 113 <td *ngIf="isSelected('email')" [title]="user.email">
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 {
247 247
248 // Admin modal 248 // Admin modal
249 userSub.pipe( 249 userSub.pipe(
250 filter(user => user.role === UserRole.ADMINISTRATOR) 250 filter(user => user.role.id === UserRole.ADMINISTRATOR)
251 ).subscribe(user => this.openAdminModalsIfNeeded(user)) 251 ).subscribe(user => this.openAdminModalsIfNeeded(user))
252 252
253 // Account modal 253 // Account modal
254 userSub.pipe( 254 userSub.pipe(
255 filter(user => user.role !== UserRole.ADMINISTRATOR) 255 filter(user => user.role.id !== UserRole.ADMINISTRATOR)
256 ).subscribe(user => this.openAccountModalsIfNeeded(user)) 256 ).subscribe(user => this.openAccountModalsIfNeeded(user))
257 } 257 }
258 258
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 {
43 } 43 }
44 44
45 hasRight (right: UserRight) { 45 hasRight (right: UserRight) {
46 return hasUserRight(this.role, right) 46 return hasUserRight(this.role.id, right)
47 } 47 }
48 48
49 canManage (user: ServerUserModel) { 49 canManage (user: ServerUserModel) {
50 const myRole = this.role 50 const myRole = this.role.id
51 51
52 if (myRole === UserRole.ADMINISTRATOR) return true 52 if (myRole === UserRole.ADMINISTRATOR) return true
53 53
54 // I'm a moderator: I can only manage users 54 // I'm a moderator: I can only manage users
55 return user.role === UserRole.USER 55 return user.role.id === UserRole.USER
56 } 56 }
57 57
58 computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> { 58 computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> {
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 {
59 id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ID), 10), 59 id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ID), 10),
60 username: this.localStorageService.getItem(UserLocalStorageKeys.USERNAME), 60 username: this.localStorageService.getItem(UserLocalStorageKeys.USERNAME),
61 email: this.localStorageService.getItem(UserLocalStorageKeys.EMAIL), 61 email: this.localStorageService.getItem(UserLocalStorageKeys.EMAIL),
62 role: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ROLE), 10) as UserRole, 62 role: {
63 id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ROLE), 10) as UserRole,
64 label: ''
65 },
63 66
64 ...this.getUserInfo() 67 ...this.getUserInfo()
65 } 68 }
@@ -69,12 +72,14 @@ export class UserLocalStorageService {
69 id: number 72 id: number
70 username: string 73 username: string
71 email: string 74 email: string
72 role: UserRole 75 role: {
76 id: UserRole
77 }
73 }) { 78 }) {
74 this.localStorageService.setItem(UserLocalStorageKeys.ID, user.id.toString()) 79 this.localStorageService.setItem(UserLocalStorageKeys.ID, user.id.toString())
75 this.localStorageService.setItem(UserLocalStorageKeys.USERNAME, user.username) 80 this.localStorageService.setItem(UserLocalStorageKeys.USERNAME, user.username)
76 this.localStorageService.setItem(UserLocalStorageKeys.EMAIL, user.email) 81 this.localStorageService.setItem(UserLocalStorageKeys.EMAIL, user.email)
77 this.localStorageService.setItem(UserLocalStorageKeys.ROLE, user.role.toString()) 82 this.localStorageService.setItem(UserLocalStorageKeys.ROLE, user.role.id.toString())
78 } 83 }
79 84
80 flushLoggedInUser () { 85 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 {
34 videosHistoryEnabled: boolean 34 videosHistoryEnabled: boolean
35 videoLanguages: string[] 35 videoLanguages: string[]
36 36
37 role: UserRole 37 role: {
38 roleLabel: string 38 id: UserRole
39 label: string
40 }
39 41
40 videoQuota: number 42 videoQuota: number
41 videoQuotaDaily: number 43 videoQuotaDaily: number
@@ -123,7 +125,7 @@ export class User implements UserServerModel {
123 } 125 }
124 126
125 hasRight (right: UserRight) { 127 hasRight (right: UserRight) {
126 return hasUserRight(this.role, right) 128 return hasUserRight(this.role.id, right)
127 } 129 }
128 130
129 patch (obj: UserServerModel) { 131 patch (obj: UserServerModel) {
@@ -148,6 +150,6 @@ export class User implements UserServerModel {
148 isAutoBlocked (serverConfig: HTMLServerConfig) { 150 isAutoBlocked (serverConfig: HTMLServerConfig) {
149 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false 151 if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
150 152
151 return this.role === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST 153 return this.role.id === UserRole.USER && this.adminFlags !== UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
152 } 154 }
153} 155}
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 {
125 } 125 }
126 126
127 return Object.assign(user, { 127 return Object.assign(user, {
128 roleLabel: roleLabels[user.role], 128 role: {
129 id: user.role.id,
130 label: roleLabels[user.role.id]
131 },
129 videoQuota, 132 videoQuota,
130 videoQuotaUsed, 133 videoQuotaUsed,
131 rawVideoQuota: user.videoQuota, 134 rawVideoQuota: user.videoQuota,