aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/users/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/users/users.ts')
-rw-r--r--shared/utils/users/users.ts33
1 files changed, 25 insertions, 8 deletions
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 '..
4import { UserRole } from '../../index' 4import { UserRole } from '../../index'
5import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type' 5import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
6import { ServerInfo, userLogin } from '..' 6import { ServerInfo, userLogin } from '..'
7import { UserAdminFlag } from '../../models/users/user-flag.model'
7 8
8function createUser ( 9type 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}
19function 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
36async function generateUserAccessToken (server: ServerInfo, username: string) { 51async 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,