Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

feat: move api v0 functionality to v1 #168

Merged
merged 13 commits into from
May 14, 2024

Conversation

jfcalvo
Copy link
Member

@jfcalvo jfcalvo commented May 13, 2024

Description

Feature branch for migrating API endpoints from v0 to v1.

Refs argilla-io/argilla#4773

Type of change

(Please delete options that are not relevant. Remember to title the PR according to the type of change)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (change restructuring the codebase without changing functionality)
  • Improvement (change adding some improvement to an existing functionality)
  • Documentation update

How Has This Been Tested

  • Adding new tests.

Checklist

  • 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 filled out the contributor form (see text above)
  • I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)

jfcalvo added 12 commits May 6, 2024 15:49
# Description

This PR implements a new endpoint on API v1 to create tokens for users.
It works the same than the one in API v0 with small changes.

The new endpoint created is `POST /api/v1/token`. I have used `/token`
instead of `/login` because I think we are creating tokens and it's
better if we continue using that naming for it.

@frascuchon tell me if we still have a good reason for rename it to
`/login` and I will change it if necessary.

Closes #137 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Adding new tests.
- [x] I have check that old tests are passing using the new endpoint
too.

**Checklist**

- [ ] 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 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/)
# Description

This PR creates a new `/api/v1/me` endpoint with similar functionality
to the old `/me` endpoint from API v0.

The following changes are included:
* `full_name` user attribute is not used in the new `User` v1 schema.
Instead the frontend should concatenate `first_name` and `last_name` if
necessary.
* `workspaces` user attribute is not used in the new `User` v1 schema.
`/api/v1/me/workspaces` could be used instead.

Closes #139

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Adding new tests.

**Checklist**

- [ ] 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 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/)
# Description

This PR add a new endpoint `GET /api/v1/users` returning a list of users
if the current user is an owner.

Changes of the new endpoint compared to the old one:
* The returned object is different, in the old endpoint an array with
the users is returned. In the new endpoint an object of the type
`{"items": [...]}` is used.
* The returned users as with previous PRs is not including the
`workspaces` attribute and `full_name` has been removed as well.

Closes #141 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Adding new tests.

**Checklist**

- [ ] 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 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/)
# Description

This PR adds a new endpoint `POST /api/v1/users` allowing the creation
of a new user for API v1.

Changes of the new endpoint compared to the old one:
* `workspaces` attribute is not allowed when creating users with this
endpoint. If necessary subsequent requests should be done to an endpoint
that is still pending to be migrated. Specifically `POST
/api/v1/workspaces/:workspace_id/users/:user_id`.
* In the same way that is happening with previous PRs the returned
created user is not including `full_name` attribute.

Closes #145 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Adding new tests and checking that the tests for API v0 are
working as expected if using API v1 endpoint (except the ones creating
workspaces along with the user).

**Checklist**

