This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/api/Users.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-02-19 17:43:57 +00:00
import { DefaultClient, AKResponse, QueryArguments } from "./Client";
let _globalMePromise: Promise<User>;
export class User {
pk: number;
username: string;
name: string;
is_superuser: boolean;
email: boolean;
avatar: string;
2021-02-19 17:43:57 +00:00
is_active: boolean;
last_login: number;
constructor() {
throw Error();
}
2021-02-19 17:43:57 +00:00
static get(pk: string): Promise<User> {
return DefaultClient.fetch<User>(["core", "users", pk]);
}
static list(filter?: QueryArguments): Promise<AKResponse<User>> {
return DefaultClient.fetch<AKResponse<User>>(["core", "users"], filter);
}
static adminUrl(rest: string): string {
return `/administration/users/${rest}`;
}
static me(): Promise<User> {
if (!_globalMePromise) {
_globalMePromise = DefaultClient.fetch<User>(["core", "users", "me"]);
}
return _globalMePromise;
}
2020-12-01 11:41:37 +00:00
static count(): Promise<number> {
2021-02-09 16:04:55 +00:00
return DefaultClient.fetch<AKResponse<User>>(["core", "users"], {
2020-12-01 11:41:37 +00:00
"page_size": 1
}).then(r => {
return r.pagination.count;
});
}
}