-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move users and workspaces schemas under schemas module (#4532)
<!-- Thanks for your contribution! As part of our Community Growers initiative 🌱, we're donating Justdiggit bunds in your name to reforest sub-Saharan Africa. To claim your Community Growers certificate, please contact David Berenstein in our Slack community or fill in this form https://tally.so/r/n9XrxK once your PR has been merged. --> # Description This PR moves user and workspace schemas defined in the `security` module to the proper `schemas.v0` module. Also, the `users_file` setting attribute is removed, but the corresponding environment variable is still available from the `user migrate` command. This change does not change the current behaviour. **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] New feature (non-breaking change which adds functionality) - [X] Refactor (change restructuring the codebase without changing functionality) - [ ] 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`) Running tests locally **Checklist** - [ ] I added relevant documentation - [X] I followed the style guidelines of this project - [X] 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/) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
75c8461
commit 123ddf1
Showing
15 changed files
with
192 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from datetime import datetime | ||
from typing import Any, List, Optional | ||
from uuid import UUID | ||
|
||
from argilla.server.constants import ES_INDEX_REGEX_PATTERN | ||
from argilla.server.enums import UserRole | ||
from argilla.server.pydantic_v1 import BaseModel, Field, constr | ||
from argilla.server.pydantic_v1.utils import GetterDict | ||
|
||
USER_USERNAME_REGEX = ES_INDEX_REGEX_PATTERN | ||
USER_PASSWORD_MIN_LENGTH = 8 | ||
USER_PASSWORD_MAX_LENGTH = 100 | ||
|
||
|
||
class UserGetter(GetterDict): | ||
def get(self, key: str, default: Any = None) -> Any: | ||
if key == "full_name": | ||
return f"{self._obj.first_name} {self._obj.last_name}" if self._obj.last_name else self._obj.first_name | ||
elif key == "workspaces": | ||
return [workspace.name for workspace in self._obj.workspaces] | ||
else: | ||
return super().get(key, default) | ||
|
||
|
||
class User(BaseModel): | ||
"""Base user schema""" | ||
|
||
id: UUID | ||
first_name: str | ||
last_name: Optional[str] | ||
full_name: Optional[str] = Field(description="Deprecated. Use `first_name` and `last_name` instead") | ||
username: str = Field() | ||
role: UserRole | ||
workspaces: Optional[List[str]] | ||
api_key: str | ||
inserted_at: datetime | ||
updated_at: datetime | ||
|
||
class Config: | ||
orm_mode = True | ||
getter_dict = UserGetter | ||
|
||
|
||
class UserCreate(BaseModel): | ||
first_name: constr(min_length=1, strip_whitespace=True) | ||
last_name: Optional[constr(min_length=1, strip_whitespace=True)] | ||
username: str = Field(regex=USER_USERNAME_REGEX, min_length=1) | ||
role: Optional[UserRole] | ||
password: constr(min_length=USER_PASSWORD_MIN_LENGTH, max_length=USER_PASSWORD_MAX_LENGTH) | ||
workspaces: Optional[List[str]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.