Skip to content

Create students in Profile API #370

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 11 commits into from
Jul 8, 2024
Merged

Conversation

chrisroos
Copy link
Contributor

@chrisroos chrisroos commented Jul 2, 2024

With this PR we're now creating students in Profile API when they're added in editor-standalone. There are a number of commits but they should all be fairly easy to follow in isolation:

  • The first 5 commits refactor the ProfileApiClient in preparation for implementing .create_school_student.
  • The next 3 commits add methods to ProfileApiClient to list, create and destroy safeguarding flags in Profile API.
  • The penultimate commit adds a before_filter to SchoolStudentsController that creates the relevant (teacher and/or owner) safeguarding flags in Profile API for the authenticated user.
  • The final commit modifies .create_school_student so that it creates a student in Profile API.

Although the create student endpoint in Profile API allows us to create multiple students in a single request, we're currently only ever calling it with a single student: even in the SchoolStudent::CreateBatch operation. We're also not currently using the create batch endpoint in the editor-standalone CSV import functionality, and are instead making a request for each row in the CSV file. This will need more work as it currently only displays a single error message, rather than all error messages preventing students from being created.

@cla-bot cla-bot bot added the cla-signed label Jul 2, 2024
@raspberrypiherokubot raspberrypiherokubot temporarily deployed to editor-api-p-create-stu-ojx35n July 2, 2024 16:14 Inactive
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 2, 2024 16:38 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from ad48cc5 to 0a24f45 Compare July 3, 2024 12:02
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 3, 2024 12:03 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 0a24f45 to 78803f8 Compare July 3, 2024 12:08
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 3, 2024 12:09 Inactive
@chrisroos chrisroos changed the title Create students in profile api Create students in Profile API Jul 3, 2024
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 78803f8 to b8d52cb Compare July 3, 2024 13:45
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 3, 2024 13:45 Inactive
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 3, 2024 13:53 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from fd14dd2 to b8677c6 Compare July 4, 2024 09:03
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 09:04 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from b8677c6 to bfccdd1 Compare July 4, 2024 10:24
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 10:24 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from bfccdd1 to 9b8cf3a Compare July 4, 2024 10:35
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 10:35 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 9b8cf3a to 4a80abe Compare July 4, 2024 10:54
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 10:54 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 4a80abe to 0052659 Compare July 4, 2024 11:01
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 11:02 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 0052659 to 2d47a97 Compare July 4, 2024 11:42
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 11:43 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 2d47a97 to 7867f7c Compare July 4, 2024 13:55
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 4, 2024 13:55 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 7867f7c to bd7b4b7 Compare July 5, 2024 09:13
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 5, 2024 09:13 Inactive
@chrisroos chrisroos self-assigned this Jul 5, 2024
@chrisroos chrisroos linked an issue Jul 5, 2024 that may be closed by this pull request
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from bd7b4b7 to 70aa257 Compare July 5, 2024 09:47
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 5, 2024 11:11 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from c332139 to a04fbf5 Compare July 5, 2024 11:43
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 5, 2024 11:43 Inactive
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from a04fbf5 to 2695350 Compare July 5, 2024 11:54
@chrisroos chrisroos temporarily deployed to editor-api-p-create-stu-ojx35n July 5, 2024 11:54 Inactive
@chrisroos chrisroos marked this pull request as ready for review July 5, 2024 12:09
@sra405
Copy link
Contributor

sra405 commented Jul 8, 2024

🔧 I can't comment against it but there's a rogue wem file in the root now, just needs removing 😄

@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 2695350 to 5d6330e Compare July 8, 2024 10:40
Copy link
Contributor

@sra405 sra405 left a comment

Choose a reason for hiding this comment

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

👍 nice! LGTM

chrisroos added 11 commits July 8, 2024 12:21
I think it probably makes sense to think of ProfileApiClient as an
external library that wraps Profile API but doesn't know anything about
our domain objects.
To automatically serialise the request body as JSON and set the
`Content-Type` header[1].

[1]: https://lostisland.github.io/faraday/#/middleware/included/json?id=json-requests
To automatically deserialize the response body when the `Content-Type`
indicates that it contains JSON[1]

[1]: https://lostisland.github.io/faraday/#/middleware/included/json?id=json-responses
This is probably more idiomatic than setting them in the
`apply_default_headers` method.
To list the Safeguarding flags for the user associated with the access
token.

Note that I'm intentionally not doing anything different if
`BYPASS_OAUTH` is set. Given how tightly coupled Editor API and Profile
API are I'm less convinced it makes sense to attempt to run one without
the other in development.

API docs: https://my.raspberrypi.org/api/v1/documentation/#/Safeguarding%20Flags/get_safeguarding_flags
In preparation for creating the relevant teacher or owner safeguarding
flags for the authenticated user so that they have permission to CRUD
students in Profile API.

Note that Profile API returns 201 if the flag was created and 303 if it
already exists.

Note that I'm intentionally not doing anything different if
`BYPASS_OAUTH` is set. Given how tightly coupled Editor API and Profile
API are I'm less convinced it makes sense to attempt to run one without
the other in development.

API docs: https://my.raspberrypi.org/api/v1/documentation/#/Safeguarding%20Flags/post_safeguarding_flags
We're not using this at the moment but it makes it easier to test in
development if we can create and delete safeguarding flags for a user.

Note that I'm intentionally not doing anything different if
`BYPASS_OAUTH` is set. Given how tightly coupled Editor API and Profile
API are I'm less convinced it makes sense to attempt to run one without
the other in development.

API docs: https://my.raspberrypi.org/api/v1/documentation/#/Safeguarding%20Flags/delete_safeguarding_flags__flag_
The Profile API requires that the authenticated user has:

- either the school:owner or school:teacher safeguarding flags set in
  order to be able to create, edit and list students
- the school:owner safeguarding flag set in order to be able to delete
  students

Safeguarding flags can only be set in Profile API for the authenticated
user so we're conditionally creating them here before the user then
attempts to interact with Profile API to CRUD students.
Note that if the student is successfully created in Profile API then we
receive their ID in the response. We use this to create the relevant
student role and also make it available in the OperationResponse
returned by `SchoolStudent::Create.call` so that clients of Editor API
can use it if necessary.

I'm stripping any extraneous leading and trailing spaces from name,
username and password in ProfileApiClient.create_school_student to avoid
the sorts of problems that can occur when usernames and passwords
include these unnecessary spaces. I've tested the Profile API and it's
not (currently, at least) doing any kind of normalizing of what we pass
to it.

Note that I'm intentionally not doing anything different if
`BYPASS_OAUTH` is set. Given how tightly coupled Editor API and Profile
API are I'm less convinced it makes sense to attempt to run one without
the other in development.

API docs: https://my.raspberrypi.org/api/v1/documentation/#/Students/post_schools__schoolId__students
@chrisroos chrisroos force-pushed the create-students-in-profile-api branch from 5d6330e to 2d8ec2e Compare July 8, 2024 11:21
@chrisroos chrisroos enabled auto-merge July 8, 2024 11:21
@chrisroos chrisroos merged commit c23c079 into main Jul 8, 2024
3 checks passed
@chrisroos chrisroos deleted the create-students-in-profile-api branch July 8, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create students in Profile API when created in Editor API
3 participants