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: add User class to manage and create users within Argilla #3169

Merged
merged 42 commits into from
Jun 21, 2023

Conversation

alvarobartt
Copy link
Member

@alvarobartt alvarobartt commented Jun 13, 2023

Description

This PR addresses the addition of a new user-management layer in the Python client via the User class, wrapping up the /api/users and /api/me endpoints in the API v0.

Closes #2968

Type of change

  • New feature (non-breaking change which adds functionality)
  • Improvement (change adding some improvement to an existing functionality)

How Has This Been Tested

  • Add unit tests for the new User class
  • Add unit tests for the user_api endpoints
  • Revisit existing tests to pass with updated UserModel (formerly named User)

Checklist

  • I have merged the original branch into my forked branch
  • I added relevant documentation
  • follows the style guidelines of this project
  • I did a self-review of my code
  • I made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

@alvarobartt alvarobartt added this to the v1.11.0 milestone Jun 13, 2023
@davidberenstein1957
Copy link
Member

shouldn't we also be able to update users? or will we then need to delete and re-create?

@alvarobartt
Copy link
Member Author

shouldn't we also be able to update users? or will we then need to delete and re-create?

That's a nice question indeed, maybe @frascuchon can answer this.

But for the moment, the only available endpoints for user-management are the following, so I guess we're not able to, but it's a nice addition for sure.

image

src/argilla/client/users.py Outdated Show resolved Hide resolved
src/argilla/client/sdk/users/models.py Show resolved Hide resolved
src/argilla/client/sdk/users/api.py Show resolved Hide resolved
src/argilla/client/users.py Show resolved Hide resolved
src/argilla/client/users.py Outdated Show resolved Hide resolved
@davidberenstein1957
Copy link
Member

davidberenstein1957 commented Jun 13, 2023

But for the moment, the only available endpoints for user management are the following, so I guess we're not able to, but it's a nice addition for sure.

Yes exactly, because I would expect to be able to update passwords, roles etc.

alvarobartt added a commit that referenced this pull request Jun 13, 2023
To be removed and replaced with the `UserModel` created upon #3169 completion
@frascuchon
Copy link
Member

shouldn't we also be able to update users? or will we then need to delete and re-create?

That's a nice question indeed, maybe @frascuchon can answer this.

But for the moment, the only available endpoints for user-management are the following, so I guess we're not able to, but it's a nice addition for sure.

image

The CLI commands for users management are not using the API for the actions. I would prefer to provide basic support from python cli (by using available endpoints) and add more features later iteratively (which maybe means creating a new endpoint to update users, or reset passwords,...)

@davidberenstein1957
Copy link
Member

Perfect. @frascuchon could you potentially add some context here for our contributors?

To be removed once all the SDK functions are aligned to expect the `httpx.Client` to be provided instead of the `AuthenticatedClient`
@alvarobartt alvarobartt marked this pull request as ready for review June 20, 2023 13:09
src/argilla/client/sdk/users/api.py Outdated Show resolved Hide resolved
src/argilla/client/users.py Show resolved Hide resolved
src/argilla/client/users.py Outdated Show resolved Hide resolved
Comment on lines +47 to +52
def test_list_users(owner: User) -> None:
UserFactory.create(username="user_1")
UserFactory.create(username="user_2")
httpx_client = ArgillaSingleton.init(api_key=owner.api_key).http_client.httpx

response = list_users(client=httpx_client)
Copy link
Member

Choose a reason for hiding this comment

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

For this kind of tests I think you can use directly the client: TestClient, fixture

Suggested change
def test_list_users(owner: User) -> None:
UserFactory.create(username="user_1")
UserFactory.create(username="user_2")
httpx_client = ArgillaSingleton.init(api_key=owner.api_key).http_client.httpx
response = list_users(client=httpx_client)
def test_list_users(client: TestClient, owner: User, owner_auth_header: dict) -> None:
UserFactory.create(username="user_1")
UserFactory.create(username="user_2")
client.headers.update(owner_auth_header)
response = list_users(client=client)

Copy link
Member Author

Choose a reason for hiding this comment

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

But won't the ArgillaSingleton use the TestClient as configured in the conftest.py? Is this change worth it? Asking because if so, we should change this is more than one place, LMKWYT!

Copy link
Member

Choose a reason for hiding this comment

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

Yes, just to be more explicit here in tests if we're using the HTTP client directly. The conftest is a fixture to use the rg.init functions with an already mocked client

alvarobartt and others added 3 commits June 20, 2023 16:12
Co-authored-by: Gabriel Martin <gabriel@argilla.io>
Co-authored-by: Francisco Aranda <francis@argilla.io>
Also included under `TYPE_CHECKING` when applicable

Co-authored-by: Francisco Aranda <francis@argilla.io>
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Patch coverage: 91.34% and project coverage change: +0.08 🎉

Comparison is base (51751ac) 90.91% compared to head (9a9d3d8) 90.99%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3169      +/-   ##
===========================================
+ Coverage    90.91%   90.99%   +0.08%     
===========================================
  Files          215      219       +4     
  Lines        11304    11663     +359     
===========================================
+ Hits         10277    10613     +336     
- Misses        1027     1050      +23     
Flag Coverage Δ
pytest 90.99% <91.34%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/argilla/__init__.py 86.66% <ø> (+3.33%) ⬆️
src/argilla/client/datasets.py 93.85% <ø> (ø)
src/argilla/server/contexts/datasets.py 96.01% <ø> (ø)
src/argilla/server/seeds.py 0.00% <ø> (ø)
src/argilla/tasks/users/create.py 91.11% <ø> (-4.45%) ⬇️
src/argilla/client/apis/datasets.py 91.72% <75.00%> (+1.35%) ⬆️
src/argilla/client/feedback/dataset.py 83.33% <75.00%> (+0.80%) ⬆️
src/argilla/client/feedback/utils.py 78.94% <78.57%> (+7.51%) ⬆️
src/argilla/client/users.py 84.40% <84.40%> (ø)
src/argilla/client/workspaces.py 86.31% <85.86%> (-7.44%) ⬇️
... and 37 more

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Co-authored-by: Francisco Aranda <francis@argilla.io>
@alvarobartt alvarobartt merged commit 48cc016 into develop Jun 21, 2023
@alvarobartt alvarobartt deleted the feat/user-management branch June 21, 2023 05:55
alvarobartt added a commit that referenced this pull request Sep 7, 2023
#3729)

# Description

This PR addresses a pending TODO upon
#3169 completion where the
`UserModel` was included when wrapping the `/api/users` API endpoints.
So on, in this PR we remove the `WorkspaceUserModel` schema in favour of
`UserModel` to avoid duplicating the same schema to avoid potential
incompatibilities.

**Type of change**

- [X] Refactor (change restructuring the codebase without changing
functionality)
- [X] Improvement (change adding some improvement to an existing
functionality)

**How Has This Been Tested**

(Please describe the tests that you ran to verify your changes. And
ideally, reference `tests`)

- [X] Replace outdated references to `WorkspaceUserModel` with
`UserModel` and re-run the existing unit/integration tests

**Checklist**

- [ ] I added relevant documentation
- [X] follows the style guidelines of this project
- [X] I did a self-review of my code
- [ ] I made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK)
(see text above)
- [ ] I have added relevant notes to the CHANGELOG.md file (See
https://keepachangelog.com/)
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.

Add a user-management layer from the Python client
4 participants