diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/models/users/user-create.model.ts | 2 | ||||
-rw-r--r-- | shared/models/users/user-flag.model.ts | 4 | ||||
-rw-r--r-- | shared/models/users/user-update.model.ts | 2 | ||||
-rw-r--r-- | shared/models/users/user.model.ts | 5 | ||||
-rw-r--r-- | shared/utils/users/users.ts | 33 | ||||
-rw-r--r-- | shared/utils/videos/video-blacklist.ts | 51 |
6 files changed, 56 insertions, 41 deletions
diff --git a/shared/models/users/user-create.model.ts b/shared/models/users/user-create.model.ts index 08be4db05..6677b42aa 100644 --- a/shared/models/users/user-create.model.ts +++ b/shared/models/users/user-create.model.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { UserRole } from './user-role' | 1 | import { UserRole } from './user-role' |
2 | import { UserAdminFlag } from './user-flag.model' | ||
2 | 3 | ||
3 | export interface UserCreate { | 4 | export interface UserCreate { |
4 | username: string | 5 | username: string |
@@ -7,4 +8,5 @@ export interface UserCreate { | |||
7 | videoQuota: number | 8 | videoQuota: number |
8 | videoQuotaDaily: number | 9 | videoQuotaDaily: number |
9 | role: UserRole | 10 | role: UserRole |
11 | adminFlags?: UserAdminFlag | ||
10 | } | 12 | } |
diff --git a/shared/models/users/user-flag.model.ts b/shared/models/users/user-flag.model.ts new file mode 100644 index 000000000..f5759f18f --- /dev/null +++ b/shared/models/users/user-flag.model.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export enum UserAdminFlag { | ||
2 | NONE = 0, | ||
3 | BY_PASS_VIDEO_AUTO_BLACKLIST = 1 << 0 | ||
4 | } | ||
diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts index cd215bab3..fa43487ac 100644 --- a/shared/models/users/user-update.model.ts +++ b/shared/models/users/user-update.model.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { UserRole } from './user-role' | 1 | import { UserRole } from './user-role' |
2 | import { UserAdminFlag } from './user-flag.model' | ||
2 | 3 | ||
3 | export interface UserUpdate { | 4 | export interface UserUpdate { |
4 | password?: string | 5 | password?: string |
@@ -7,4 +8,5 @@ export interface UserUpdate { | |||
7 | videoQuota?: number | 8 | videoQuota?: number |
8 | videoQuotaDaily?: number | 9 | videoQuotaDaily?: number |
9 | role?: UserRole | 10 | role?: UserRole |
11 | adminFlags?: UserAdminFlag | ||
10 | } | 12 | } |
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts index af783d389..2f6a3c719 100644 --- a/shared/models/users/user.model.ts +++ b/shared/models/users/user.model.ts | |||
@@ -3,6 +3,7 @@ import { VideoChannel } from '../videos/channel/video-channel.model' | |||
3 | import { UserRole } from './user-role' | 3 | import { UserRole } from './user-role' |
4 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' | 4 | import { NSFWPolicyType } from '../videos/nsfw-policy.type' |
5 | import { UserNotificationSetting } from './user-notification-setting.model' | 5 | import { UserNotificationSetting } from './user-notification-setting.model' |
6 | import { UserAdminFlag } from './user-flag.model' | ||
6 | 7 | ||
7 | export interface User { | 8 | export interface User { |
8 | id: number | 9 | id: number |
@@ -11,11 +12,15 @@ export interface User { | |||
11 | emailVerified: boolean | 12 | emailVerified: boolean |
12 | nsfwPolicy: NSFWPolicyType | 13 | nsfwPolicy: NSFWPolicyType |
13 | 14 | ||
15 | adminFlags?: UserAdminFlag | ||
16 | |||
14 | autoPlayVideo: boolean | 17 | autoPlayVideo: boolean |
15 | webTorrentEnabled: boolean | 18 | webTorrentEnabled: boolean |
16 | videosHistoryEnabled: boolean | 19 | videosHistoryEnabled: boolean |
17 | 20 | ||
18 | role: UserRole | 21 | role: UserRole |
22 | roleLabel: string | ||
23 | |||
19 | videoQuota: number | 24 | videoQuota: number |
20 | videoQuotaDaily: number | 25 | videoQuotaDaily: number |
21 | createdAt: Date | 26 | createdAt: Date |
diff --git a/shared/utils/users/users.ts b/shared/utils/users/users.ts index e3c14a4a3..2bd37b8be 100644 --- a/shared/utils/users/users.ts +++ b/shared/utils/users/users.ts | |||
@@ -4,22 +4,37 @@ import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '.. | |||
4 | import { UserRole } from '../../index' | 4 | import { UserRole } from '../../index' |
5 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' | 5 | import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' |
6 | import { ServerInfo, userLogin } from '..' | 6 | import { ServerInfo, userLogin } from '..' |
7 | import { UserAdminFlag } from '../../models/users/user-flag.model' | ||
7 | 8 | ||
8 | function createUser ( | 9 | type CreateUserArgs = { url: string, |
9 | url: string, | ||
10 | accessToken: string, | 10 | accessToken: string, |
11 | username: string, | 11 | username: string, |
12 | password: string, | 12 | password: string, |
13 | videoQuota = 1000000, | 13 | videoQuota?: number, |
14 | videoQuotaDaily = -1, | 14 | videoQuotaDaily?: number, |
15 | role: UserRole = UserRole.USER, | 15 | role?: UserRole, |
16 | specialStatus = 200 | 16 | adminFlags?: UserAdminFlag, |
17 | ) { | 17 | specialStatus?: number |
18 | } | ||
19 | function createUser (parameters: CreateUserArgs) { | ||
20 | const { | ||
21 | url, | ||
22 | accessToken, | ||
23 | username, | ||
24 | adminFlags, | ||
25 | password = 'password', | ||
26 | videoQuota = 1000000, | ||
27 | videoQuotaDaily = -1, | ||
28 | role = UserRole.USER, | ||
29 | specialStatus = 200 | ||
30 | } = parameters | ||
31 | |||
18 | const path = '/api/v1/users' | 32 | const path = '/api/v1/users' |
19 | const body = { | 33 | const body = { |
20 | username, | 34 | username, |
21 | password, | 35 | password, |
22 | role, | 36 | role, |
37 | adminFlags, | ||
23 | email: username + '@example.com', | 38 | email: username + '@example.com', |
24 | videoQuota, | 39 | videoQuota, |
25 | videoQuotaDaily | 40 | videoQuotaDaily |
@@ -35,7 +50,7 @@ function createUser ( | |||
35 | 50 | ||
36 | async function generateUserAccessToken (server: ServerInfo, username: string) { | 51 | async function generateUserAccessToken (server: ServerInfo, username: string) { |
37 | const password = 'my super password' | 52 | const password = 'my super password' |
38 | await createUser(server.url, server.accessToken, username, password) | 53 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
39 | 54 | ||
40 | return userLogin(server, { username, password }) | 55 | return userLogin(server, { username, password }) |
41 | } | 56 | } |
@@ -222,6 +237,7 @@ function updateUser (options: { | |||
222 | videoQuota?: number, | 237 | videoQuota?: number, |
223 | videoQuotaDaily?: number, | 238 | videoQuotaDaily?: number, |
224 | password?: string, | 239 | password?: string, |
240 | adminFlags?: UserAdminFlag, | ||
225 | role?: UserRole | 241 | role?: UserRole |
226 | }) { | 242 | }) { |
227 | const path = '/api/v1/users/' + options.userId | 243 | const path = '/api/v1/users/' + options.userId |
@@ -233,6 +249,7 @@ function updateUser (options: { | |||
233 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota | 249 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota |
234 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily | 250 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily |
235 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role | 251 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role |
252 | if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags | ||
236 | 253 | ||
237 | return makePutBodyRequest({ | 254 | return makePutBodyRequest({ |
238 | url: options.url, | 255 | url: options.url, |
diff --git a/shared/utils/videos/video-blacklist.ts b/shared/utils/videos/video-blacklist.ts index 82d5b7e31..e25a292fc 100644 --- a/shared/utils/videos/video-blacklist.ts +++ b/shared/utils/videos/video-blacklist.ts | |||
@@ -1,4 +1,6 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { VideoBlacklistType } from '../../models/videos' | ||
3 | import { makeGetRequest } from '..' | ||
2 | 4 | ||
3 | function addVideoToBlacklist ( | 5 | function addVideoToBlacklist ( |
4 | url: string, | 6 | url: string, |
@@ -39,40 +41,25 @@ function removeVideoFromBlacklist (url: string, token: string, videoId: number | | |||
39 | .expect(specialStatus) | 41 | .expect(specialStatus) |
40 | } | 42 | } |
41 | 43 | ||
42 | function getBlacklistedVideosList (url: string, token: string, specialStatus = 200) { | 44 | function getBlacklistedVideosList (parameters: { |
45 | url: string, | ||
46 | token: string, | ||
47 | sort?: string, | ||
48 | type?: VideoBlacklistType, | ||
49 | specialStatus?: number | ||
50 | }) { | ||
51 | let { url, token, sort, type, specialStatus = 200 } = parameters | ||
43 | const path = '/api/v1/videos/blacklist/' | 52 | const path = '/api/v1/videos/blacklist/' |
44 | 53 | ||
45 | return request(url) | 54 | const query = { sort, type } |
46 | .get(path) | ||
47 | .query({ sort: 'createdAt' }) | ||
48 | .set('Accept', 'application/json') | ||
49 | .set('Authorization', 'Bearer ' + token) | ||
50 | .expect(specialStatus) | ||
51 | .expect('Content-Type', /json/) | ||
52 | } | ||
53 | |||
54 | function getBlacklistedVideosListWithTypeFilter (url: string, token: string, type: number, specialStatus = 200) { | ||
55 | const path = '/api/v1/videos/blacklist/' | ||
56 | 55 | ||
57 | return request(url) | 56 | return makeGetRequest({ |
58 | .get(path) | 57 | url, |
59 | .query({ sort: 'createdAt', type }) | 58 | path, |
60 | .set('Accept', 'application/json') | 59 | query, |
61 | .set('Authorization', 'Bearer ' + token) | 60 | token, |
62 | .expect(specialStatus) | 61 | statusCodeExpected: specialStatus |
63 | .expect('Content-Type', /json/) | 62 | }) |
64 | } | ||
65 | |||
66 | function getSortedBlacklistedVideosList (url: string, token: string, sort: string, specialStatus = 200) { | ||
67 | const path = '/api/v1/videos/blacklist/' | ||
68 | |||
69 | return request(url) | ||
70 | .get(path) | ||
71 | .query({ sort: sort }) | ||
72 | .set('Accept', 'application/json') | ||
73 | .set('Authorization', 'Bearer ' + token) | ||
74 | .expect(specialStatus) | ||
75 | .expect('Content-Type', /json/) | ||
76 | } | 63 | } |
77 | 64 | ||
78 | // --------------------------------------------------------------------------- | 65 | // --------------------------------------------------------------------------- |
@@ -81,7 +68,5 @@ export { | |||
81 | addVideoToBlacklist, | 68 | addVideoToBlacklist, |
82 | removeVideoFromBlacklist, | 69 | removeVideoFromBlacklist, |
83 | getBlacklistedVideosList, | 70 | getBlacklistedVideosList, |
84 | getBlacklistedVideosListWithTypeFilter, | ||
85 | getSortedBlacklistedVideosList, | ||
86 | updateVideoBlacklist | 71 | updateVideoBlacklist |
87 | } | 72 | } |