- [ ] 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 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/)
…1/users/:user_id` (#148)

# Description

This PR migrate adds a new endpoint `DELETE /api/v1/users/:user_id`
allowing the deletion of users using API v1.

Closes #147 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Adding new tests and checking that old tests for API v0 pass with
API v1 implementation.

**Checklist**

- [ ] 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 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/)
…aces` (#150)

# Description

This PR adds a new endpoint `POST /api/v1/workspace` allowing the
creation of new workspaces for API v1.

Changes of the new endpoint compared to the old one:
* The new endpoint returns a `201` status code instead of the `200`
returned by the old endpoint.

I have added also some changes to the new token creation endpoint to
return `201` instead of `200`.

Closes #149

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Adding new tests and manually checking the old ones pass with the
new endpoint.

**Checklist**

- [ ] 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 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/)
…GET /api/v1/workspaces/:workspace_id/users` (#153)

# Description

This PR adds a new endpoint `GET /api/v1/workspaces/:workspace_id/users`
allowing to get a list of users belonging to a workspace for API v1.

Changes of the new endpoint compared to the old one:
* The list of returned users are wrapped inside an `items` attribute
like `{"items": [...]}`. This is what we do for all endpoints on API v1
returning collections.
* The returned users are not including the workspaces. For the migration
we removed that attribute from `User` schema and that affect this
endpoint too.
* Small change on error message when the workspace is not found (we are
using a custom HTTP exception).

Closes #152 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Adding new tests.

**Checklist**

- [ ] 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 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/)
)

# Description

This PR add a new endpoint `POST /api/v1/workspaces/:workspace_id/users`
to create a new user for a workspace.

Changes introduced in this new endpoint compared to the old one:
* Now we must provide the `user_id` in the body of the `POST` request
instead of adding it in the URL.
* I have changed the `create_workspace_user` context function so we need
an additional change in `argilla` repo. The PR with the changes on
argilla is here: argilla-io/argilla#4807
* As done with previous PRs the returned user doesn't has `full_name` or
`workspaces`.

Closes #155 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Adding new tests for the endpoint.

**Checklist**

- [ ] 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 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/)
…o API v1 (#158)

# Description

This PR migrates the endpoint `DELETE
/api/workspaces/:workspace_id/users/:user_id` to API v1 so users can be
removed from a workspace.

Closes #157 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Add new tests.

**Checklist**

- [ ] 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 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/)
# Description

With this PR I'm creating a new endpoint on API v1 `GET /api/v1/version`
to return the current argilla version.

I renamed it to `/api/v1/version` instead of `/api/v1/info` because at
the end we are only returning the version.

Closes #161

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [x] Added new tests.

**Checklist**

- [ ] 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 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/)
# Description

This PR add changes to migrate `/api/_status` endpoint to
`/api/v1/status` endpoint.

The changes added in this PR compared to the endpoint from API v0:
* Instead of `mem_info` attribute name we are using now `memory`.
* I'm not using the info service code because it has a lot of accidental
complexity. Instead I have created a new `info` context with three
functions that returns the Argilla version, ElasticSearch and Memory
status. (Once we delete old endpoints we can remove the service code).

Closes #164 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Adding tests for the new endpoint.

**Checklist**

- [ ] 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 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/)
# Description

This PR add a new API v1 endpoint `GET /api/v1/users/:user_id` endpoint
so the server can return a user information given a user id.

Closes #163 

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

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

- [x] Adding new tests for the endpoint

**Checklist**

- [ ] 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 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/)
@jfcalvo jfcalvo requested a review from frascuchon May 13, 2024 13:22
@jfcalvo jfcalvo changed the title [FEATURE-BRANCH] feat:move api v0 functionality to v1 [FEATURE-BRANCH] feat: move api v0 functionality to v1 May 13, 2024
Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 96.35628% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 90.94%. Comparing base (0efba5c) to head (e4bb929).
Report is 57 commits behind head on main.

Files Patch % Lines
src/argilla_server/contexts/info.py 80.95% 4 Missing ⚠️
src/argilla_server/apis/v1/handlers/users.py 95.00% 2 Missing ⚠️
src/argilla_server/search_engine/base.py 66.66% 1 Missing ⚠️
src/argilla_server/search_engine/elasticsearch.py 50.00% 1 Missing ⚠️
src/argilla_server/search_engine/opensearch.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   90.34%   90.94%   +0.59%     
==========================================
  Files         189      205      +16     
  Lines        9302    10083     +781     
==========================================
+ Hits         8404     9170     +766     
- Misses        898      913      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

frascuchon pushed a commit to argilla-io/argilla that referenced this pull request May 13, 2024
# Description

Add `argilla-server` to his own folder using code from
argilla-io/argilla-server#168

The following code has been removed/changed:
* Folder `/.github` has not been copied from `argilla-server`.
* Submodule `argilla` has not been copied from `argilla-server`.

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)
- [ ] Documentation update

**How Has This Been Tested**

- [ ] Build should be successfully created.

**Checklist**

- [ ] 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 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/)
@jfcalvo jfcalvo changed the title [FEATURE-BRANCH] feat: move api v0 functionality to v1 feat: move api v0 functionality to v1 May 14, 2024
@jfcalvo jfcalvo merged commit e103dcd into main May 14, 2024
14 checks passed
@jfcalvo jfcalvo deleted the feat/move-api-v0-functionality-to-v1 branch May 14, 2024 14:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants