diff --git a/packages/syft/src/syft/service/dataset/dataset.py b/packages/syft/src/syft/service/dataset/dataset.py index 10b5be04ca9..5b13e108435 100644 --- a/packages/syft/src/syft/service/dataset/dataset.py +++ b/packages/syft/src/syft/service/dataset/dataset.py @@ -144,14 +144,21 @@ def _repr_html_(self) -> Any: else "" ) - if isinstance(self.data, ActionObject): - data_table_line = itables.to_html_datatable( - df=self.data.syft_action_data, css=itables_css - ) - elif isinstance(self.data, pd.DataFrame): - data_table_line = itables.to_html_datatable(df=self.data, css=itables_css) + private_data_res = self._private_data() + if private_data_res.is_err(): + data_table_line = private_data_res.err_value else: - data_table_line = self.data + private_data_obj = private_data_res.ok_value + if isinstance(private_data_obj, ActionObject): + data_table_line = itables.to_html_datatable( + df=self.data.syft_action_data, css=itables_css + ) + elif isinstance(private_data_obj, pd.DataFrame): + data_table_line = itables.to_html_datatable( + df=private_data_obj, css=itables_css + ) + else: + data_table_line = private_data_res.ok_value if isinstance(self.mock, ActionObject): mock_table_line = itables.to_html_datatable( @@ -176,7 +183,7 @@ def _repr_html_(self) -> Any:

{self.name}

-

{self.description}

+

{self.description or ""}

Asset ID: {self.id}

Action Object ID: {self.action_id}

{uploaded_by_line} @@ -278,25 +285,36 @@ def has_permission(self, data_result: Any) -> bool: and data_result.endswith("denied") ) - @property - def data(self) -> Any: - # relative + def _private_data(self) -> Result[Any, str]: + """ + Retrieves the private data associated with this asset. + Returns: + Result[Any, str]: A Result object containing the private data if the user has permission + otherwise an Err object with the message "You do not have permission to access private data." + """ api = APIRegistry.api_for( server_uid=self.server_uid, user_verify_key=self.syft_client_verify_key, ) if api is None or api.services is None: - return None + return Ok(None) res = api.services.action.get(self.action_id) if self.has_permission(res): - return res.syft_action_data + return Ok(res.syft_action_data) else: - warning = SyftError( - message="You do not have permission to access private data." - ) - display(warning, clear=True) + return Err("You do not have permission to access private data.") + + @property + def data(self) -> Any: + # relative + private_data_or_error = self._private_data() + + if private_data_or_error.is_err(): + display(SyftError(message=private_data_or_error.err_value), clear=True) return None + else: + return private_data_or_error.ok_value def _is_action_data_empty(obj: Any) -> bool: