-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0223b8e
commit 55e2338
Showing
16 changed files
with
199 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { z } from 'zod' | ||
|
||
export const disableUserInputSchema = z.object({ | ||
userId: z.string(), | ||
}) | ||
|
||
export type DisableUserInput = z.input<typeof disableUserInputSchema> | ||
|
||
export type DisableUserOutput = undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { z } from 'zod' | ||
|
||
export const enableUserInputSchema = z.object({ | ||
userId: z.string(), | ||
}) | ||
|
||
export type EnableUserInput = z.input<typeof enableUserInputSchema> | ||
|
||
export type EnableUserOutput = undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { | ||
disableUserInputSchema, | ||
DisableUserOutput, | ||
} from '@stanfordbdhg/engagehf-models' | ||
import { UserRole } from '../services/credential/credential.js' | ||
import { getServiceFactory } from '../services/factory/getServiceFactory.js' | ||
import { validatedOnCall } from './helpers.js' | ||
|
||
export const disableUser = validatedOnCall( | ||
'disableUser', | ||
disableUserInputSchema, | ||
async (request): Promise<DisableUserOutput> => { | ||
const factory = getServiceFactory() | ||
const credential = factory.credential(request.auth) | ||
const userId = request.data.userId | ||
const userService = factory.user() | ||
|
||
await credential.checkAsync( | ||
() => [UserRole.admin], | ||
async () => { | ||
const user = await userService.getUser(credential.userId) | ||
return user?.content.organization !== undefined ? | ||
[ | ||
UserRole.owner(user.content.organization), | ||
UserRole.clinician(user.content.organization), | ||
] | ||
: [] | ||
}, | ||
) | ||
|
||
await userService.disableUser(userId) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import { | ||
enableUserInputSchema, | ||
EnableUserOutput, | ||
} from '@stanfordbdhg/engagehf-models' | ||
import { UserRole } from '../services/credential/credential.js' | ||
import { getServiceFactory } from '../services/factory/getServiceFactory.js' | ||
import { validatedOnCall } from './helpers.js' | ||
|
||
export const enableUser = validatedOnCall( | ||
'enableUser', | ||
enableUserInputSchema, | ||
async (request): Promise<EnableUserOutput> => { | ||
const factory = getServiceFactory() | ||
const credential = factory.credential(request.auth) | ||
const userId = request.data.userId | ||
const userService = factory.user() | ||
|
||
await credential.checkAsync( | ||
() => [UserRole.admin], | ||
async () => { | ||
const user = await userService.getUser(credential.userId) | ||
return user?.content.organization !== undefined ? | ||
[ | ||
UserRole.owner(user.content.organization), | ||
UserRole.clinician(user.content.organization), | ||
] | ||
: [] | ||
}, | ||
) | ||
|
||
await userService.enableUser(userId) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.