-
Notifications
You must be signed in to change notification settings - Fork 728
feat: add admin apis (CM-1235) #4211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c89142f
feat: add admin apis
ulemons 18a2168
fix: reset inactive reason on open
ulemons 4e4819e
fix: revert standard
ulemons 4832260
fix: revert standard
ulemons d8debe4
fix: unmock stewardship
ulemons 58aec2c
feat: add openApi yaml
ulemons edf8b4a
feat: add openApi yaml and use auth0 for assignment
ulemons 1d22c78
fix: review comments
ulemons 105ac98
fix: add resolution path (#4215)
ulemons 7bf574d
fix: lint
ulemons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| import type { Request, Response } from 'express' | ||
| import { z } from 'zod' | ||
|
|
||
| import { NotFoundError } from '@crowd/common' | ||
| import { assignSteward } from '@crowd/data-access-layer' | ||
|
|
||
| import { getPackagesQx } from '@/db/packagesDb' | ||
| import { ok } from '@/utils/api' | ||
| import { validateOrThrow } from '@/utils/validation' | ||
|
|
||
| const paramsSchema = z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }) | ||
|
|
||
| const bodySchema = z.object({ | ||
| userId: z.string().trim().min(1), | ||
| role: z.enum(['lead', 'co_steward']), | ||
| moveToAssessing: z.boolean().optional().default(false), | ||
| }) | ||
|
|
||
| export async function assignStewardHandler(req: Request, res: Response): Promise<void> { | ||
| const { id } = validateOrThrow(paramsSchema, req.params) | ||
| const { userId, role, moveToAssessing } = validateOrThrow(bodySchema, req.body) | ||
|
|
||
| const qx = await getPackagesQx() | ||
| const result = await assignSteward(qx, id, { | ||
| userId, | ||
| role, | ||
| assignedBy: req.actor.id, | ||
| moveToAssessing, | ||
| }) | ||
|
|
||
| if (!result) { | ||
| throw new NotFoundError(`Stewardship not found: ${id}`) | ||
| } | ||
|
|
||
| ok(res, { stewardship: result.stewardship, stewards: result.stewards }) | ||
| } |
This file contains hidden or 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,36 @@ | ||
| import type { Request, Response } from 'express' | ||
| import { z } from 'zod' | ||
|
|
||
| import { NotFoundError } from '@crowd/common' | ||
| import { ESCALATION_RESOLUTION_PATHS, escalateStewardship } from '@crowd/data-access-layer' | ||
|
|
||
| import { getPackagesQx } from '@/db/packagesDb' | ||
| import { ok } from '@/utils/api' | ||
| import { validateOrThrow } from '@/utils/validation' | ||
|
|
||
| const paramsSchema = z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }) | ||
|
|
||
| const bodySchema = z.object({ | ||
| resolutionPath: z.enum(ESCALATION_RESOLUTION_PATHS), | ||
| notes: z.string().trim().min(1).optional(), | ||
| }) | ||
|
|
||
| export async function escalateHandler(req: Request, res: Response): Promise<void> { | ||
| const { id } = validateOrThrow(paramsSchema, req.params) | ||
| const { resolutionPath, notes } = validateOrThrow(bodySchema, req.body) | ||
|
|
||
| const qx = await getPackagesQx() | ||
| const stewardship = await escalateStewardship(qx, id, { | ||
| resolutionPath, | ||
| notes, | ||
| actorUserId: req.actor.id, | ||
| }) | ||
|
|
||
| if (!stewardship) { | ||
| throw new NotFoundError(`Stewardship not found: ${id}`) | ||
| } | ||
|
|
||
| ok(res, { stewardship }) | ||
| } |
This file contains hidden or 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,50 @@ | ||
| import { Router } from 'express' | ||
|
|
||
| import { createRateLimiter } from '@/api/apiRateLimiter' | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // import { requireScopes } from '@/api/public/middlewares/requireScopes' | ||
| import { safeWrap } from '@/middlewares/errorMiddleware' | ||
|
|
||
|
ulemons marked this conversation as resolved.
|
||
| // import { SCOPES } from '@/security/scopes' | ||
| import { assignStewardHandler } from './assignSteward' | ||
| import { escalateHandler } from './escalate' | ||
| import { openStewardship } from './openStewardship' | ||
| import { updateStatusHandler } from './updateStatus' | ||
|
|
||
| const rateLimiter = createRateLimiter({ max: 60, windowMs: 60 * 1000 }) | ||
|
|
||
| export function stewardshipsRouter(): Router { | ||
| const router = Router() | ||
|
|
||
| router.use(rateLimiter) | ||
|
Comment on lines
+1
to
+19
|
||
|
|
||
| router.post( | ||
| '/', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(openStewardship), | ||
|
Comment on lines
+21
to
+25
|
||
| ) | ||
|
ulemons marked this conversation as resolved.
|
||
|
|
||
| router.put( | ||
| '/:id/steward', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(assignStewardHandler), | ||
| ) | ||
|
|
||
| router.put( | ||
| '/:id/escalate', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(escalateHandler), | ||
| ) | ||
|
|
||
| router.put( | ||
| '/:id/status', | ||
| // TODO: restore once write:stewardships is added to Auth0 staging tenant | ||
| // requireScopes([SCOPES.WRITE_STEWARDSHIPS]), | ||
| safeWrap(updateStatusHandler), | ||
| ) | ||
|
|
||
| return router | ||
| } | ||
This file contains hidden or 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,33 @@ | ||
| import type { Request, Response } from 'express' | ||
| import { z } from 'zod' | ||
|
|
||
| import { NotFoundError } from '@crowd/common' | ||
| import { openStewardshipByPurl } from '@crowd/data-access-layer' | ||
|
|
||
| import { getPackagesQx } from '@/db/packagesDb' | ||
| import { ok } from '@/utils/api' | ||
| import { validateOrThrow } from '@/utils/validation' | ||
|
|
||
| import { normalizePurl } from '../packages/purl' | ||
|
|
||
| const bodySchema = z.object({ | ||
| purl: z | ||
| .string() | ||
| .trim() | ||
| .min(1) | ||
| .refine((v) => v.startsWith('pkg:'), { message: 'purl must start with pkg:' }) | ||
| .transform(normalizePurl), | ||
| }) | ||
|
|
||
| export async function openStewardship(req: Request, res: Response): Promise<void> { | ||
| const { purl } = validateOrThrow(bodySchema, req.body) | ||
|
|
||
| const qx = await getPackagesQx() | ||
| const stewardship = await openStewardshipByPurl(qx, purl, req.actor.id) | ||
|
|
||
| if (!stewardship) { | ||
| throw new NotFoundError(`Package not found: ${purl}`) | ||
| } | ||
|
|
||
| ok(res, { stewardship }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.