From 2b175f253087db351f675fbc66a6cd8d97dfb244 Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 16:17:06 +0100 Subject: [PATCH 1/7] feat: adjust notification html repr --- .../service/notification/notifications.py | 19 +++++++++++++++++++ packages/syft/src/syft/store/linked_obj.py | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/notification/notifications.py b/packages/syft/src/syft/service/notification/notifications.py index c2e5b9ea53f..97e9022fd6d 100644 --- a/packages/syft/src/syft/service/notification/notifications.py +++ b/packages/syft/src/syft/service/notification/notifications.py @@ -17,6 +17,8 @@ from ...types.transforms import generate_id from ...types.transforms import transform from ...types.uid import UID +from ...util import options +from ...util.colors import SURFACE @serializable() @@ -67,6 +69,23 @@ class Notification(SyftObject): ] __repr_attrs__ = ["subject", "status", "created_at", "linked_obj"] + def _repr_html_(self) -> str: + return f""" + +
+

Notification

+

ID: {self.id}

+

Subject: {self.subject}

+

Status: {self.status}

+

Created at: {self.created_at}

+

Linked object: {self.linked_obj}

+

Replies: {self.replies}

+

+

+ """ + @property def link(self) -> Optional[SyftObject]: if self.linked_obj: diff --git a/packages/syft/src/syft/store/linked_obj.py b/packages/syft/src/syft/store/linked_obj.py index 20a1e3dffde..90f0491ec8d 100644 --- a/packages/syft/src/syft/store/linked_obj.py +++ b/packages/syft/src/syft/store/linked_obj.py @@ -30,7 +30,12 @@ class LinkedObject(SyftObject): object_uid: UID def __str__(self) -> str: - return f"<{self.object_type}: {self.object_uid}@" + resolved_obj_type = ( + type(self.resolve) if self.object_type == None else self.object_type + ) + return ( + f"{resolved_obj_type.__name__}: {self.object_uid} @ Node<{self.node_uid}>" + ) @property def resolve(self) -> SyftObject: From f8fa8801abd0787119fd9ea1aa93f4967a5c568b Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 16:39:38 +0100 Subject: [PATCH 2/7] fix: remove get_all_unread as default for client.notifications --- packages/syft/src/syft/client/api.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/syft/src/syft/client/api.py b/packages/syft/src/syft/client/api.py index 1a69fce69aa..703684e9e11 100644 --- a/packages/syft/src/syft/client/api.py +++ b/packages/syft/src/syft/client/api.py @@ -357,10 +357,7 @@ def __getitem__(self, key: Union[str, int]) -> Any: def _repr_html_(self) -> Any: if not hasattr(self, "get_all"): return NotImplementedError - if hasattr(self, "get_all_unread"): - results = self.get_all_unread() - else: - results = self.get_all() + results = self.get_all() return results._repr_html_() From cab5c9dab523e89f70ac5de624599d6e00d91cc0 Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 16:46:18 +0100 Subject: [PATCH 3/7] fix: adjust styling for the notification repr html --- packages/syft/src/syft/service/notification/notifications.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/notification/notifications.py b/packages/syft/src/syft/service/notification/notifications.py index 97e9022fd6d..90a77df0319 100644 --- a/packages/syft/src/syft/service/notification/notifications.py +++ b/packages/syft/src/syft/service/notification/notifications.py @@ -72,16 +72,15 @@ class Notification(SyftObject): def _repr_html_(self) -> str: return f"""

Notification

ID: {self.id}

Subject: {self.subject}

-

Status: {self.status}

+

Status: {self.status.name}

Created at: {self.created_at}

Linked object: {self.linked_obj}

-

Replies: {self.replies}

""" From dc0aa77f513a0c6291f5724512df9e492a53c14e Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 16:50:41 +0100 Subject: [PATCH 4/7] feat: add node id to notification html repr --- packages/syft/src/syft/store/linked_obj.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/store/linked_obj.py b/packages/syft/src/syft/store/linked_obj.py index 90f0491ec8d..99f3fa12a98 100644 --- a/packages/syft/src/syft/store/linked_obj.py +++ b/packages/syft/src/syft/store/linked_obj.py @@ -34,7 +34,7 @@ def __str__(self) -> str: type(self.resolve) if self.object_type == None else self.object_type ) return ( - f"{resolved_obj_type.__name__}: {self.object_uid} @ Node<{self.node_uid}>" + f"{resolved_obj_type.__name__}: {self.object_uid} @ Node {self.node_uid}" ) @property From bdec00371d45fb76d5898b18a3a9582bb3e22748 Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 17:04:39 +0100 Subject: [PATCH 5/7] lint: fix linked_obj.py --- packages/syft/src/syft/store/linked_obj.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/store/linked_obj.py b/packages/syft/src/syft/store/linked_obj.py index 99f3fa12a98..8ac219a3936 100644 --- a/packages/syft/src/syft/store/linked_obj.py +++ b/packages/syft/src/syft/store/linked_obj.py @@ -31,11 +31,9 @@ class LinkedObject(SyftObject): def __str__(self) -> str: resolved_obj_type = ( - type(self.resolve) if self.object_type == None else self.object_type - ) - return ( - f"{resolved_obj_type.__name__}: {self.object_uid} @ Node {self.node_uid}" + type(self.resolve) if self.object_type is None else self.object_type ) + return f"{resolved_obj_type.__name__}: {self.object_uid} @ Node {self.node_uid}" @property def resolve(self) -> SyftObject: From abc1f90e5a273ea765a1d330d73eba615f10db4c Mon Sep 17 00:00:00 2001 From: Thiago Costa Porto Date: Thu, 21 Sep 2023 17:35:29 +0100 Subject: [PATCH 6/7] fix: adds uploader to dataset/asset A contributor added with the role of "Uploader" is also added to the dataset and asset as the "uploader". --- .../syft/src/syft/service/dataset/dataset.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/syft/src/syft/service/dataset/dataset.py b/packages/syft/src/syft/service/dataset/dataset.py index e9da25cbb45..84856a9ce16 100644 --- a/packages/syft/src/syft/service/dataset/dataset.py +++ b/packages/syft/src/syft/service/dataset/dataset.py @@ -21,6 +21,7 @@ from result import Err from result import Ok from result import Result +from syft.service.user.roles import Roles # relative from ...serde.serializable import serializable @@ -154,11 +155,7 @@ def _repr_html_(self) -> Any: # relative from ...service.action.action_object import ActionObject - uploaded_by_line = "n/a" - if len(self.contributors) > 0: - uploaded_by_line = ( - f"

Uploaded by: {self.uploader.name}

" - ) + uploaded_by_line = f"

Uploaded by: {self.uploader.name} ({self.uploader.email})

" if self.uploader else "" if isinstance(self.data, ActionObject): data_table_line = itables.to_html_datatable( df=self.data.syft_action_data, css=itables_css @@ -336,6 +333,8 @@ def add_contributor( name=name, role=_role_str, email=email, phone=phone, note=note ) self.contributors.append(contributor) + if _role_str == Roles.UPLOADER.value: + self.uploader = contributor return SyftSuccess( message=f"Contributor '{name}' added to '{self.name}' Asset." ) @@ -451,12 +450,11 @@ def _coll_repr_(self) -> Dict[str, Any]: } def _repr_html_(self) -> Any: - uploaded_by_line = "n/a" - if len(self.contributors) > 0: - uploaded_by_line = ( + uploaded_by_line = ( "

" - + f"Uploaded by:{self.uploader.name}

" - ) + + f"Uploaded by:{self.uploader.name} ({self.uploader.email})

" + ) if self.uploader else "" + return f"""