diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-27 16:55:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-27 16:55:03 +0200 |
commit | 954605a804da399317ca62afa2fb9244afa11ebf (patch) | |
tree | de6ee69280bfb928bc01c29430e13d5b820e921a /shared/models | |
parent | e02573ad67626210ed279bad321ee139094921a1 (diff) | |
download | PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.gz PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.tar.zst PeerTube-954605a804da399317ca62afa2fb9244afa11ebf.zip |
Support roles with rights and add moderator role
Diffstat (limited to 'shared/models')
-rw-r--r-- | shared/models/users/index.ts | 3 | ||||
-rw-r--r-- | shared/models/users/user-create.model.ts | 3 | ||||
-rw-r--r-- | shared/models/users/user-right.enum.ts | 10 | ||||
-rw-r--r-- | shared/models/users/user-role.ts | 36 | ||||
-rw-r--r-- | shared/models/users/user-role.type.ts | 1 | ||||
-rw-r--r-- | shared/models/users/user-update.model.ts | 3 | ||||
-rw-r--r-- | shared/models/users/user.model.ts | 2 |
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' | |||
4 | export * from './user-refresh-token.model' | 4 | export * from './user-refresh-token.model' |
5 | export * from './user-update.model' | 5 | export * from './user-update.model' |
6 | export * from './user-update-me.model' | 6 | export * from './user-update-me.model' |
7 | export * from './user-role.type' | 7 | export * from './user-right.enum' |
8 | export * 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 @@ | |||
1 | import { UserRole } from './user-role' | ||
2 | |||
1 | export interface UserCreate { | 3 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | import { UserRight } from './user-right.enum' | ||
2 | |||
3 | // Keep the order | ||
4 | export enum UserRole { | ||
5 | ADMINISTRATOR = 0, | ||
6 | MODERATOR = 1, | ||
7 | USER = 2 | ||
8 | } | ||
9 | |||
10 | export 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 | ||
17 | const 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 | |||
32 | export 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 @@ | |||
1 | export 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 @@ | |||
1 | import { UserRole } from './user-role' | ||
2 | |||
1 | export interface UserUpdate { | 3 | export 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 @@ | |||
1 | import { UserRole } from './user-role.type' | ||
2 | import { VideoChannel } from '../videos/video-channel.model' | 1 | import { VideoChannel } from '../videos/video-channel.model' |
2 | import { UserRole } from './user-role' | ||
3 | 3 | ||
4 | export interface User { | 4 | export interface User { |
5 | id: number | 5 | id: number |