Breaking API: Consistency with role id/label
This commit is contained in:
parent
3f9decbd01
commit
9e5cf66be7
14 changed files with 55 additions and 38 deletions
|
@ -49,7 +49,7 @@ export abstract class UserEdit extends FormReactive implements OnInit {
|
||||||
buildRoles () {
|
buildRoles () {
|
||||||
const authUser = this.auth.getUser()
|
const authUser = this.auth.getUser()
|
||||||
|
|
||||||
if (authUser.role === UserRole.ADMINISTRATOR) {
|
if (authUser.role.id === UserRole.ADMINISTRATOR) {
|
||||||
this.roles = Object.keys(USER_ROLE_LABELS)
|
this.roles = Object.keys(USER_ROLE_LABELS)
|
||||||
.map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
|
.map(key => ({ value: key.toString(), label: USER_ROLE_LABELS[key] }))
|
||||||
return
|
return
|
||||||
|
|
|
@ -144,7 +144,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
|
||||||
|
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
email: userJson.email,
|
email: userJson.email,
|
||||||
role: userJson.role.toString(),
|
role: userJson.role.id.toString(),
|
||||||
videoQuota: userJson.videoQuota,
|
videoQuota: userJson.videoQuota,
|
||||||
videoQuotaDaily: userJson.videoQuotaDaily,
|
videoQuotaDaily: userJson.videoQuotaDaily,
|
||||||
pluginAuth: userJson.pluginAuth,
|
pluginAuth: userJson.pluginAuth,
|
||||||
|
|
|
@ -106,8 +106,8 @@
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td *ngIf="isSelected('role')">
|
<td *ngIf="isSelected('role')">
|
||||||
<span *ngIf="user.blocked" class="pt-badge badge-banned" i18n-title title="The user was banned">{{ user.roleLabel }}</span>
|
<span *ngIf="user.blocked" class="pt-badge badge-banned" i18n-title title="The user was banned">{{ user.role.label }}</span>
|
||||||
<span *ngIf="!user.blocked" class="pt-badge" [ngClass]="getRoleClass(user.role)">{{ user.roleLabel }}</span>
|
<span *ngIf="!user.blocked" class="pt-badge" [ngClass]="getRoleClass(user.role.id)">{{ user.role.label }}</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td *ngIf="isSelected('email')" [title]="user.email">
|
<td *ngIf="isSelected('email')" [title]="user.email">
|
||||||
|
|
|
@ -247,12 +247,12 @@ export class AppComponent implements OnInit, AfterViewInit {
|
||||||
|
|
||||||
// Admin modal
|
// Admin modal
|
||||||
userSub.pipe(
|
userSub.pipe(
|
||||||
filter(user => user.role === UserRole.ADMINISTRATOR)
|
filter(user => user.role.id === UserRole.ADMINISTRATOR)
|
||||||
).subscribe(user => this.openAdminModalsIfNeeded(user))
|
).subscribe(user => this.openAdminModalsIfNeeded(user))
|
||||||
|
|
||||||
// Account modal
|
// Account modal
|
||||||
userSub.pipe(
|
userSub.pipe(
|
||||||
filter(user => user.role !== UserRole.ADMINISTRATOR)
|
filter(user => user.role.id !== UserRole.ADMINISTRATOR)
|
||||||
).subscribe(user => this.openAccountModalsIfNeeded(user))
|
).subscribe(user => this.openAccountModalsIfNeeded(user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,16 @@ export class AuthUser extends User implements ServerMyUserModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRight (right: UserRight) {
|
hasRight (right: UserRight) {
|
||||||
return hasUserRight(this.role, right)
|
return hasUserRight(this.role.id, right)
|
||||||
}
|
}
|
||||||
|
|
||||||
canManage (user: ServerUserModel) {
|
canManage (user: ServerUserModel) {
|
||||||
const myRole = this.role
|
const myRole = this.role.id
|
||||||
|
|
||||||
if (myRole === UserRole.ADMINISTRATOR) return true
|
if (myRole === UserRole.ADMINISTRATOR) return true
|
||||||
|
|
||||||
// I'm a moderator: I can only manage users
|
// I'm a moderator: I can only manage users
|
||||||
return user.role === UserRole.USER
|
return user.role.id === UserRole.USER
|
||||||
}
|
}
|
||||||
|
|
||||||
computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> {
|
computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> {
|
||||||
|
|
|
@ -59,7 +59,10 @@ export class UserLocalStorageService {
|
||||||
id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ID), 10),
|
id: parseInt(this.localStorageService.getItem(UserLocalStorageKeys.ID), 10),
|
||||||
username: this.localStorageService.getItem(UserLocalStorageKeys.USERNAME),
|
username: this.localStorageService.getItem(UserLocalStorageKeys.USERNAME),
|
||||||
email: this.localStorageService.getItem(UserLocalStorageKeys.EMAIL),
|
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()
|
...this.getUserInfo()
|
||||||
}
|
}
|
||||||
|
@ -69,12 +72,14 @@ export class UserLocalStorageService {
|
||||||
id: number
|
id: number
|
||||||
username: string
|
username: string
|
||||||
email: string
|
email: string
|
||||||
role: UserRole
|
role: {
|
||||||
|
id: UserRole
|
||||||
|
}
|
||||||
}) {
|
}) {
|
||||||
this.localStorageService.setItem(UserLocalStorageKeys.ID, user.id.toString())
|
this.localStorageService.setItem(UserLocalStorageKeys.ID, user.id.toString())
|
||||||
this.localStorageService.setItem(UserLocalStorageKeys.USERNAME, user.username)
|
this.localStorageService.setItem(UserLocalStorageKeys.USERNAME, user.username)
|
||||||
this.localStorageService.setItem(UserLocalStorageKeys.EMAIL, user.email)
|
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 () {
|
flushLoggedInUser () {
|
||||||
|
|
|
@ -34,8 +34,10 @@ export class User implements UserServerModel {
|
||||||
videosHistoryEnabled: boolean
|
videosHistoryEnabled: boolean
|
||||||
videoLanguages: string[]
|
videoLanguages: string[]
|
||||||
|
|
||||||
role: UserRole
|
role: {
|
||||||
roleLabel: string
|
id: UserRole
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
videoQuota: number
|
videoQuota: number
|
||||||
videoQuotaDaily: number
|
videoQuotaDaily: number
|
||||||
|
@ -123,7 +125,7 @@ export class User implements UserServerModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
hasRight (right: UserRight) {
|
hasRight (right: UserRight) {
|
||||||
return hasUserRight(this.role, right)
|
return hasUserRight(this.role.id, right)
|
||||||
}
|
}
|
||||||
|
|
||||||
patch (obj: UserServerModel) {
|
patch (obj: UserServerModel) {
|
||||||
|
@ -148,6 +150,6 @@ export class User implements UserServerModel {
|
||||||
isAutoBlocked (serverConfig: HTMLServerConfig) {
|
isAutoBlocked (serverConfig: HTMLServerConfig) {
|
||||||
if (serverConfig.autoBlacklist.videos.ofUsers.enabled !== true) return false
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,10 @@ export class UserAdminService {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.assign(user, {
|
return Object.assign(user, {
|
||||||
roleLabel: roleLabels[user.role],
|
role: {
|
||||||
|
id: user.role.id,
|
||||||
|
label: roleLabels[user.role.id]
|
||||||
|
},
|
||||||
videoQuota,
|
videoQuota,
|
||||||
videoQuotaUsed,
|
videoQuotaUsed,
|
||||||
rawVideoQuota: user.videoQuota,
|
rawVideoQuota: user.videoQuota,
|
||||||
|
|
|
@ -891,8 +891,10 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
|
||||||
autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist,
|
autoPlayNextVideoPlaylist: this.autoPlayNextVideoPlaylist,
|
||||||
videoLanguages: this.videoLanguages,
|
videoLanguages: this.videoLanguages,
|
||||||
|
|
||||||
role: this.role,
|
role: {
|
||||||
roleLabel: USER_ROLE_LABELS[this.role],
|
id: this.role,
|
||||||
|
label: USER_ROLE_LABELS[this.role]
|
||||||
|
},
|
||||||
|
|
||||||
videoQuota: this.videoQuota,
|
videoQuota: this.videoQuota,
|
||||||
videoQuotaDaily: this.videoQuotaDaily,
|
videoQuotaDaily: this.videoQuotaDaily,
|
||||||
|
|
|
@ -219,7 +219,7 @@ describe('Test users', function () {
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
expect(user.email).to.equal('user_1@example.com')
|
||||||
expect(user.nsfwPolicy).to.equal('display')
|
expect(user.nsfwPolicy).to.equal('display')
|
||||||
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
||||||
expect(user.roleLabel).to.equal('User')
|
expect(user.role.label).to.equal('User')
|
||||||
expect(user.id).to.be.a('number')
|
expect(user.id).to.be.a('number')
|
||||||
expect(user.account.displayName).to.equal('user_1')
|
expect(user.account.displayName).to.equal('user_1')
|
||||||
expect(user.account.description).to.be.null
|
expect(user.account.description).to.be.null
|
||||||
|
@ -277,7 +277,7 @@ describe('Test users', function () {
|
||||||
const user = data[0]
|
const user = data[0]
|
||||||
expect(user.username).to.equal('root')
|
expect(user.username).to.equal('root')
|
||||||
expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
|
expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
|
||||||
expect(user.roleLabel).to.equal('Administrator')
|
expect(user.role.label).to.equal('Administrator')
|
||||||
expect(user.nsfwPolicy).to.equal('display')
|
expect(user.nsfwPolicy).to.equal('display')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -531,7 +531,7 @@ describe('Test users', function () {
|
||||||
expect(user.emailVerified).to.be.true
|
expect(user.emailVerified).to.be.true
|
||||||
expect(user.nsfwPolicy).to.equal('do_not_list')
|
expect(user.nsfwPolicy).to.equal('do_not_list')
|
||||||
expect(user.videoQuota).to.equal(42)
|
expect(user.videoQuota).to.equal(42)
|
||||||
expect(user.roleLabel).to.equal('Moderator')
|
expect(user.role.label).to.equal('Moderator')
|
||||||
expect(user.id).to.be.a('number')
|
expect(user.id).to.be.a('number')
|
||||||
expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
|
expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
|
||||||
expect(user.pluginAuth).to.equal('toto')
|
expect(user.pluginAuth).to.equal('toto')
|
||||||
|
|
|
@ -155,7 +155,7 @@ describe('Test external auth plugins', function () {
|
||||||
expect(body.username).to.equal('cyan')
|
expect(body.username).to.equal('cyan')
|
||||||
expect(body.account.displayName).to.equal('cyan')
|
expect(body.account.displayName).to.equal('cyan')
|
||||||
expect(body.email).to.equal('cyan@example.com')
|
expect(body.email).to.equal('cyan@example.com')
|
||||||
expect(body.role).to.equal(UserRole.USER)
|
expect(body.role.id).to.equal(UserRole.USER)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ describe('Test external auth plugins', function () {
|
||||||
expect(body.username).to.equal('kefka')
|
expect(body.username).to.equal('kefka')
|
||||||
expect(body.account.displayName).to.equal('Kefka Palazzo')
|
expect(body.account.displayName).to.equal('Kefka Palazzo')
|
||||||
expect(body.email).to.equal('kefka@example.com')
|
expect(body.email).to.equal('kefka@example.com')
|
||||||
expect(body.role).to.equal(UserRole.ADMINISTRATOR)
|
expect(body.role.id).to.equal(UserRole.ADMINISTRATOR)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ describe('Test external auth plugins', function () {
|
||||||
expect(body.username).to.equal('cyan')
|
expect(body.username).to.equal('cyan')
|
||||||
expect(body.account.displayName).to.equal('Cyan Garamonde')
|
expect(body.account.displayName).to.equal('Cyan Garamonde')
|
||||||
expect(body.account.description).to.equal('Retainer to the king of Doma')
|
expect(body.account.description).to.equal('Retainer to the king of Doma')
|
||||||
expect(body.role).to.equal(UserRole.USER)
|
expect(body.role.id).to.equal(UserRole.USER)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not update an external auth email', async function () {
|
it('Should not update an external auth email', async function () {
|
||||||
|
|
|
@ -48,7 +48,7 @@ describe('Test id and pass auth plugins', function () {
|
||||||
|
|
||||||
expect(body.username).to.equal('spyro')
|
expect(body.username).to.equal('spyro')
|
||||||
expect(body.account.displayName).to.equal('Spyro the Dragon')
|
expect(body.account.displayName).to.equal('Spyro the Dragon')
|
||||||
expect(body.role).to.equal(UserRole.USER)
|
expect(body.role.id).to.equal(UserRole.USER)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should login Crash, create the user and use the token', async function () {
|
it('Should login Crash, create the user and use the token', async function () {
|
||||||
|
@ -63,7 +63,7 @@ describe('Test id and pass auth plugins', function () {
|
||||||
|
|
||||||
expect(body.username).to.equal('crash')
|
expect(body.username).to.equal('crash')
|
||||||
expect(body.account.displayName).to.equal('Crash Bandicoot')
|
expect(body.account.displayName).to.equal('Crash Bandicoot')
|
||||||
expect(body.role).to.equal(UserRole.MODERATOR)
|
expect(body.role.id).to.equal(UserRole.MODERATOR)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ describe('Test id and pass auth plugins', function () {
|
||||||
|
|
||||||
expect(body.username).to.equal('laguna')
|
expect(body.username).to.equal('laguna')
|
||||||
expect(body.account.displayName).to.equal('laguna')
|
expect(body.account.displayName).to.equal('laguna')
|
||||||
expect(body.role).to.equal(UserRole.USER)
|
expect(body.role.id).to.equal(UserRole.USER)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ describe('Test id and pass auth plugins', function () {
|
||||||
expect(body.username).to.equal('crash')
|
expect(body.username).to.equal('crash')
|
||||||
expect(body.account.displayName).to.equal('Beautiful Crash')
|
expect(body.account.displayName).to.equal('Beautiful Crash')
|
||||||
expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
|
expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
|
||||||
expect(body.role).to.equal(UserRole.MODERATOR)
|
expect(body.role.id).to.equal(UserRole.MODERATOR)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should reject token of laguna by the plugin hook', async function () {
|
it('Should reject token of laguna by the plugin hook', async function () {
|
||||||
|
|
|
@ -28,8 +28,10 @@ export interface User {
|
||||||
videosHistoryEnabled: boolean
|
videosHistoryEnabled: boolean
|
||||||
videoLanguages: string[]
|
videoLanguages: string[]
|
||||||
|
|
||||||
role: UserRole
|
role: {
|
||||||
roleLabel: string
|
id: UserRole
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
videoQuota: number
|
videoQuota: number
|
||||||
videoQuotaDaily: number
|
videoQuotaDaily: number
|
||||||
|
|
|
@ -7522,13 +7522,16 @@ components:
|
||||||
nsfwPolicy:
|
nsfwPolicy:
|
||||||
$ref: '#/components/schemas/NSFWPolicy'
|
$ref: '#/components/schemas/NSFWPolicy'
|
||||||
role:
|
role:
|
||||||
$ref: '#/components/schemas/UserRole'
|
type: object
|
||||||
roleLabel:
|
properties:
|
||||||
type: string
|
id:
|
||||||
enum:
|
$ref: '#/components/schemas/UserRole'
|
||||||
- User
|
label:
|
||||||
- Moderator
|
type: string
|
||||||
- Administrator
|
enum:
|
||||||
|
- User
|
||||||
|
- Moderator
|
||||||
|
- Administrator
|
||||||
theme:
|
theme:
|
||||||
type: string
|
type: string
|
||||||
description: Theme enabled by this user
|
description: Theme enabled by this user
|
||||||
|
|
Loading…
Reference in a new issue