From 70d1afce762f71684823b9f66c558df83d804e4c Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Fri, 25 Sep 2020 10:46:55 -0700 Subject: [PATCH] Move user schemas so they can be imported --- Public API v1.yaml | 191 +++++++++++++++++++++----------------- src/app/posts.services.ts | 46 +++++---- 2 files changed, 134 insertions(+), 103 deletions(-) diff --git a/Public API v1.yaml b/Public API v1.yaml index e508fd5..70d56c5 100644 --- a/Public API v1.yaml +++ b/Public API v1.yaml @@ -695,35 +695,13 @@ paths: content: application/json: schema: - type: object - properties: - user: - $ref: '#/components/schemas/User' - token: - type: string - permissions: - type: array - items: - type: string - available_permissions: - type: array - items: - type: string + $ref: '#/components/schemas/LoginResponse' description: Use this method to log into a user using their username and password and receive a jwt auth token so you can send per-user requests. requestBody: content: application/json: schema: - type: object - properties: - userid: - type: string - description: 'This is the username, not the user uid' - password: - type: string - required: - - userid - - password + $ref: '#/components/schemas/LoginRequest' security: - Auth query parameter: [] tags: @@ -738,27 +716,13 @@ paths: content: application/json: schema: - type: object - properties: - user: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/RegisterResponse' description: Use this endpoint to register a user. It will only work if registration is enabled. requestBody: content: application/json: schema: - type: object - properties: - userid: - type: string - username: - type: string - password: - type: string - required: - - userid - - username - - password + $ref: '#/components/schemas/RegisterRequest' security: - Auth query parameter: [] tags: @@ -778,21 +742,7 @@ paths: content: application/json: schema: - type: object - properties: - change_object: - required: - - uid - type: object - properties: - uid: - type: string - name: - type: string - role: - type: string - required: - - change_object + $ref: '#/components/schemas/UpdateUserRequest' description: Updates certain properties for a user. Only two are possible right now. security: - Auth query parameter: [] @@ -814,12 +764,7 @@ paths: content: application/json: schema: - type: object - properties: - uid: - type: string - required: - - uid + $ref: '#/components/schemas/DeleteUserRequest' security: - Auth query parameter: [] tags: @@ -834,25 +779,7 @@ paths: content: application/json: schema: - type: object - properties: - roles: - type: object - properties: - admin: - type: object - properties: - permissions: - type: array - items: - $ref: '#/components/schemas/UserPermission' - user: - type: object - properties: - permissions: - type: array - items: - $ref: '#/components/schemas/UserPermission' + $ref: '#/components/schemas/GetRolesResponse' description: Gets the available roles and their permissions security: - Auth query parameter: [] @@ -910,12 +837,7 @@ paths: content: application/json: schema: - type: object - properties: - users: - type: array - items: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/GetUsersResponse' description: 'Gets all users, returns a list of the user objects including their user permissions, videos, playlists, subscriptions, etc.' security: - Auth query parameter: [] @@ -1695,6 +1617,103 @@ components: properties: id: type: string + RegisterRequest: + required: + - userid + - username + - password + type: object + properties: + userid: + type: string + username: + type: string + password: + type: string + RegisterResponse: + type: object + properties: + user: + $ref: '#/components/schemas/User' + LoginRequest: + required: + - username + - password + type: object + properties: + username: + type: string + password: + type: string + LoginResponse: + type: object + properties: + user: + $ref: '#/components/schemas/User' + token: + type: string + permissions: + type: array + items: + $ref: '#/components/schemas/UserPermission' + available_permissions: + type: array + items: + $ref: '#/components/schemas/UserPermission' + UpdateUserRequest: + required: + - change_object + type: object + properties: + change_object: + required: + - uid + type: object + properties: + uid: + type: string + name: + type: string + role: + type: string + DeleteUserRequest: + required: + - uid + type: object + properties: + uid: + type: string + GetUsersResponse: + required: + - users + type: object + properties: + users: + type: array + items: + $ref: '#/components/schemas/User' + GetRolesResponse: + required: + - roles + type: object + properties: + roles: + type: object + properties: + admin: + type: object + properties: + permissions: + type: array + items: + $ref: '#/components/schemas/UserPermission' + user: + type: object + properties: + permissions: + type: array + items: + $ref: '#/components/schemas/UserPermission' securitySchemes: Auth query parameter: name: apiKey diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index d0fad49..976298c 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -19,6 +19,7 @@ import type { DeleteMp3Mp4Request, DeletePlaylistRequest, DeleteSubscriptionFileRequest, + DeleteUserRequest, DownloadArchiveRequest, DownloadFileRequest, FileType, @@ -34,13 +35,19 @@ import type { GetMp4sResponse, GetPlaylistRequest, GetPlaylistResponse, + GetRolesResponse, GetSubscriptionRequest, GetSubscriptionResponse, + GetUsersResponse, + LoginRequest, + LoginResponse, Mp3DownloadRequest, Mp3DownloadResponse, Mp4DownloadRequest, Mp4DownloadResponse, Playlist, + RegisterRequest, + RegisterResponse, SetConfigRequest, SharingToggle, SubscribeRequest, @@ -53,6 +60,7 @@ import type { UpdatePlaylistFilesRequest, UpdatePlaylistRequest, UpdateServerRequest, + UpdateUserRequest, UserPermission, YesNo, } from '../api-types'; @@ -444,9 +452,9 @@ export class PostsService implements CanActivate { } // user methods - login(username, password) { - const call = this.http.post(this.path + 'auth/login', {username: username, password: password}, this.httpOptions); - return call; + login(username: string, password: string) { + const body: LoginRequest = {username: username, password: password}; + return this.http.post(this.path + 'auth/login', body, this.httpOptions); } // user methods @@ -481,10 +489,11 @@ export class PostsService implements CanActivate { } // user methods - register(username, password) { - const call = this.http.post(this.path + 'auth/register', {userid: username, - username: username, - password: password}, this.httpOptions); + register(username: string, password: string) { + const body: RegisterRequest = {userid: username, + username: username, + password: password} + const call = this.http.post(this.path + 'auth/register', body, this.httpOptions); return call; } @@ -529,10 +538,11 @@ export class PostsService implements CanActivate { return this.http.post(this.path + 'auth/adminExists', {}, this.httpOptions); } - createAdminAccount(password) { - return this.http.post(this.path + 'auth/register', {userid: 'admin', - username: 'admin', - password: password}, this.httpOptions); + createAdminAccount(password: string) { + const body: RegisterRequest = {userid: 'admin', + username: 'admin', + password: password}; + return this.http.post(this.path + 'auth/register', body, this.httpOptions); } checkAdminCreationStatus(force_show = false) { @@ -547,12 +557,14 @@ export class PostsService implements CanActivate { }); } - changeUser(change_obj) { - return this.http.post(this.path + 'updateUser', {change_object: change_obj}, this.httpOptions); + changeUser(change_obj: UpdateUserRequest['change_object']) { + const body: UpdateUserRequest = {change_object: change_obj}; + return this.http.post(this.path + 'updateUser', body, this.httpOptions); } - deleteUser(uid) { - return this.http.post(this.path + 'deleteUser', {uid: uid}, this.httpOptions); + deleteUser(uid: string) { + const body: DeleteUserRequest = {uid: uid}; + return this.http.post(this.path + 'deleteUser', body, this.httpOptions); } changeUserPassword(user_uid, new_password) { @@ -560,11 +572,11 @@ export class PostsService implements CanActivate { } getUsers() { - return this.http.post(this.path + 'getUsers', {}, this.httpOptions); + return this.http.post(this.path + 'getUsers', {}, this.httpOptions); } getRoles() { - return this.http.post(this.path + 'getRoles', {}, this.httpOptions); + return this.http.post(this.path + 'getRoles', {}, this.httpOptions); } setUserPermission(user_uid: string, permission: UserPermission, new_value: YesNo) {