From 1de0935e1f218b9f0d51d6e7bad421305facf91b Mon Sep 17 00:00:00 2001 From: Sal Tijerina Date: Mon, 16 Sep 2024 10:45:30 -0500 Subject: [PATCH] task/WP-685: user work workspace file select (#1426) * handle error in revoke method * handle cloud.data work system in workspace select modal --- client/modules/_hooks/src/systems/types.ts | 1 + .../workspace/src/SelectModal/SelectModal.tsx | 16 +++++++++++----- designsafe/apps/auth/backends.py | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/client/modules/_hooks/src/systems/types.ts b/client/modules/_hooks/src/systems/types.ts index 742588cfd0..afc7f718bb 100644 --- a/client/modules/_hooks/src/systems/types.ts +++ b/client/modules/_hooks/src/systems/types.ts @@ -61,6 +61,7 @@ export type TTapisSystem = { label?: string; keyservice?: boolean; isMyData?: boolean; + hasWork?: boolean; portalNames: string[]; }; importRefId?: string; diff --git a/client/modules/workspace/src/SelectModal/SelectModal.tsx b/client/modules/workspace/src/SelectModal/SelectModal.tsx index e49f37b007..fbbb4906f2 100644 --- a/client/modules/workspace/src/SelectModal/SelectModal.tsx +++ b/client/modules/workspace/src/SelectModal/SelectModal.tsx @@ -103,9 +103,13 @@ const getSystemRootPath = ( storageSystem: TTapisSystem | undefined, user: TUser | undefined ): string => { - return storageSystem?.notes?.isMyData - ? encodeURIComponent('/' + user?.username) - : ''; + if (storageSystem?.notes?.isMyData) { + return encodeURIComponent('/' + user?.username); + } + if (storageSystem?.notes?.hasWork) { + return encodeURIComponent('/work/' + user?.homedir); + } + return ''; }; const getBackPath = ( @@ -298,7 +302,7 @@ export const SelectModal: React.FC<{ return (a.notes?.isMyData ? 0 : 1) - (b.notes?.isMyData ? 0 : 1); }) .map((system) => ({ - label: system.notes.label, + label: system.notes?.hasWork ? 'Work' : system.notes.label ?? system.id, value: system.id, })); systemOptions.push({ label: 'My Projects', value: 'myprojects' }); @@ -363,7 +367,9 @@ export const SelectModal: React.FC<{ selectedPath: getSystemRootPath(system, user), scheme: getScheme(system), }); - setSystemLabel(system.notes.label ?? system.id); + setSystemLabel( + system.notes?.hasWork ? 'Work' : system.notes.label ?? system.id + ); }; const onProjectSelect = (uuid: string, projectId: string) => { diff --git a/designsafe/apps/auth/backends.py b/designsafe/apps/auth/backends.py index b668a94b3b..ab04993cf5 100644 --- a/designsafe/apps/auth/backends.py +++ b/designsafe/apps/auth/backends.py @@ -36,7 +36,8 @@ def on_user_logged_out(sender, request, user, **kwargs): login_provider = "TACC" logger.info( - "Revoking tapis token: %s", TapisOAuthToken().get_masked_token(user.tapis_oauth.access_token) + "Revoking tapis token: %s", + TapisOAuthToken().get_masked_token(user.tapis_oauth.access_token), ) backend = TapisOAuthBackend() TapisOAuthBackend.revoke(backend, user.tapis_oauth.access_token) @@ -139,7 +140,8 @@ def authenticate(self, *args, **kwargs): token = kwargs["token"] logger.info( - 'Attempting login via Tapis with token "%s"' % TapisOAuthToken().get_masked_token(token) + 'Attempting login via Tapis with token "%s"' + % TapisOAuthToken().get_masked_token(token) ) client = Tapis(base_url=settings.TAPIS_TENANT_BASEURL, access_token=token) @@ -188,9 +190,13 @@ def authenticate(self, *args, **kwargs): def revoke(self, token): logger.info( - "Attempting to revoke Tapis token %s" % TapisOAuthToken().get_masked_token(token) + "Attempting to revoke Tapis token %s" + % TapisOAuthToken().get_masked_token(token) ) - client = Tapis(base_url=settings.TAPIS_TENANT_BASEURL, access_token=token) - response = client.authenticator.revoke_token(token=token) - logger.info("revoke response is %s" % response) + try: + client = Tapis(base_url=settings.TAPIS_TENANT_BASEURL, access_token=token) + response = client.authenticator.revoke_token(token=token) + logger.info("revoke response is %s" % response) + except BaseTapyException as e: + logger.error("Error revoking token: %s", e.message)