aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
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
parent29ccdcb51f069d6a64744ffb216cb00ce4bf2d3d (diff)
downloadPeerTube-208c97e111f2610880a588964bb61a03503cfcf6.tar.gz
PeerTube-208c97e111f2610880a588964bb61a03503cfcf6.tar.zst
PeerTube-208c97e111f2610880a588964bb61a03503cfcf6.zip
Always translate user role
Diffstat (limited to 'client')
-rw-r--r--client/src/app/+admin/overview/users/user-edit/user-edit.ts24
-rw-r--r--client/src/app/core/server/server.service.ts2
-rw-r--r--client/src/app/shared/shared-users/user-admin.service.ts35
3 files changed, 33 insertions, 28 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 1edca7fbf..5d6c6a91e 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
@@ -2,6 +2,7 @@ import { Directive, OnInit } from '@angular/core'
2import { ConfigService } from '@app/+admin/config/shared/config.service' 2import { ConfigService } from '@app/+admin/config/shared/config.service'
3import { AuthService, ScreenService, ServerService, User } from '@app/core' 3import { AuthService, ScreenService, ServerService, User } from '@app/core'
4import { FormReactive } from '@app/shared/shared-forms' 4import { FormReactive } from '@app/shared/shared-forms'
5import { peertubeTranslate } from '@shared/core-utils'
5import { USER_ROLE_LABELS } from '@shared/core-utils/users' 6import { USER_ROLE_LABELS } from '@shared/core-utils/users'
6import { HTMLServerConfig, UserAdminFlag, UserRole } from '@shared/models' 7import { HTMLServerConfig, UserAdminFlag, UserRole } from '@shared/models'
7import { SelectOptionsItem } from '../../../../../types/select-options-item.model' 8import { SelectOptionsItem } from '../../../../../types/select-options-item.model'
@@ -25,7 +26,7 @@ export abstract class UserEdit extends FormReactive implements OnInit {
25 abstract isCreation (): boolean 26 abstract isCreation (): boolean
26 abstract getFormButtonTitle (): string 27 abstract getFormButtonTitle (): string
27 28
28 ngOnInit (): void { 29 ngOnInit () {
29 this.serverConfig = this.serverService.getHTMLConfig() 30 this.serverConfig = this.serverService.getHTMLConfig()
30 31
31 this.buildRoles() 32 this.buildRoles()
@@ -49,15 +50,18 @@ export abstract class UserEdit extends FormReactive implements OnInit {
49 buildRoles () { 50 buildRoles () {
50 const authUser = this.auth.getUser() 51 const authUser = this.auth.getUser()
51 52
52 if (authUser.role.id === UserRole.ADMINISTRATOR) { 53 this.serverService.getServerLocale()
53 this.roles = Object.keys(USER_ROLE_LABELS) 54 .subscribe(translations => {
54 .map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] })) 55 if (authUser.role.id === UserRole.ADMINISTRATOR) {
55 return 56 this.roles = Object.keys(USER_ROLE_LABELS)
56 } 57 .map(key => ({ value: key.toString(), label: peertubeTranslate(USER_ROLE_LABELS[key], translations) }))
57 58 return
58 this.roles = [ 59 }
59 { value: UserRole.USER.toString(), label: USER_ROLE_LABELS[UserRole.USER] } 60
60 ] 61 this.roles = [
62 { value: UserRole.USER.toString(), label: peertubeTranslate(USER_ROLE_LABELS[UserRole.USER], translations) }
63 ]
64 })
61 } 65 }
62 66
63 displayDangerZone () { 67 displayDangerZone () {
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts
index 0829d87d5..9f191f0a6 100644
--- a/client/src/app/core/server/server.service.ts
+++ b/client/src/app/core/server/server.service.ts
@@ -137,7 +137,7 @@ export class ServerService {
137 return this.videoPlaylistPrivaciesObservable.pipe(first()) 137 return this.videoPlaylistPrivaciesObservable.pipe(first())
138 } 138 }
139 139
140 getServerLocale () { 140 getServerLocale (): Observable<{ [ id: string ]: string }> {
141 if (!this.localeObservable) { 141 if (!this.localeObservable) {
142 const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId) 142 const completeLocale = isOnDevLocale() ? getDevLocale() : getCompleteLocale(this.localeId)
143 143
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,