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

Consolidate list remote users api #12321

Merged

Conversation

AlexVelezLl
Copy link
Member

Summary

Consolidates the logic of listing remote users from the user_profile and setup_wizard plugins, and migrates them to core auth so that they are accessible by multiple plugins.

There were some differences between both endpoints, and the following decisions were made to merge them:

  • The setup wizard endpoint returned an object { admin, students }, while the user_profile endpoint returned a list of users. It was decided to keep the response the same as that of user_profile as it was more flexible, and in the setup wizard to make the admin, students filter on the frontend instead of the backend.
  • The setup wizard endpoint returns a 403 error if there are authentication errors, but the user_profile endpoint returns a 200 code, but with an error object. The 403 error was maintained, and where it is called to the user_profile endpoint in the frontend the error handling was updated.
  • The setup_wizard endpoint gets a "facility_id" param, while the user_profile endpoint gets a "facility" param. The naming of "facility_id" was preferred.
  • The user_profile endpoint validated the input data, and the setup_wizard endpoint did not. It was preferred to validate it as the user_profile.

Reviewer guidance

  • Check the flow of importing users as administrator of the setup wizard.
  • Check the flow of changing facilities for an "on my own" user, and merging users using administrator credentials.

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

@AlexVelezLl AlexVelezLl added the TODO: needs review Waiting for review label Jun 19, 2024
@github-actions github-actions bot added DEV: backend Python, databases, networking, filesystem... APP: User Re: User app (sign-in, sign-up, user profile, etc.) APP: Setup Wizard Re: Setup Wizard (facility import, superuser creation, settings, etc.) DEV: frontend labels Jun 19, 2024
@rtibbles rtibbles self-assigned this Jul 16, 2024
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Changes make sense, and being able to reuse the same API endpoint with just some minor tweaks of how they are handled in Javascript is a neat way to do this with minimal changes.

Having more tests, and also using the API endpoints more consistently would be preferable in the future, but this does well to do the minimal required change.

@pcenov
Copy link
Member

pcenov commented Aug 8, 2024

Hi @AlexVelezLl - I confirm that there are no issues when importing learners as an administrator in the setup wizard or when changing facilities for an "On my own" learner. However when I attempt to merge a learner that was created on the actual "On my own" device then when I try to migrate the learner either by using his password or by using an admin account I am getting permission denied 403 errors in the console and the learner cannot be migrated:

migrate.user.mp4

LogsDB.zip

@AlexVelezLl AlexVelezLl force-pushed the consolidate-list-remote-users branch from ee2e845 to 41b4eda Compare August 8, 2024 20:49
@AlexVelezLl AlexVelezLl force-pushed the consolidate-list-remote-users branch from 41b4eda to ef85477 Compare August 8, 2024 21:24
@AlexVelezLl
Copy link
Member Author

Hi @pcenov! I have solved the mentioned issues both when mergin the self user and with an admin:

Screenshot from 2024-08-08 15-42-38

@rtibbles I have updated the RemoteFacilityUserAuthenticatedViewset so if the queried user is not an admin we just return the user: 98f2f55.

Also, since this commit the IsSelf permission was not working ok because local_user_id was not in kwargs. I tried to solve this here, would love to hear if you have any comment about this 👐.

@rtibbles
Copy link
Member

rtibbles commented Aug 8, 2024

I think rather than mess with the signature of the task function, it might be simpler just to update how the IsSelf references the args/kwargs?

class IsSelf(BasePermission):
    def user_can_run_job(self, user, job):
        return user.id == job.args[1] or user.id == job.kwargs.get("remote_user_pk", None)

    def user_can_read_job(self, user, job):
        return user.id == job.args[1] or user.id == job.kwargs.get("remote_user_pk", None)

@pcenov
Copy link
Member

pcenov commented Aug 9, 2024

Thanks @AlexVelezLl - I confirm that everything is working correctly now!

@AlexVelezLl
Copy link
Member Author

Thank you @pcenov! @rtibbles would you give it one last look, please? 👐.

@rtibbles rtibbles merged commit fc6ba3e into learningequality:develop Aug 9, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Setup Wizard Re: Setup Wizard (facility import, superuser creation, settings, etc.) APP: User Re: User app (sign-in, sign-up, user profile, etc.) DEV: backend Python, databases, networking, filesystem... DEV: frontend SIZE: medium TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants