Skip to content

Commit

Permalink
fix(misc): IdP and UI
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Nov 8, 2024
1 parent 66f13e0 commit d5eea37
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 97 deletions.
53 changes: 19 additions & 34 deletions idp/docs/index.html

Large diffs are not rendered by default.

57 changes: 27 additions & 30 deletions idp/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"http"
],
"paths": {
"/v3/user/": {
"/v3/users/me": {
"get": {
"description": "",
"responses": {
Expand All @@ -25,19 +25,16 @@
"responses": {
"204": {
"description": "No Content"
},
"400": {
"description": "Bad Request"
}
}
}
},
"/v3/user/{pictureext}": {
"/v3/users/me/{pictureextension}": {
"get": {
"description": "",
"parameters": [
{
"name": "pictureext",
"name": "pictureextension",
"in": "path",
"required": true,
"type": "string"
Expand All @@ -55,7 +52,7 @@
}
}
},
"/v3/user/update_full_name": {
"/v3/users/me/update_full_name": {
"post": {
"description": "",
"responses": {
Expand All @@ -65,7 +62,7 @@
}
}
},
"/v3/user/update_email_request": {
"/v3/users/me/update_email_request": {
"post": {
"description": "",
"responses": {
Expand All @@ -75,7 +72,7 @@
}
}
},
"/v3/user/update_email_confirmation": {
"/v3/users/me/update_email_confirmation": {
"post": {
"description": "",
"responses": {
Expand All @@ -85,20 +82,17 @@
}
}
},
"/v3/user/update_password": {
"/v3/users/me/update_password": {
"post": {
"description": "",
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
}
}
}
},
"/v3/user/update_picture": {
"/v3/users/me/update_picture": {
"post": {
"description": "",
"responses": {
Expand All @@ -108,7 +102,7 @@
}
}
},
"/v3/user/delete_picture": {
"/v3/users/me/delete_picture": {
"post": {
"description": "",
"responses": {
Expand All @@ -118,7 +112,7 @@
}
}
},
"/v3/user/all": {
"/v3/users/": {
"get": {
"description": "",
"parameters": [
Expand Down Expand Up @@ -150,10 +144,16 @@
}
}
},
"/v3/user/suspend": {
"patch": {
"/v3/users/{id}/suspend": {
"post": {
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "Authorization",
"in": "header",
Expand All @@ -167,10 +167,16 @@
}
}
},
"/v3/user/admin": {
"patch": {
"/v3/users/{id}/make_admin": {
"post": {
"description": "",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "Authorization",
"in": "header",
Expand All @@ -184,7 +190,7 @@
}
}
},
"/v3/user/{id}": {
"/v3/users/{id}": {
"get": {
"description": "",
"parameters": [
Expand Down Expand Up @@ -263,12 +269,6 @@
"responses": {
"200": {
"description": "OK"
},
"400": {
"description": "Bad Request"
},
"403": {
"description": "Forbidden"
}
}
}
Expand All @@ -279,9 +279,6 @@
"responses": {
"200": {
"description": "OK"
},
"503": {
"description": "Service Unavailable"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion idp/qodana.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"
version: '1.0'

#Specify inspection profile for code analysis
profile:
Expand Down
8 changes: 4 additions & 4 deletions idp/src/user/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class UserRepoImpl {
return this.mapRow(rows[0])
}

async listAllPaginated(page: number, size: number): Promise<User[]> {
async list(page: number, size: number): Promise<User[]> {
const { rowCount, rows } = await client.query(
`SELECT *
FROM "user"
Expand All @@ -138,13 +138,13 @@ class UserRepoImpl {
return this.mapList(rows)
}

async listAllByIds(idList: number[]): Promise<User[]> {
async findMany(ids: string[]): Promise<User[]> {
const { rowCount, rows } = await client.query(
`SELECT *
FROM "user"
WHERE id = ANY ($1)
ORDER BY create_time`,
[idList],
[ids],
)
if (rowCount < 1) {
throw newError({
Expand All @@ -156,7 +156,7 @@ class UserRepoImpl {
return this.mapList(rows)
}

async getUserCount(): Promise<number> {
async getCount(): Promise<number> {
const { rowCount, rows } = await client.query(
`SELECT COUNT(id) as count FROM "user"`,
)
Expand Down
18 changes: 9 additions & 9 deletions idp/src/user/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
suspendUser,
makeAdminUser,
getUserByAdmin,
searchUserListPaginated,
list,
getUserPicture,
UserMakeAdminOptions,
UserSuspendOptions,
Expand Down Expand Up @@ -189,7 +189,7 @@ router.delete(
router.get(
'/',
passport.authenticate('jwt', { session: false }),
query('query').isString().notEmpty().trim().escape(),
query('query').isString().optional(),
query('page').isInt(),
query('size').isInt(),
async (req: PassportRequest, res: Response) => {
Expand All @@ -199,16 +199,16 @@ router.get(
throw parseValidationError(result)
}
res.json(
await searchUserListPaginated(
req.query.query as string,
parseInt(req.query.size as string),
parseInt(req.query.page as string),
),
await list({
query: req.query.query as string,
size: parseInt(req.query.size as string),
page: parseInt(req.query.page as string),
}),
)
},
)

router.patch(
router.post(
'/:id/suspend',
passport.authenticate('jwt', { session: false }),
body('suspend').isBoolean(),
Expand All @@ -223,7 +223,7 @@ router.patch(
},
)

router.patch(
router.post(
'/:id/make_admin',
passport.authenticate('jwt', { session: false }),
body('makeAdmin').isBoolean(),
Expand Down
34 changes: 17 additions & 17 deletions idp/src/user/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ export type UserPictureResponse = {
mime: string
}

export type SearchRequest = {
page: string
size: string
query: string
}

export interface UserSuspendOptions {
export type UserSuspendOptions = {
suspend: boolean
}

export interface UserMakeAdminOptions {
export type UserMakeAdminOptions = {
makeAdmin: boolean
}

export type UserListOptions = {
query?: string
size: number
page: number
}

export async function getUser(id: string): Promise<UserDTO> {
return mapEntity(await userRepo.findByID(id))
}
Expand All @@ -123,11 +123,11 @@ export async function getUserPicture(id: string): Promise<UserPictureResponse> {
}
}

export async function searchUserListPaginated(
query: string,
size: number,
page: number,
): Promise<UserAdminList> {
export async function list({
query,
size,
page,
}: UserListOptions): Promise<UserAdminList> {
if (query && query.length >= 3) {
const users = await search
.index(USER_SEARCH_INDEX)
Expand All @@ -140,7 +140,7 @@ export async function searchUserListPaginated(
})
return {
data: (
await userRepo.listAllByIds(
await userRepo.findMany(
users.data.map((value) => {
return value.id
}),
Expand All @@ -152,18 +152,18 @@ export async function searchUserListPaginated(
}
} else {
return {
data: (await userRepo.listAllPaginated(page, size)).map((value) =>
data: (await userRepo.list(page, size)).map((value) =>
adminMapEntity(value),
),
totalElements: await userRepo.getUserCount(),
totalElements: await userRepo.getCount(),
size: size,
page: page,
}
}
}

export async function getUserCount(): Promise<number> {
return await userRepo.getUserCount()
return await userRepo.getCount()
}

export async function updateFullName(
Expand Down
4 changes: 2 additions & 2 deletions ui/src/client/idp/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ export default class UserAPI {
static suspend(id: string, options: SuspendOptions) {
return idpFetcher({
url: `/users/${id}/suspend`,
method: 'PATCH',
method: 'POST',
body: JSON.stringify(options),
}) as Promise<User>
}

static makeAdmin(id: string, options: MakeAdminOptions) {
return idpFetcher({
url: `/users/${id}/make_admin`,
method: 'PATCH',
method: 'POST',
body: JSON.stringify(options),
}) as Promise<User>
}
Expand Down

0 comments on commit d5eea37

Please sign in to comment.