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

Add export for participant requests #3578

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

chrisvanrun
Copy link
Contributor

Note

This is in a first reviewable state. However, I am pausing development on this and switching to cycle work. So any work following reviews will be delayed. Feel free to delay the review as you see fit.

Export of participant requests

This PR adds an export via API for participants' requests.

image

The JSON format:
image

The CSV format has the following headers:

  • challenge
  • changed
  • created
  • registration_question_answers.0.answer
  • registration_question_answers.0.question.question_help_text
  • registration_question_answers.0.question.question_text
  • registration_question_answers.0.question.required
  • registration_status
  • user.department
  • user.institution
  • user.location
  • user.mugshot
  • user.user.username
  • user.website

The default CSV renderer dumps any JSON under the top level. I have intentionally switched to using the 'regular' PaginatedCSVRender with a special application for registration_question_answers. This is to address any strange rendering of actual JSONField values.


class RegistrationRequestViewSet(mixins.ListModelMixin, GenericViewSet):
serializer_class = RegistrationRequestSerializer
permission_classes = [IsAuthenticated]
Copy link
Member

Choose a reason for hiding this comment

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

This should have object based permissions, otherwise this is all public information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are permission checks in the get_queryset. Currently, we don't have any "view_registrationrequest" permissions being assigned to the challenge.admins_groups. Should we? If so, I'll create a PR + manual call to have them added first, before doing anything that relies on them.

from rest_framework_csv.renderers import PaginatedCSVRenderer


class RegistrationRequestCSVRenderer(PaginatedCSVRenderer):
Copy link
Member

Choose a reason for hiding this comment

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

Rather than flattening stuff with a special renderer why not serialize the answers instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was 50/50. I had the answers as a Charfield initially, but it felt really strange to have a JSON string in a JSON object for the regular API.

Copy link
Member

Choose a reason for hiding this comment

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

That's what it is though - it is a JSON field so in the future may not necessarily be a string. I think it is best to take the same approach as the evaluation serialisation and serialise things on the answer level, rather than the registration request. Permissions are already implemented for that so is less impact. You would then get some duplicate data that is serialised along with each answer (e.g. the username, the request status, the question text) but that is okay for now, it's not much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to have a CSV row per answer?

If so, what about registrees that did not answer any questions? IMHO they should be included in any challenge registration overview. Plus, there are no permissions for the RegistrationQuestionAnswers.

Permissions are already implemented for that so is less impact.

Are you referring to the permissions for the RegistrationQuestionAnswers? Those were deemed to be overkill and were removed from the original implementation.

Copy link
Member

Choose a reason for hiding this comment

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

Empty answers are saved for users that don't answer, right? The permissions weren't added because they weren't needed. Now they are needed if you want to add this view in line with the existing framework. We should do that rather than trying to fight it with custom renderers specific to one particular field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Empty answers are indeed saved (by design), but if there are no questions at the time of sign-up, the registree would now show up in an answer-level serialization.

Copy link
Member

Choose a reason for hiding this comment

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

Then add another viewset, serialiser and permissions for the registration requests and link to those from the answers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. The current plan (somewhere in the next cooldown week) is to have two routes:

  • Link for downloading the registration requests.
  • Link for downloading the answers to question registrations (with a crosslink to the registration requests).

@chrisvanrun
Copy link
Contributor Author

Side note: is the swagger view supposed to work in local development?

@jmsmkn
Copy link
Member

jmsmkn commented Oct 10, 2024

Side note: is the swagger view supposed to work in local development?

Set the environment variable CSP_REPORT_ONLY=True

@chrisvanrun chrisvanrun marked this pull request as draft October 18, 2024 10:35
@chrisvanrun
Copy link
Contributor Author

Making this a draft to clearly indicate that this is WIP and been put on the backburner for now.

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