Skip to content

Commit 5213557

Browse files
authored
fix: user management for team admins (#752)
* fix: improve modify user data functions * feat: add modify user tests * feat: update modify user teams endpoint
1 parent 884fce5 commit 5213557

5 files changed

Lines changed: 327 additions & 71 deletions

File tree

src/api/v1/teams/{teamId}/users.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import Debug from 'debug'
22
import { Operation, OperationHandlerArray } from 'express-openapi'
3-
import { OpenApiRequestExt, User } from 'src/otomi-models'
3+
import { OpenApiRequestExt, SessionUser, User } from 'src/otomi-models'
44

55
const debug = Debug('otomi:api:v1:teams:users')
66
type UserBasicInfo = Pick<User, 'id' | 'email' | 'isPlatformAdmin' | 'isTeamAdmin' | 'teams'>
77

88
export default function (): OperationHandlerArray {
99
const put: Operation = [
10-
async ({ otomi, params: { teamId }, body }: OpenApiRequestExt, res): Promise<void> => {
10+
async ({ otomi, params: { teamId }, user, body }: OpenApiRequestExt, res): Promise<void> => {
1111
debug(`editTeamUsers(${teamId})`)
12-
const v = await otomi.editTeamUsers(body as UserBasicInfo[])
12+
const v = await otomi.editTeamUsers(body as UserBasicInfo[], user as SessionUser)
1313
res.json(v)
1414
},
1515
]

src/api/v1/users/{userId}.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Debug from 'debug'
22
import { Operation, OperationHandlerArray } from 'express-openapi'
3-
import { OpenApiRequestExt, User } from 'src/otomi-models'
3+
import { OpenApiRequestExt, SessionUser, User } from 'src/otomi-models'
44

55
const debug = Debug('otomi:api:v1:users')
66

@@ -13,9 +13,9 @@ export default function (): OperationHandlerArray {
1313
},
1414
]
1515
const put: Operation = [
16-
async ({ otomi, params: { userId }, body }: OpenApiRequestExt, res): Promise<void> => {
16+
async ({ otomi, params: { userId }, user, body }: OpenApiRequestExt, res): Promise<void> => {
1717
debug(`editUser(${userId})`)
18-
const data = await otomi.editUser(decodeURIComponent(userId), body as User)
18+
const data = await otomi.editUser(decodeURIComponent(userId), body as User, user as SessionUser)
1919
res.json(data)
2020
},
2121
]

src/openapi/api.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,12 +1580,6 @@ paths:
15801580
properties:
15811581
id:
15821582
$ref: '#/components/schemas/User/properties/id'
1583-
email:
1584-
$ref: '#/components/schemas/User/properties/email'
1585-
isPlatformAdmin:
1586-
$ref: '#/components/schemas/User/properties/isPlatformAdmin'
1587-
isTeamAdmin:
1588-
$ref: '#/components/schemas/User/properties/isTeamAdmin'
15891583
teams:
15901584
$ref: '#/components/schemas/User/properties/teams'
15911585
description: User object that contains updated values
@@ -1599,7 +1593,12 @@ paths:
15991593
schema:
16001594
type: array
16011595
items:
1602-
$ref: '#/components/schemas/User'
1596+
type: object
1597+
properties:
1598+
id:
1599+
$ref: '#/components/schemas/User/properties/id'
1600+
teams:
1601+
$ref: '#/components/schemas/User/properties/teams'
16031602

16041603
'/v1/projects':
16051604
get:

0 commit comments

Comments
 (0)