aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-17 09:21:02 +0200
committerChocobozzz <me@florianbigard.com>2023-04-17 09:21:02 +0200
commit208c97e111f2610880a588964bb61a03503cfcf6 (patch)
tree3ec04f25dec1411a284aa6e453d9e2cb460ce373 /client/src/app/shared
parent29ccdcb51f069d6a64744ffb216cb00ce4bf2d3d (diff)
downloadPeerTube-208c97e111f2610880a588964bb61a03503cfcf6.tar.gz
PeerTube-208c97e111f2610880a588964bb61a03503cfcf6.tar.zst
PeerTube-208c97e111f2610880a588964bb61a03503cfcf6.zip
Always translate user role
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/shared-users/user-admin.service.ts35
1 files changed, 18 insertions, 17 deletions
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 6224f0bd5..b18a36241 100644
--- a/client/src/app/shared/shared-users/user-admin.service.ts
+++ b/client/src/app/shared/shared-users/user-admin.service.ts
@@ -1,12 +1,12 @@
1import { SortMeta } from 'primeng/api' 1import { SortMeta } from 'primeng/api'
2import { from, Observable } from 'rxjs' 2import { from, Observable } from 'rxjs'
3import { catchError, concatMap, map, toArray } from 'rxjs/operators' 3import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
4import { HttpClient, HttpParams } from '@angular/common/http' 4import { HttpClient, HttpParams } from '@angular/common/http'
5import { Injectable } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { RestExtractor, RestPagination, RestService, UserService } from '@app/core' 6import { RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core'
7import { getBytes } from '@root-helpers/bytes' 7import { getBytes } from '@root-helpers/bytes'
8import { arrayify } from '@shared/core-utils' 8import { arrayify, peertubeTranslate } from '@shared/core-utils'
9import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate } from '@shared/models' 9import { ResultList, User as UserServerModel, UserCreate, UserUpdate } from '@shared/models'
10 10
11@Injectable() 11@Injectable()
12export class UserAdminService { 12export class UserAdminService {
@@ -14,7 +14,8 @@ export class UserAdminService {
14 constructor ( 14 constructor (
15 private authHttp: HttpClient, 15 private authHttp: HttpClient,
16 private restExtractor: RestExtractor, 16 private restExtractor: RestExtractor,
17 private restService: RestService 17 private restService: RestService,
18 private serverService: ServerService
18 ) { } 19 ) { }
19 20
20 addUser (userCreate: UserCreate) { 21 addUser (userCreate: UserCreate) {
@@ -58,10 +59,16 @@ export class UserAdminService {
58 } 59 }
59 60
60 return this.authHttp.get<ResultList<UserServerModel>>(UserService.BASE_USERS_URL, { params }) 61 return this.authHttp.get<ResultList<UserServerModel>>(UserService.BASE_USERS_URL, { params })
61 .pipe( 62 .pipe(
62 map(res => this.restExtractor.applyToResultListData(res, this.formatUser.bind(this))), 63 switchMap(data => {
63 catchError(err => this.restExtractor.handleError(err)) 64 return this.serverService.getServerLocale()
64 ) 65 .pipe(map(translations => ({ data, translations })))
66 }),
67 map(({ data, translations }) => {
68 return this.restExtractor.applyToResultListData(data, this.formatUser.bind(this), [translations])
69 }),
70 catchError(err => this.restExtractor.handleError(err))
71 )
65 } 72 }
66 73
67 removeUsers (usersArg: UserServerModel | UserServerModel[]) { 74 removeUsers (usersArg: UserServerModel | UserServerModel[]) {
@@ -98,7 +105,7 @@ export class UserAdminService {
98 ) 105 )
99 } 106 }
100 107
101 private formatUser (user: UserServerModel) { 108 private formatUser (user: UserServerModel, translations: { [ id: string ]: string } = {}) {
102 let videoQuota 109 let videoQuota
103 if (user.videoQuota === -1) { 110 if (user.videoQuota === -1) {
104 videoQuota = '∞' 111 videoQuota = '∞'
@@ -118,16 +125,10 @@ export class UserAdminService {
118 videoQuotaUsedDaily = getBytes(user.videoQuotaUsedDaily || 0, 0) + '' 125 videoQuotaUsedDaily = getBytes(user.videoQuotaUsedDaily || 0, 0) + ''
119 } 126 }
120 127
121 const roleLabels: { [ id in UserRole ]: string } = {
122 [UserRole.USER]: $localize`User`,
123 [UserRole.ADMINISTRATOR]: $localize`Administrator`,
124 [UserRole.MODERATOR]: $localize`Moderator`
125 }
126
127 return Object.assign(user, { 128 return Object.assign(user, {
128 role: { 129 role: {
129 id: user.role.id, 130 id: user.role.id,
130 label: roleLabels[user.role.id] 131 label: peertubeTranslate(user.role.label, translations)
131 }, 132 },
132 videoQuota, 133 videoQuota,
133 videoQuotaUsed, 134 videoQuotaUsed,