Skip to content

Commit

Permalink
Merge pull request #9286 from OpenMined/refactor-usercodestatus
Browse files Browse the repository at this point in the history
refactor user code status
  • Loading branch information
koenvanderveen authored Sep 20, 2024
2 parents ea17414 + f9dc9a0 commit 2174ec5
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 252 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ packages/grid/helm/examples/dev/migration.yaml


notebooks/scenarios/bigquery/*.json

notebooks/tutorials/version-upgrades/*.yaml
notebooks/tutorials/version-upgrades/*.blob
12 changes: 4 additions & 8 deletions notebooks/scenarios/bigquery/sync/040-do-review-requests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@
"metadata": {},
"outputs": [],
"source": [
"assert len(diffs.batches) == 1\n",
"assert diffs.batches[0].root_diff.obj_type.__qualname__ == \"Job\""
"batch_root_strs = [x.root_diff.obj_type.__qualname__ for x in diffs.batches]\n",
"assert len(diffs.batches) == 3\n",
"assert \"Job\" in batch_root_strs"
]
},
{
Expand Down Expand Up @@ -285,11 +286,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -300,7 +296,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.5"
}
},
"nbformat": 4,
Expand Down
35 changes: 28 additions & 7 deletions packages/syft/src/syft/protocol/protocol_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,41 @@
"action": "add"
}
},
"SyftWorker": {
"2": {
"version": 2,
"hash": "e996dabbb8ad4ff0bc5d19528077c11f73b9300d810735d367916e4e5b9149b6",
"action": "add"
}
},
"WorkerSettings": {
"2": {
"version": 2,
"hash": "91c375dd40d06c81fc6403751ee48cbc94b9877f91e65a7e302303218dfe71fa",
"action": "add"
}
},
"ApprovalDecision": {
"1": {
"version": 1,
"hash": "ecce7c6e01af68b0c0a73605f0c2226917f0784ecce69e9f64ce004b243252d4",
"action": "add"
}
},
"UserCodeStatusCollection": {
"2": {
"version": 2,
"hash": "22a1574d4d2d5dcfa26791f2a5007bf3885dae707e175bf8cc20d0803ae54dec",
"action": "add"
}
},
"UserCode": {
"2": {
"version": 2,
"hash": "726bc406449178029c04b0b21b50f86ea12b18ea5b7dd030ad7dbfc6e60f6909",
"action": "add"
}
},
"QueueItem": {
"2": {
"version": 2,
Expand Down Expand Up @@ -66,13 +94,6 @@
"hash": "2e1365c5535fa51c22eef79f67dd6444789bc829c27881367e3050e06e2ffbfe",
"action": "remove"
}
},
"SyftWorker": {
"2": {
"version": 2,
"hash": "e996dabbb8ad4ff0bc5d19528077c11f73b9300d810735d367916e4e5b9149b6",
"action": "add"
}
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion packages/syft/src/syft/service/code/status_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
# third party

# relative
from ...client.api import ServerIdentity
from ...serde.serializable import serializable
from ...store.db.db import DBManager
from ...store.db.stash import ObjectStash
from ...store.document_store import PartitionSettings
from ...types.syft_object import PartialSyftObject
from ...types.syft_object import SYFT_OBJECT_VERSION_1
from ...types.uid import UID
from ..context import AuthedServiceContext
from ..response import SyftSuccess
Expand All @@ -15,6 +18,7 @@
from ..service import service_method
from ..user.user_roles import ADMIN_ROLE_LEVEL
from ..user.user_roles import GUEST_ROLE_LEVEL
from .user_code import ApprovalDecision
from .user_code import UserCodeStatusCollection


Expand All @@ -26,6 +30,14 @@ class StatusStash(ObjectStash[UserCodeStatusCollection]):
)


class CodeStatusUpdate(PartialSyftObject):
__canonical_name__ = "CodeStatusUpdate"
__version__ = SYFT_OBJECT_VERSION_1

id: UID
decision: ApprovalDecision


@serializable(canonical_name="UserCodeStatusService", version=1)
class UserCodeStatusService(AbstractService):
stash: StatusStash
Expand All @@ -39,10 +51,30 @@ def create(
context: AuthedServiceContext,
status: UserCodeStatusCollection,
) -> UserCodeStatusCollection:
return self.stash.set(
res = self.stash.set(
credentials=context.credentials,
obj=status,
).unwrap()
return res

@service_method(
path="code_status.update",
name="update",
roles=ADMIN_ROLE_LEVEL,
autosplat=["code_update"],
unwrap_on_success=False,
)
def update(
self, context: AuthedServiceContext, code_update: CodeStatusUpdate
) -> SyftSuccess:
existing_status = self.stash.get_by_uid(
context.credentials, uid=code_update.id
).unwrap()
server_identity = ServerIdentity.from_server(context.server)
existing_status.status_dict[server_identity] = code_update.decision

res = self.stash.update(context.credentials, existing_status).unwrap()
return SyftSuccess(message="UserCode updated successfully", value=res)

@service_method(
path="code_status.get_by_uid", name="get_by_uid", roles=GUEST_ROLE_LEVEL
Expand Down
Loading

0 comments on commit 2174ec5

Please sign in to comment.