Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | 3x 3x 2x 6x 1x 1x 9x 9x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 2x 2x 13x 13x 2x 2x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x | // @flow import { prune } from '../../utils/objects'; import { into, type AccountProfile as AdminUser } from '../account/profile'; import { type Caller } from '.'; /** * A description of a user. */ export type { AdminUser }; /** * Values for updating a user. */ export type AdminUserUpdateValues = { email?: string, name?: string, }; /** * Values for creating a new user. */ export type AdminUserCreateValues = { email: string, password: string, username: string, department?: number, name?: string, }; /** * User API keys. */ export type AdminUserKeys = { apiKey: string, secretKey: string, }; export type AdminUserKeysParams = { username?: string, uuid?: string, }; /** * Manage your users. */ export interface AdminUsersAPI { list(): Promise<Array<AdminUser>>; get(username: string): Promise<AdminUser>; keys(values: AdminUserKeysParams): Promise<AdminUserKeys>; create(values: AdminUserCreateValues): Promise<AdminUser>; update(username: string, values: AdminUserUpdateValues): Promise<AdminUser>; changePassword(username: string, newPassword: string): Promise<AdminUser>; enable(username: string): Promise<AdminUser>; disable(username: string): Promise<AdminUser>; addSuperAdmin(username: string): Promise<AdminUser>; removeSuperAdmin(username: string): Promise<AdminUser>; delete(username: string): Promise<number>; } export { into }; function intoCreateValues({ email, department, name, password, username, }: AdminUserCreateValues): mixed { return prune({ email, password, username, fullName: name, resellerId: department, }); } function intoUpdateValues({ email, name }: AdminUserUpdateValues): mixed { return prune({ email, full_name: name, }); } export function gqConsoleUsers(call: Caller): AdminUsersAPI { async function list() { const objects = await call('GET', 'account/simple_user_list'); return objects.map(into); } async function get(username) { const user = await call('GET', 'account/user', { params: { username }, }); return into(user); } async function keys(params) { const result = await call('GET', 'account-keys/get_user_keys', { params, }); return { apiKey: result.api_public_key, secretKey: result.api_private_key }; } async function create(values) { const data = intoCreateValues(values); const user = await call('POST', 'account', { data }); return into(user); } async function update(username, values) { const { id } = await get(username); const data = intoUpdateValues(values); await call('PUT', `account/${id}`, { data }); return get(username); } async function changePassword(username, newPassword) { return call('PUT', `account/change_password_admin`, { data: { username, password1: newPassword }, }); } async function enable(username) { return call('GET', 'account/enable_user', { params: { username } }); } async function disable(username) { return call('GET', 'account/disable_user', { params: { username } }); } async function addSuperAdmin(username) { const { id } = await get(username); return call('POST', `accounts/${id}/superuser/enable`, { version: '' }); } async function removeSuperAdmin(username) { const { id } = await get(username); return call('POST', `accounts/${id}/superuser/disable`, { version: '' }); } async function remove(username) { const { id } = await get(username); await call('DELETE', `account/${id}`); return id; } return { list, get, keys, create, update, changePassword, enable, disable, addSuperAdmin, removeSuperAdmin, delete: remove, }; } export function users(call: Caller): AdminUsersAPI { async function list() { const objects = await call('GET', 'simple_user_list'); return objects.map(into); } async function get(username) { const user = await call('GET', 'account/user', { params: { username }, }); return into(user); } async function keys(params) { const result = await call('GET', 'account-keys/get_user_keys', { params, }); return { apiKey: result.api_public_key, secretKey: result.api_private_key }; } async function create(values) { const data = intoCreateValues(values); const user = await call('POST', 'accounts', { data }); return into(user); } async function update(username, values) { const { id } = await get(username); const data = intoUpdateValues(values); await call('PUT', `accounts/${id}`, { data }); return get(username); } async function changePassword(username, newPassword) { const { id } = await get(username); return call('PUT', `accounts/${id}/password_admin`, { data: { password1: newPassword }, }); } async function enable(username) { const { id } = await get(username); return call('PUT', `accounts/${id}/status/enabled`); } async function disable(username) { const { id } = await get(username); return call('DELETE', `accounts/${id}/status/enabled`); } async function addSuperAdmin(username) { const { id } = await get(username); return call('PUT', `accounts/${id}/superuser`); } async function removeSuperAdmin(username) { const { id } = await get(username); return call('DELETE', `accounts/${id}/superuser`); } async function remove(username) { const { id } = await get(username); await call('DELETE', `accounts/${id}`); return id; } return { list, get, keys, create, update, changePassword, enable, disable, addSuperAdmin, removeSuperAdmin, delete: remove, }; } |