aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/http/user.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-22 09:53:31 +0800
committerGitHub <noreply@github.com>2020-11-22 09:53:31 +0800
commitb3c9cf4bf66bd3b78e94dc522c53e7f7522897f0 (patch)
tree996eed1f087a50e8d5cd865e1440f4dbb8a7873b /FrontEnd/src/app/http/user.ts
parente0785b385138057a23ffd1703a7265c371aef45d (diff)
parentf1aabc06f1005b26bd1c0c5f36c98c28a62fc31e (diff)
downloadtimeline-b3c9cf4bf66bd3b78e94dc522c53e7f7522897f0.tar.gz
timeline-b3c9cf4bf66bd3b78e94dc522c53e7f7522897f0.tar.bz2
timeline-b3c9cf4bf66bd3b78e94dc522c53e7f7522897f0.zip
Merge pull request #189 from crupest/admin
Refactor front end to use the new permission system. Enhance admin page.
Diffstat (limited to 'FrontEnd/src/app/http/user.ts')
-rw-r--r--FrontEnd/src/app/http/user.ts83
1 files changed, 82 insertions, 1 deletions
diff --git a/FrontEnd/src/app/http/user.ts b/FrontEnd/src/app/http/user.ts
index a0a02cce..929956d0 100644
--- a/FrontEnd/src/app/http/user.ts
+++ b/FrontEnd/src/app/http/user.ts
@@ -12,14 +12,28 @@ import {
convertToNotModified,
} from "./common";
+export const kUserManagement = "UserManagement";
+export const kAllTimelineManagement = "AllTimelineManagement";
+export const kHighlightTimelineManagement = "HighlightTimelineManagement";
+
+export const kUserPermissionList = [
+ kUserManagement,
+ kAllTimelineManagement,
+ kHighlightTimelineManagement,
+] as const;
+
+export type UserPermission = typeof kUserPermissionList[number];
+
export interface HttpUser {
uniqueId: string;
username: string;
- administrator: boolean;
+ permissions: UserPermission[];
nickname: string;
}
export interface HttpUserPatchRequest {
+ username?: string;
+ password?: string;
nickname?: string;
}
@@ -28,6 +42,11 @@ export interface HttpChangePasswordRequest {
newPassword: string;
}
+export interface HttpCreateUserRequest {
+ username: string;
+ password: string;
+}
+
export class HttpUserNotExistError extends Error {
constructor(public innerError?: AxiosError) {
super();
@@ -41,12 +60,14 @@ export class HttpChangePasswordBadCredentialError extends Error {
}
export interface IHttpUserClient {
+ list(): Promise<HttpUser[]>;
get(username: string): Promise<HttpUser>;
patch(
username: string,
req: HttpUserPatchRequest,
token: string
): Promise<HttpUser>;
+ delete(username: string, token: string): Promise<void>;
getAvatar(username: string): Promise<BlobWithEtag>;
getAvatar(
username: string,
@@ -54,9 +75,28 @@ export interface IHttpUserClient {
): Promise<BlobWithEtag | NotModified>;
putAvatar(username: string, data: Blob, token: string): Promise<void>;
changePassword(req: HttpChangePasswordRequest, token: string): Promise<void>;
+ putUserPermission(
+ username: string,
+ permission: UserPermission,
+ token: string
+ ): Promise<void>;
+ deleteUserPermission(
+ username: string,
+ permission: UserPermission,
+ token: string
+ ): Promise<void>;
+
+ createUser(req: HttpCreateUserRequest, token: string): Promise<HttpUser>;
}
export class HttpUserClient implements IHttpUserClient {
+ list(): Promise<HttpUser[]> {
+ return axios
+ .get<HttpUser[]>(`${apiBaseUrl}/users`)
+ .then(extractResponseData)
+ .catch(convertToNetworkError);
+ }
+
get(username: string): Promise<HttpUser> {
return axios
.get<HttpUser>(`${apiBaseUrl}/users/${username}`)
@@ -76,6 +116,13 @@ export class HttpUserClient implements IHttpUserClient {
.catch(convertToNetworkError);
}
+ delete(username: string, token: string): Promise<void> {
+ return axios
+ .delete(`${apiBaseUrl}/users/${username}?token=${token}`)
+ .catch(convertToNetworkError)
+ .then();
+ }
+
getAvatar(username: string): Promise<BlobWithEtag>;
getAvatar(
username: string,
@@ -119,6 +166,40 @@ export class HttpUserClient implements IHttpUserClient {
.catch(convertToNetworkError)
.then();
}
+
+ putUserPermission(
+ username: string,
+ permission: UserPermission,
+ token: string
+ ): Promise<void> {
+ return axios
+ .put(
+ `${apiBaseUrl}/users/${username}/permissions/${permission}?token=${token}`
+ )
+ .catch(convertToNetworkError)
+ .then();
+ }
+
+ deleteUserPermission(
+ username: string,
+ permission: UserPermission,
+ token: string
+ ): Promise<void> {
+ return axios
+ .delete(
+ `${apiBaseUrl}/users/${username}/permissions/${permission}?token=${token}`
+ )
+ .catch(convertToNetworkError)
+ .then();
+ }
+
+ createUser(req: HttpCreateUserRequest, token: string): Promise<HttpUser> {
+ return axios
+ .post<HttpUser>(`${apiBaseUrl}/userop/createuser?token=${token}`, req)
+ .then(extractResponseData)
+ .catch(convertToNetworkError)
+ .then();
+ }
}
let client: IHttpUserClient = new HttpUserClient();