From cb92050aeddeaff6fb8a818c26a810e97329c5c4 Mon Sep 17 00:00:00 2001 From: khoaguin Date: Tue, 6 Feb 2024 15:31:07 +0700 Subject: [PATCH 01/10] [refactor] fixing issues in `syft/user` --- packages/syft/src/syft/serde/third_party.py | 4 ++-- packages/syft/src/syft/service/user/user.py | 22 +++++++++---------- .../syft/src/syft/service/user/user_roles.py | 8 ++++--- .../src/syft/service/user/user_service.py | 16 +++++++++----- .../syft/src/syft/service/user/user_stash.py | 8 +++---- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/packages/syft/src/syft/serde/third_party.py b/packages/syft/src/syft/serde/third_party.py index 1abfe2d9cdc..2d70250cbe6 100644 --- a/packages/syft/src/syft/serde/third_party.py +++ b/packages/syft/src/syft/serde/third_party.py @@ -96,8 +96,8 @@ def deserialize_dataframe(buf: bytes) -> DataFrame: def deserialize_series(blob: bytes) -> Series: - df = DataFrame.from_dict(deserialize(blob, from_bytes=True)) - return df[df.columns[0]] + df: DataFrame = DataFrame.from_dict(deserialize(blob, from_bytes=True)) + return Series(df[df.columns[0]]) recursive_serde_register( diff --git a/packages/syft/src/syft/service/user/user.py b/packages/syft/src/syft/service/user/user.py index c6211f9d0d3..d36b162fd7a 100644 --- a/packages/syft/src/syft/service/user/user.py +++ b/packages/syft/src/syft/service/user/user.py @@ -191,9 +191,9 @@ class UserCreate(UserUpdate): role: Optional[ServiceRole] = None # make sure role cant be set without uid password: str password_verify: Optional[str] = None - verify_key: Optional[SyftVerifyKey] - institution: Optional[str] - website: Optional[str] + verify_key: Optional[SyftVerifyKey] # type: ignore[assignment] + institution: Optional[str] # type: ignore[assignment] + website: Optional[str] # type: ignore[assignment] created_by: Optional[SyftSigningKey] mock_execution_permission: bool = False @@ -399,40 +399,40 @@ def user_to_user_verify() -> List[Callable]: @migrate(UserV1, User) -def upgrade_user_v1_to_v2(): +def upgrade_user_v1_to_v2() -> List[Callable]: return [make_set_default(key="mock_execution_permission", value=False)] @migrate(User, UserV1) -def downgrade_user_v2_to_v1(): +def downgrade_user_v2_to_v1() -> List[Callable]: return [drop(["mock_execution_permission"])] @migrate(UserUpdateV1, UserUpdate) -def upgrade_user_update_v1_to_v2(): +def upgrade_user_update_v1_to_v2() -> List[Callable]: return [make_set_default(key="mock_execution_permission", value=False)] @migrate(UserUpdate, UserUpdateV1) -def downgrade_user_update_v2_to_v1(): +def downgrade_user_update_v2_to_v1() -> List[Callable]: return [drop(["mock_execution_permission"])] @migrate(UserCreateV1, UserCreate) -def upgrade_user_create_v1_to_v2(): +def upgrade_user_create_v1_to_v2() -> List[Callable]: return [make_set_default(key="mock_execution_permission", value=False)] @migrate(UserCreate, UserCreateV1) -def downgrade_user_create_v2_to_v1(): +def downgrade_user_create_v2_to_v1() -> List[Callable]: return [drop(["mock_execution_permission"])] @migrate(UserViewV1, UserView) -def upgrade_user_view_v1_to_v2(): +def upgrade_user_view_v1_to_v2() -> List[Callable]: return [make_set_default(key="mock_execution_permission", value=False)] @migrate(UserView, UserViewV1) -def downgrade_user_view_v2_to_v1(): +def downgrade_user_view_v2_to_v1() -> List[Callable]: return [drop(["mock_execution_permission"])] diff --git a/packages/syft/src/syft/service/user/user_roles.py b/packages/syft/src/syft/service/user/user_roles.py index f4ee5bf03d4..5785c9f5dca 100644 --- a/packages/syft/src/syft/service/user/user_roles.py +++ b/packages/syft/src/syft/service/user/user_roles.py @@ -90,13 +90,15 @@ def __lt__(self, other: Self) -> bool: + ServiceRole.ADMIN ) -DATA_SCIENTIST_ROLE_LEVEL = ServiceRole.roles_for_level( +DATA_SCIENTIST_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level( ServiceRole.DATA_SCIENTIST + ServiceRole.DATA_OWNER + ServiceRole.ADMIN ) -ONLY_DATA_SCIENTIST_ROLE_LEVEL = ServiceRole.roles_for_level(ServiceRole.DATA_SCIENTIST) +ONLY_DATA_SCIENTIST_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level( + ServiceRole.DATA_SCIENTIST +) -DATA_OWNER_ROLE_LEVEL = ServiceRole.roles_for_level( +DATA_OWNER_ROLE_LEVEL: List[ServiceRole] = ServiceRole.roles_for_level( ServiceRole.DATA_OWNER + ServiceRole.ADMIN ) diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 79067aa0e1f..a7bf1c5b051 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -122,8 +122,10 @@ def get_all( for i in range(0, len(results), page_size) ] # Return the proper slice using chunk_index - results = results[page_index] - results = UserViewPage(users=results, total=total) + if page_index: + results = results[page_index] + results = UserViewPage(users=results, total=total) + return results # 🟡 TODO: No user exists will happen when result.ok() is empty list @@ -180,9 +182,9 @@ def search( ] # Return the proper slice using page_index - results = results[page_index] - - results = UserViewPage(users=results, total=total) + if page_index: + results = results[page_index] + results = UserViewPage(users=results, total=total) return results @@ -317,7 +319,9 @@ def update( return user.to(UserView) - def get_target_object(self, credentials: SyftVerifyKey, uid: UID): + def get_target_object( + self, credentials: SyftVerifyKey, uid: UID + ) -> Union[SyftError, User]: user_result = self.stash.get_by_uid(credentials=credentials, uid=uid) if user_result.is_err(): return SyftError(message=str(user_result.err())) diff --git a/packages/syft/src/syft/service/user/user_stash.py b/packages/syft/src/syft/service/user/user_stash.py index fe76cc8de9f..834a342afaf 100644 --- a/packages/syft/src/syft/service/user/user_stash.py +++ b/packages/syft/src/syft/service/user/user_stash.py @@ -60,10 +60,10 @@ def set( ignore_duplicates=ignore_duplicates, ) - def admin_verify_key(self): + def admin_verify_key(self) -> Result[SyftVerifyKey]: return Ok(self.partition.root_verify_key) - def admin_user(self): + def admin_user(self) -> Result[Optional[User], str]: return self.get_by_role( credentials=self.admin_verify_key().ok(), role=ServiceRole.ADMIN ) @@ -110,7 +110,7 @@ def get_by_verify_key( return self.query_one(credentials=credentials, qks=qks) def delete_by_uid( - self, credentials: SyftVerifyKey, uid: UID, has_permission=False + self, credentials: SyftVerifyKey, uid: UID, has_permission: bool = False ) -> Result[SyftSuccess, str]: qk = UIDPartitionKey.with_obj(uid) result = super().delete( @@ -121,7 +121,7 @@ def delete_by_uid( return result def update( - self, credentials: SyftVerifyKey, user: User, has_permission=False + self, credentials: SyftVerifyKey, user: User, has_permission: bool = False ) -> Result[User, str]: res = self.check_type(user, self.object_type) # we dont use and_then logic here as it is hard because of the order of the arguments From 297e0b3d737987a2bdc39943ff69919631aa3f18 Mon Sep 17 00:00:00 2001 From: khoaguin Date: Wed, 7 Feb 2024 09:07:29 +0700 Subject: [PATCH 02/10] [refactor] mypy passes for files in `service/user` - add some `type: ignore[assignment]` to UserCreate and UserCreateV1 - add some type annotations - add packages/syft/src/syft/service/user/ to pre-commit-config.yaml --- .pre-commit-config.yaml | 2 +- packages/syft/src/syft/service/user/roles.py | 2 +- packages/syft/src/syft/service/user/user.py | 14 +++++++------- packages/syft/src/syft/service/user/user_roles.py | 9 +++++---- packages/syft/src/syft/service/user/user_stash.py | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81b29307e8a..2f93130001e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -172,7 +172,7 @@ repos: - id: mypy name: "mypy: syft" always_run: true - files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py" + files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/user/" #files: "^packages/syft/src/syft/serde" args: [ "--follow-imports=skip", diff --git a/packages/syft/src/syft/service/user/roles.py b/packages/syft/src/syft/service/user/roles.py index d9f548272e1..6d7fd256217 100644 --- a/packages/syft/src/syft/service/user/roles.py +++ b/packages/syft/src/syft/service/user/roles.py @@ -7,5 +7,5 @@ class Roles(Enum): UPLOADER = "Uploader" EDITOR = "Editor" - def __str__(self): + def __str__(self) -> str: return f"{self.value}" diff --git a/packages/syft/src/syft/service/user/user.py b/packages/syft/src/syft/service/user/user.py index d36b162fd7a..98e087aaeb5 100644 --- a/packages/syft/src/syft/service/user/user.py +++ b/packages/syft/src/syft/service/user/user.py @@ -172,12 +172,12 @@ class UserCreateV1(UserUpdateV1): email: EmailStr name: str - role: Optional[ServiceRole] = None + role: Optional[ServiceRole] = None # type: ignore[assignment] password: str - password_verify: Optional[str] = None + password_verify: Optional[str] = None # type: ignore[assignment] verify_key: Optional[SyftVerifyKey] - institution: Optional[str] - website: Optional[str] + institution: Optional[str] # type: ignore[assignment] + website: Optional[str] # type: ignore[assignment] created_by: Optional[SyftSigningKey] @@ -188,10 +188,10 @@ class UserCreate(UserUpdate): email: EmailStr name: str - role: Optional[ServiceRole] = None # make sure role cant be set without uid + role: Optional[ServiceRole] = None # type: ignore[assignment] password: str - password_verify: Optional[str] = None - verify_key: Optional[SyftVerifyKey] # type: ignore[assignment] + password_verify: Optional[str] = None # type: ignore[assignment] + verify_key: Optional[SyftVerifyKey] institution: Optional[str] # type: ignore[assignment] website: Optional[str] # type: ignore[assignment] created_by: Optional[SyftSigningKey] diff --git a/packages/syft/src/syft/service/user/user_roles.py b/packages/syft/src/syft/service/user/user_roles.py index 5785c9f5dca..26addf4734c 100644 --- a/packages/syft/src/syft/service/user/user_roles.py +++ b/packages/syft/src/syft/service/user/user_roles.py @@ -1,6 +1,7 @@ # stdlib from enum import Enum from typing import Any +from typing import Dict from typing import List from typing import Tuple from typing import Union @@ -36,14 +37,14 @@ class ServiceRole(Enum): # Disabling it, as both property and classmethod only works for python >= 3.9 # @property @classmethod - def roles_descending(cls) -> List[Tuple[int, Self]]: + def roles_descending(cls) -> List[Tuple[int, "ServiceRole"]]: tuples = [] for x in cls: tuples.append((x.value, x)) return sorted(tuples, reverse=True) @staticmethod - def roles_for_level(level: Union[int, Self]) -> List[Self]: + def roles_for_level(level: Union[int, "ServiceRole"]) -> List["ServiceRole"]: if isinstance(level, ServiceRole): level = level.value roles = [] @@ -59,7 +60,7 @@ def roles_for_level(level: Union[int, Self]) -> List[Self]: level_float = level_float % role_num return roles - def capabilities(self): + def capabilities(self) -> List["ServiceRoleCapability"]: return ROLE_TO_CAPABILITIES[self] def __add__(self, other: Any) -> int: @@ -104,7 +105,7 @@ def __lt__(self, other: Self) -> bool: ADMIN_ROLE_LEVEL = ServiceRole.roles_for_level(ServiceRole.ADMIN) -ROLE_TO_CAPABILITIES = { +ROLE_TO_CAPABILITIES: Dict["ServiceRole", List["ServiceRoleCapability"]] = { ServiceRole.NONE: [], ServiceRole.GUEST: [ ServiceRoleCapability.CAN_MAKE_DATA_REQUESTS, diff --git a/packages/syft/src/syft/service/user/user_stash.py b/packages/syft/src/syft/service/user/user_stash.py index 834a342afaf..a130f83b3bb 100644 --- a/packages/syft/src/syft/service/user/user_stash.py +++ b/packages/syft/src/syft/service/user/user_stash.py @@ -60,7 +60,7 @@ def set( ignore_duplicates=ignore_duplicates, ) - def admin_verify_key(self) -> Result[SyftVerifyKey]: + def admin_verify_key(self) -> Result[Optional[SyftVerifyKey], str]: return Ok(self.partition.root_verify_key) def admin_user(self) -> Result[Optional[User], str]: From e934baa2b993b66522d4eee0ce043104c7b41481 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Fri, 9 Feb 2024 13:53:59 +0530 Subject: [PATCH 03/10] [ci] untag old betas --- .github/workflows/cd-syft-dev.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/cd-syft-dev.yml b/.github/workflows/cd-syft-dev.yml index 657afc0e8d1..cb8891476df 100644 --- a/.github/workflows/cd-syft-dev.yml +++ b/.github/workflows/cd-syft-dev.yml @@ -192,10 +192,17 @@ jobs: for repo in $REPO_LIST do echo "Cleaning up '$repo'" + # remove dev tags az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ | grep dev- \ | tail -n +$TAIL_FROM_LINE \ | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% + + # remove beta tags + az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ + | grep beta \ + | tail -n +$TAIL_FROM_LINE \ + | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% done - name: Logout and cleanup Azure account From 9e8ed3cbe69d0e8be49de4a6dc08b05cd23d0a23 Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Fri, 9 Feb 2024 14:30:01 +0530 Subject: [PATCH 04/10] [ci] move cleanup to azure tasks --- .github/workflows/cd-syft-dev.yml | 80 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/cd-syft-dev.yml b/.github/workflows/cd-syft-dev.yml index cb8891476df..d4a844bec3c 100644 --- a/.github/workflows/cd-syft-dev.yml +++ b/.github/workflows/cd-syft-dev.yml @@ -70,15 +70,15 @@ jobs: id: buildx uses: docker/setup-buildx-action@v3 - - name: Install Azure CLI - run: | - curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash - az version + # - name: Install Azure CLI + # run: | + # curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash + # az version - - name: Login to Azure CLI - uses: azure/login@v1 - with: - creds: ${{ secrets.AZURE_CREDENTIALS_GITHUB_CI }} + # - name: Login to Azure CLI + # uses: azure/login@v1 + # with: + # creds: ${{ secrets.AZURE_CREDENTIALS_GITHUB_CI }} - name: Login to Azure Container Registry uses: azure/docker-login@v1 @@ -179,35 +179,35 @@ jobs: push: "origin main" cwd: "./infrastructure/" - - name: Cleanup Azure Container Registry - run: | - ACR_REGISTRY_NAME=${{ secrets.ACR_REGISTRY_NAME }} - - echo ">> Fetching repo list.." - REPO_LIST=$(az acr repository list -n $ACR_REGISTRY_NAME -o tsv) - - KEEP_PREV_VERSIONS=5 - TAIL_FROM_LINE=$(($KEEP_PREV_VERSIONS + 1)) - - for repo in $REPO_LIST - do - echo "Cleaning up '$repo'" - # remove dev tags - az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ - | grep dev- \ - | tail -n +$TAIL_FROM_LINE \ - | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% - - # remove beta tags - az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ - | grep beta \ - | tail -n +$TAIL_FROM_LINE \ - | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% - done - - - name: Logout and cleanup Azure account - if: always() - run: | - az logout - az cache purge - az account clear + # - name: Cleanup Azure Container Registry + # run: | + # ACR_REGISTRY_NAME=${{ secrets.ACR_REGISTRY_NAME }} + + # echo ">> Fetching repo list.." + # REPO_LIST=$(az acr repository list -n $ACR_REGISTRY_NAME -o tsv) + + # KEEP_PREV_VERSIONS=5 + # TAIL_FROM_LINE=$(($KEEP_PREV_VERSIONS + 1)) + + # for repo in $REPO_LIST + # do + # echo "Cleaning up '$repo'" + # # remove dev tags + # az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ + # | grep dev- \ + # | tail -n +$TAIL_FROM_LINE \ + # | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% + + # # remove beta tags + # az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ + # | grep beta \ + # | tail -n +$TAIL_FROM_LINE \ + # | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% + # done + + # - name: Logout and cleanup Azure account + # if: always() + # run: | + # az logout + # az cache purge + # az account clear From bdaec6e1d7895611725039d4f641966aae1b3e8c Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 12 Feb 2024 11:47:33 +0530 Subject: [PATCH 05/10] [ci] remove az cli login --- .github/workflows/cd-syft-dev.yml | 43 ------------------------------- 1 file changed, 43 deletions(-) diff --git a/.github/workflows/cd-syft-dev.yml b/.github/workflows/cd-syft-dev.yml index d4a844bec3c..9dee3c1e056 100644 --- a/.github/workflows/cd-syft-dev.yml +++ b/.github/workflows/cd-syft-dev.yml @@ -70,16 +70,6 @@ jobs: id: buildx uses: docker/setup-buildx-action@v3 - # - name: Install Azure CLI - # run: | - # curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash - # az version - - # - name: Login to Azure CLI - # uses: azure/login@v1 - # with: - # creds: ${{ secrets.AZURE_CREDENTIALS_GITHUB_CI }} - - name: Login to Azure Container Registry uses: azure/docker-login@v1 with: @@ -178,36 +168,3 @@ jobs: add: "." push: "origin main" cwd: "./infrastructure/" - - # - name: Cleanup Azure Container Registry - # run: | - # ACR_REGISTRY_NAME=${{ secrets.ACR_REGISTRY_NAME }} - - # echo ">> Fetching repo list.." - # REPO_LIST=$(az acr repository list -n $ACR_REGISTRY_NAME -o tsv) - - # KEEP_PREV_VERSIONS=5 - # TAIL_FROM_LINE=$(($KEEP_PREV_VERSIONS + 1)) - - # for repo in $REPO_LIST - # do - # echo "Cleaning up '$repo'" - # # remove dev tags - # az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ - # | grep dev- \ - # | tail -n +$TAIL_FROM_LINE \ - # | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% - - # # remove beta tags - # az acr repository show-tags --name $ACR_REGISTRY_NAME --repository $repo --orderby time_desc --output tsv \ - # | grep beta \ - # | tail -n +$TAIL_FROM_LINE \ - # | xargs -r -I% az acr repository untag --name $ACR_REGISTRY_NAME --image $repo:% - # done - - # - name: Logout and cleanup Azure account - # if: always() - # run: | - # az logout - # az cache purge - # az account clear From 543af6ad6c6b58e6e005d3c9791fcd33655b78ff Mon Sep 17 00:00:00 2001 From: Yash Gorana Date: Mon, 12 Feb 2024 17:07:38 +0530 Subject: [PATCH 06/10] [cd] fix node 16 deprecation --- .github/workflows/cd-syft-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd-syft-dev.yml b/.github/workflows/cd-syft-dev.yml index 9dee3c1e056..b49e457743a 100644 --- a/.github/workflows/cd-syft-dev.yml +++ b/.github/workflows/cd-syft-dev.yml @@ -71,9 +71,9 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Login to Azure Container Registry - uses: azure/docker-login@v1 + uses: docker/login-action@v3 with: - login-server: ${{ secrets.ACR_SERVER }} + registry: ${{ secrets.ACR_SERVER }} username: ${{ secrets.ACR_USERNAME }} password: ${{ secrets.ACR_PASSWORD }} From a3e26fe20adb71923196fe57a8991b515a55706d Mon Sep 17 00:00:00 2001 From: khoaguin Date: Tue, 13 Feb 2024 10:29:14 +0700 Subject: [PATCH 07/10] [refactor] change ServiceRole.roles_for_level to classmethod add checks if None for page_index in search and get_all of UserService --- packages/syft/src/syft/service/user/user_roles.py | 10 +++++----- packages/syft/src/syft/service/user/user_service.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/syft/src/syft/service/user/user_roles.py b/packages/syft/src/syft/service/user/user_roles.py index 26addf4734c..ec45f9b33fe 100644 --- a/packages/syft/src/syft/service/user/user_roles.py +++ b/packages/syft/src/syft/service/user/user_roles.py @@ -37,19 +37,19 @@ class ServiceRole(Enum): # Disabling it, as both property and classmethod only works for python >= 3.9 # @property @classmethod - def roles_descending(cls) -> List[Tuple[int, "ServiceRole"]]: + def roles_descending(cls) -> List[Tuple[int, Self]]: tuples = [] for x in cls: tuples.append((x.value, x)) return sorted(tuples, reverse=True) - @staticmethod - def roles_for_level(level: Union[int, "ServiceRole"]) -> List["ServiceRole"]: + @classmethod + def roles_for_level(cls, level: Union[int, Self]) -> List[Self]: if isinstance(level, ServiceRole): level = level.value roles = [] level_float = float(level) - service_roles = ServiceRole.roles_descending() + service_roles = cls.roles_descending() for role in service_roles: role_num = role[0] if role_num == 0: @@ -105,7 +105,7 @@ def __lt__(self, other: Self) -> bool: ADMIN_ROLE_LEVEL = ServiceRole.roles_for_level(ServiceRole.ADMIN) -ROLE_TO_CAPABILITIES: Dict["ServiceRole", List["ServiceRoleCapability"]] = { +ROLE_TO_CAPABILITIES: Dict[ServiceRole, List[ServiceRoleCapability]] = { ServiceRole.NONE: [], ServiceRole.GUEST: [ ServiceRoleCapability.CAN_MAKE_DATA_REQUESTS, diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index a7bf1c5b051..c85e5cf6ce9 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -122,7 +122,7 @@ def get_all( for i in range(0, len(results), page_size) ] # Return the proper slice using chunk_index - if page_index: + if page_index is not None: results = results[page_index] results = UserViewPage(users=results, total=total) @@ -182,7 +182,7 @@ def search( ] # Return the proper slice using page_index - if page_index: + if page_index is not None: results = results[page_index] results = UserViewPage(users=results, total=total) From 74f761f5eab7479b7c75c9bd94142b81cbaab048 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Tue, 13 Feb 2024 13:49:44 +0800 Subject: [PATCH 08/10] Switch type order --- packages/syft/src/syft/service/user/user_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index c85e5cf6ce9..9ad1b25da68 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -321,7 +321,7 @@ def update( def get_target_object( self, credentials: SyftVerifyKey, uid: UID - ) -> Union[SyftError, User]: + ) -> Union[User, SyftError]: user_result = self.stash.get_by_uid(credentials=credentials, uid=uid) if user_result.is_err(): return SyftError(message=str(user_result.err())) From aa3e45fd86daef3db12b032eadb85b6e1899ef73 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Wed, 14 Feb 2024 16:25:49 +0800 Subject: [PATCH 09/10] Remove unnecessary quotes around type --- packages/syft/src/syft/service/user/user_roles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/user/user_roles.py b/packages/syft/src/syft/service/user/user_roles.py index ec45f9b33fe..970c75910f6 100644 --- a/packages/syft/src/syft/service/user/user_roles.py +++ b/packages/syft/src/syft/service/user/user_roles.py @@ -60,7 +60,7 @@ def roles_for_level(cls, level: Union[int, Self]) -> List[Self]: level_float = level_float % role_num return roles - def capabilities(self) -> List["ServiceRoleCapability"]: + def capabilities(self) -> List[ServiceRoleCapability]: return ROLE_TO_CAPABILITIES[self] def __add__(self, other: Any) -> int: From 970125cae0c01987574533e8d4e0d0e2db1ab1c2 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Wed, 14 Feb 2024 18:24:28 +0800 Subject: [PATCH 10/10] Fix regex file matcher --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da7122b7d2d..f1a21cb76ec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -172,7 +172,7 @@ repos: - id: mypy name: "mypy: syft" always_run: true - files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/warnings.py|^packages/syft/src/syft/service/dataset|^packages/syft/src/syft/service/worker||^packages/syft/src/syft/service/user" + files: "^packages/syft/src/syft/serde|^packages/syft/src/syft/util/env.py|^packages/syft/src/syft/util/logger.py|^packages/syft/src/syft/util/markdown.py|^packages/syft/src/syft/util/notebook_ui/notebook_addons.py|^packages/syft/src/syft/service/warnings.py|^packages/syft/src/syft/service/dataset|^packages/syft/src/syft/service/worker|^packages/syft/src/syft/service/user" #files: "^packages/syft/src/syft/serde" args: [ "--follow-imports=skip",