Skip to content
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: Create user endpoint, manage team members by email and teamSlugs #2236

Merged
merged 4 commits into from
Sep 28, 2023

Conversation

DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Sep 26, 2023

What does this PR do?

  • Adds a new create user endpoint to be used by Platform Admins
  • Updates team endpoints to use user emails and team slugs
  • Updates tests, standardises error handling in new modules
  • Fixes a few missing permissions for the platformAdmin role

Depends on theopensystemslab/planx-core#137

@github-actions
Copy link

github-actions bot commented Sep 26, 2023

🤖 Hasura Change Summary compared a subset of table metadata including permissions:

Updated Tables (2)

  • public.teams permissions:

    insert select update delete
    platformAdmin /
    teamEditor /
    2 added column permissions
    insert select update
    platformAdmin ➕ boundary_bbox
    teamEditor
  • public.users permissions:

    insert select update delete
    platformAdmin
    7 added column permissions
    insert select update
    platformAdmin ➕ created_at
    ➕ email
    ➕ first_name
    ➕ id
    ➕ is_platform_admin
    ➕ last_name
    ➕ updated_at

@DafyddLlyr DafyddLlyr force-pushed the dp/create-user-endpoint branch 2 times, most recently from 0007cf5 to a07c55c Compare September 26, 2023 08:44
const mockGetTeamBySlug = jest.fn().mockResolvedValue(mockTeam);
const mockGetUserByEmail = jest.fn().mockResolvedValue(mockUser);

jest.mock("@opensystemslab/planx-core", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point soon I'm going to look at how Jest can automock modules - I think this will allow us much easier setup and less repetition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file were required as queries were failing which should have been allowed - apologies for the nosie.

return res.status(500).json({ message: "Failed to change role" });

res.send({ message: "Successfully changed role" });
export const changeMemberRole: UpsertMember = async (req, res, next) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These simple methods should show request / response logic handled in the controller, whilst "business logic" is handled in the service.

role,
}: UpsertMember) => {
const $client = getClient();
const { user, team } = await getUserAndTeam({ userEmail, teamSlug });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing multiple round trips to the DB to get these details feels pretty awkward. If / when we expose this functionality into the UI it would be worth having userId and teamId upfront to make these requests.

@github-actions
Copy link

github-actions bot commented Sep 26, 2023

Removed vultr server and associated DNS entries

@DafyddLlyr DafyddLlyr marked this pull request as ready for review September 26, 2023 09:48
@DafyddLlyr DafyddLlyr changed the title feat(wip): Create user endpoint, manage team members by email and teamSlugs feat: Create user endpoint, manage team members by email and teamSlugs Sep 26, 2023
@DafyddLlyr DafyddLlyr marked this pull request as draft September 27, 2023 09:51
@DafyddLlyr
Copy link
Contributor Author

Moved (briefly!) back to draft - there's a few outstanding docs tidy ups needed I've just noticed on the Pizza sorry!

DafyddLlyr added a commit to theopensystemslab/planx-core that referenced this pull request Sep 27, 2023
@DafyddLlyr DafyddLlyr force-pushed the dp/create-user-endpoint branch from a07c55c to 40ed87d Compare September 27, 2023 11:54
@DafyddLlyr DafyddLlyr marked this pull request as ready for review September 27, 2023 13:40
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used the Swagger docs to test and truly a joy - all worked as expected!

Can very much imagine a near-future workflow where others interact with this too 🎉

new ServerError({ message: "Failed to create user", cause: error }),
);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we benefit from a "RemoveUser" here too that, rather than delete the actual record, nullifies the email field to lock them out? Probably not crucial yet, but it feels like the tiny missing piece from an otherwise very useful set of user & team management endpoints ! And it would probably encourage better house-keeping around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout - I'll pick this up in a quick follow on PR.

@DafyddLlyr DafyddLlyr merged commit 5c1a480 into main Sep 28, 2023
12 checks passed
@DafyddLlyr DafyddLlyr deleted the dp/create-user-endpoint branch September 28, 2023 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants