-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
feat(API): Add user management endpoints to the Projects Public API #12329
base: master
Are you sure you want to change the base?
Conversation
packages/cli/src/public-api/v1/handlers/projects/spec/paths/projects.projectId.yml
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
…-delete-users-from-project
3c650ef
to
e9d96f5
Compare
…-delete-users-from-project
…-delete-users-from-project
… personal projects with the public API
@@ -76,8 +81,8 @@ export class ProjectService { | |||
} | |||
|
|||
const project = await this.getProjectWithScope(user, projectId, ['project:delete']); | |||
if (!project) { | |||
throw new NotFoundError(`Could not find project with ID: ${projectId}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I re-added the project ID. That should make it easier to debug this when a user reports this.
// 0. check if this is a team project | ||
if (project.type !== 'team') { | ||
throw new ForbiddenError( | ||
`Can't delete project. Project with ID "${projectId}" is not a team project.`, | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to send back a ForbiddenError instead of a NotFound. The user has access to the project, they are just not allowed to delete it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if the public API DTOs should be in it's own folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if the public API should define their own DTOs. We don't want to give the public API more power by accident when we add more power to the internal API.
@@ -20,7 +20,7 @@ export const projectRoleSchema = z.enum([ | |||
export type ProjectRole = z.infer<typeof projectRoleSchema>; | |||
|
|||
export const projectRelationSchema = z.object({ | |||
userId: z.string(), | |||
userId: z.string().min(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question (non-blocking): Why the min(1)
?
userId: z.string(), | ||
role: projectRoleSchema, | ||
userId: z.string().min(1), | ||
role: projectRoleSchema.exclude(['project:personalOwner']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've excluded the project:personalOwner
here too. Personal projects are special, they can only have one owner with that role. There should not be any API endpoint that allows changing the relation. They are created when the user is created and deleted when the user is deleted.
@@ -211,28 +224,80 @@ export class ProjectService { | |||
|
|||
async syncProjectRelations( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: add a test to make sure this throws when used with personal projects or the personalOwner role.
throw new ProjectNotFoundError(projectId); | ||
} | ||
|
||
// TODO: do we need to prevent project owner from being removed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't, as long as this function only works with team projects.
TODO: add test to make sure this function throws when used on a personal project.
throw new ProjectNotFoundError(projectId); | ||
} | ||
|
||
// TODO: do we need to block any specific roles here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this function also should only work with team projects and should disallow the personalOwner role.
TODO: add test for this
Summary
Adds the ability to add and delete users to and from projects using the public API endpoint:
Also allow the ability to alter user roles in projects.
Note: There were problems getting the integration test server to work when I referenced the
projectId.yml
schema within the OpenAPI spec rather than inlined it. As we'll be looking to improve the public API at some point in the future, I've moved all the references to inline instead.Related Linear tickets, Github issues, and Community forum posts
Partially fixes: PAY-1852
Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)