aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-27 16:55:03 +0200
commit954605a804da399317ca62afa2fb9244afa11ebf (patch)
treede6ee69280bfb928bc01c29430e13d5b820e921a /shared
parente02573ad67626210ed279bad321ee139094921a1 (diff)
downloadPeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.gz
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.zst
PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.zip
Support roles with rights and add moderator role
Diffstat (limited to 'shared')
-rw-r--r--shared/models/users/index.ts3
-rw-r--r--shared/models/users/user-create.model.ts3
-rw-r--r--shared/models/users/user-right.enum.ts10
-rw-r--r--shared/models/users/user-role.ts36
-rw-r--r--shared/models/users/user-role.type.ts1
-rw-r--r--shared/models/users/user-update.model.ts3
-rw-r--r--shared/models/users/user.model.ts2
7 files changed, 55 insertions, 3 deletions
diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts
index efb58c320..a260bd380 100644
--- a/shared/models/users/index.ts
+++ b/shared/models/users/index.ts
@@ -4,4 +4,5 @@ export * from './user-login.model'
4export * from './user-refresh-token.model' 4export * from './user-refresh-token.model'
5export * from './user-update.model' 5export * from './user-update.model'
6export * from './user-update-me.model' 6export * from './user-update-me.model'
7export * from './user-role.type' 7export * from './user-right.enum'
8export * from './user-role'
diff --git a/shared/models/users/user-create.model.ts b/shared/models/users/user-create.model.ts
index 49fa2549d..65830f55e 100644
--- a/shared/models/users/user-create.model.ts
+++ b/shared/models/users/user-create.model.ts
@@ -1,6 +1,9 @@
1import { UserRole } from './user-role'
2
1export interface UserCreate { 3export interface UserCreate {
2 username: string 4 username: string
3 password: string 5 password: string
4 email: string 6 email: string
5 videoQuota: number 7 videoQuota: number
8 role: UserRole
6} 9}
diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts
new file mode 100644
index 000000000..c8c710450
--- /dev/null
+++ b/shared/models/users/user-right.enum.ts
@@ -0,0 +1,10 @@
1export enum UserRight {
2 ALL,
3 MANAGE_USERS,
4 MANAGE_PODS,
5 MANAGE_VIDEO_ABUSES,
6 MANAGE_REQUEST_SCHEDULERS,
7 MANAGE_VIDEO_BLACKLIST,
8 REMOVE_ANY_VIDEO,
9 REMOVE_ANY_VIDEO_CHANNEL,
10}
diff --git a/shared/models/users/user-role.ts b/shared/models/users/user-role.ts
new file mode 100644
index 000000000..cc32c768d
--- /dev/null
+++ b/shared/models/users/user-role.ts
@@ -0,0 +1,36 @@
1import { UserRight } from './user-right.enum'
2
3// Keep the order
4export enum UserRole {
5 ADMINISTRATOR = 0,
6 MODERATOR = 1,
7 USER = 2
8}
9
10export const USER_ROLE_LABELS = {
11 [UserRole.USER]: 'User',
12 [UserRole.MODERATOR]: 'Moderator',
13 [UserRole.ADMINISTRATOR]: 'Administrator'
14}
15
16// TODO: use UserRole for key once https://github.com/Microsoft/TypeScript/issues/13042 is fixed
17const userRoleRights: { [ id: number ]: UserRight[] } = {
18 [UserRole.ADMINISTRATOR]: [
19 UserRight.ALL
20 ],
21
22 [UserRole.MODERATOR]: [
23 UserRight.MANAGE_VIDEO_BLACKLIST,
24 UserRight.MANAGE_VIDEO_ABUSES,
25 UserRight.REMOVE_ANY_VIDEO,
26 UserRight.REMOVE_ANY_VIDEO_CHANNEL
27 ],
28
29 [UserRole.USER]: []
30}
31
32export function hasUserRight (userRole: UserRole, userRight: UserRight) {
33 const userRights = userRoleRights[userRole]
34
35 return userRights.indexOf(UserRight.ALL) !== -1 || userRights.indexOf(userRight) !== -1
36}
diff --git a/shared/models/users/user-role.type.ts b/shared/models/users/user-role.type.ts
deleted file mode 100644
index b38c4c8c3..000000000
--- a/shared/models/users/user-role.type.ts
+++ /dev/null
@@ -1 +0,0 @@
1export type UserRole = 'admin' | 'user'
diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts
index e22166fdc..96b454b7c 100644
--- a/shared/models/users/user-update.model.ts
+++ b/shared/models/users/user-update.model.ts
@@ -1,4 +1,7 @@
1import { UserRole } from './user-role'
2
1export interface UserUpdate { 3export interface UserUpdate {
2 email?: string 4 email?: string
3 videoQuota?: number 5 videoQuota?: number
6 role?: UserRole
4} 7}
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts
index 175e72f28..ee2147590 100644
--- a/shared/models/users/user.model.ts
+++ b/shared/models/users/user.model.ts
@@ -1,5 +1,5 @@
1import { UserRole } from './user-role.type'
2import { VideoChannel } from '../videos/video-channel.model' 1import { VideoChannel } from '../videos/video-channel.model'
2import { UserRole } from './user-role'
3 3
4export interface User { 4export interface User {
5 id: number 5 id: number