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 customizable demographic field entry to facility admin interface #12032

Merged
merged 6 commits into from
Apr 1, 2024

Conversation

rtibbles
Copy link
Member

@rtibbles rtibbles commented Mar 28, 2024

Summary

  • Adds the ability to customize, on a per facility basis, custom demographic fields that can be modified by admins
  • Stores this in the FacilityDataset extra_settings by extending the JSONSchema for that to schematize the specification
  • Uses this schematized specification to dynamically generate another JSONSchema that is used during FacilityUser updates via the API to validate the custom demographic data on a new field extra_demographics on the FacilityUser model
  • Deliberately does not set this up on model validation for the FacilityUser to avoid syncing being stalled by updates or merge conflicts in the schema that might cause deserialization to fail due to validation errors
  • Adds backend tests for the validation and API updates
  • Creates two new components to handle extra demographic field editing
  • Exposes a v-model interface that takes the extra_demographics of a facility user as the value and returns updates to the whole object via the input event
  • Takes another prop that is the facility dataset extra_settings, so that knowing what key to look for in there is handled internally to the component
  • Adds frontend tests for these two components
  • Integrates these components into user creation and editing in the facility app - feasibly this could also be added into user signup and profile editing, but the current need/use case for this is unclear
  • Generalizes device setting extra_settings getters and setters to make access and setting transparent, regardless of whether it is stored in the extra_settings JSON or not
  • Adds a default demographic fields specification to the device settings
  • Updates FacilityDataset creating to use the device setting default field if set

References

Fixes #11999

Reviewer guidance

I can't attach Python files, but save this to a Python script:

from kolibri.main import initialize

initialize()

from kolibri.core.device.utils import set_device_settings
from kolibri.core.device.models import DEFAULT_DEMOGRAPHIC_FIELDS_KEY

set_device_settings(**{
    DEFAULT_DEMOGRAPHIC_FIELDS_KEY: [{"id":"flavour","description": 'Flavour',"enumValues":[{"value":"up","defaultLabel":"Up"},{"value":"down","defaultLabel":"Down"},{"value":"strange","defaultLabel":"Strange"},{"value":"charm","defaultLabel":"Charm"},{"value":"top","defaultLabel":"Top"},{"value":"bottom","defaultLabel":"Bottom"}, {"value": "NOT SPECIFIED", "defaultLabel": "Not specified"}]}]
})

and then run it with a fresh Kolibri home setup. Then run through the setup wizard, and when you go to the Facility user creation and editing confirm that the "Flavour" demographic field is now shown, and that it is editable.


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) DEV: frontend SIZE: very large labels Mar 28, 2024
Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Overall the front-end looks great - super clean and straightforward implementation.

My comments are a couple questions and a picked nit but nothing blocking from me.

return value


@deconstructible
Copy link
Member

Choose a reason for hiding this comment

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

I looked up what @deconstructible does and thought it was weird that the FacilityUserDemographicValidator class didn't have the decorator -- but then I looked at JSON_Schema_Validator and saw that it was decorated.

So, just to be sure then, class decorators are inherited -- or, are they not inherited and the class below doesn't need the @deconstructible decorator at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't explicitly add it to the FacilityUserDemographicValidator because it isn't used in the validation for any field definitions within a model (and so doesn't need to be deconstructed and used within a migration) - it may incidentally be marked as such because of the inheritance though.

"items": {
"properties": {
"language": {
"enum": [
Copy link
Member

Choose a reason for hiding this comment

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

Not blocking as it's a reasonably unlikely edge case.

Looks like if we ever add new languages then we'll need to update this list? Do we have any way to be sure we keep this list up-to-date w/ our available languages?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we update the list of languages, Django will complain that we have model changes that need migrations, and we'll have to generate a new migration - this will fail CI checks, so we will notice :)

},
},
methods: {
setInput(key, value) {
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking nitpick - it took me a couple reads of this to recognize this.value and value where indeed completely different things here 😅 -- it just read a little weird because of the duplicated name so might be helpful to call the param newVal or something

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair!

@radinamatic
Copy link
Member

New demographic field can now be set in the Create new user page, and edited in the Edit user details page! 👏🏽

Create Edit
2024-03-29_01-01-51 2024-03-29_00-59-56

Cross-tested new user creation and editing as superadmin and facility admin users on Firefox, Chrome and Edge on Windows 11.

Copy link
Member

@radinamatic radinamatic left a comment

Choose a reason for hiding this comment

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

Much flavour 😋 💯 :shipit:

@radinamatic
Copy link
Member

radinamatic commented Mar 29, 2024

One thing I forgot to mention yesterday is that there is no possibility to add/edit the new demographic data in the Edit profile page, but my assumption was that it was by design...?

2024-03-28_18-50-16

@rtibbles
Copy link
Member Author

One thing I forgot to mention yesterday is that there is no possibility to add/edit the new demographic data in the Edit profile page, but my assumption was that it was by design...?

Yes - at the moment I have added these as 'admin only' fields, similarly to the id number. Possible that we will want to allow either customization of that on a per field basis, or just let it be user editable as well (other permissions permitting), but I've not heard that use case yet!

Copy link
Member

@jredrejo jredrejo left a comment

Choose a reason for hiding this comment

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

I've reviewed it all and tested it. Everything worked fine, including the frontend.
After thinking I understand the code I still have a couple of doubts:

  1. Bulk export and import commands ignore all these changes. Obviously they're out of the scope of this PR but I wonder if creating a follow up issue to include them in the future makes sense. Is this a feature to be used in situations where moving many users between courses or creating many of them at once?
  2. Validation of changes in users only happens inside the serializer, thus, it will only used when DRF is used. Are we suppossing validation is not needed when creating or updating users in the future via the backend (i.e. are we suppossing our future code will always be correct? )

@marcellamaki
Copy link
Member

Per conversation in standup today - @jredrejo and @nucleogenesis both mentioned that their comments are non-blocking and that we can proceed, although some follow up discussion (and possible issues) might be helpful. Merging for patch 1 release, and will defer to @jredrejo and @rtibbles to sort out next steps

@marcellamaki marcellamaki merged commit 033234c into learningequality:release-v0.16.x Apr 1, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) DEV: backend Python, databases, networking, filesystem... DEV: frontend SIZE: very large
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants