16848: Always use wb2 token when LoginCluster is set and isn't the home cluster
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 17 Feb 2021 20:53:05 +0000 (17:53 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 17 Feb 2021 20:53:05 +0000 (17:53 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/store/auth/auth-action.ts
src/store/token-dialog/token-dialog-actions.tsx
src/views-components/token-dialog/token-dialog.tsx

index 49a82b956252d5730e14c4cf4f8db9e699c83ac5..fb94746ff983b0a23502c3149d9f91b45bab5a73 100644 (file)
@@ -99,7 +99,9 @@ export const saveApiToken = (token: string) => (dispatch: Dispatch, getState: ()
 export const getNewExtraToken = () =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const user = getState().auth.user;
+        const loginCluster = getState().auth.config.clusterConfig.Login.LoginCluster;
         if (user === undefined) { return; }
+        if (loginCluster !== "" && getState().auth.homeCluster !== loginCluster) { return; }
         try {
             // Do not show errors on the create call, cluster security configuration may not
             // allow token creation and there's no way to know that from workbench2 side in advance.
index 656f532b5a5908a8f11a3892794822a74ef3337a..2cf573bcae8a004607fb667d16e44a212dafeaef 100644 (file)
@@ -13,14 +13,21 @@ const API_HOST_PROPERTY_NAME = 'apiHost';
 export interface TokenDialogData {
     token: string;
     apiHost: string;
+    canCreateNewTokens: boolean;
 }
 
 export const setTokenDialogApiHost = (apiHost: string) =>
     propertiesActions.SET_PROPERTY({ key: API_HOST_PROPERTY_NAME, value: apiHost });
 
-export const getTokenDialogData = (state: RootState): TokenDialogData => ({
-    apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
-    token: state.auth.extraApiToken || state.auth.apiToken || '',
-});
+export const getTokenDialogData = (state: RootState): TokenDialogData => {
+    const loginCluster = state.auth.config.clusterConfig.Login.LoginCluster;
+    const canCreateNewTokens = !(loginCluster !== "" && state.auth.homeCluster !== loginCluster);
+
+    return {
+        apiHost: getProperty<string>(API_HOST_PROPERTY_NAME)(state.properties) || '',
+        token: state.auth.extraApiToken || state.auth.apiToken || '',
+        canCreateNewTokens,
+    };
+};
 
 export const openTokenDialog = dialogActions.OPEN_DIALOG({ id: TOKEN_DIALOG_NAME, data: {} });
index 063bb2a5ef99db6433a85e8474c34be0ff89387e..5bbcaf57db5f6aeb3517c6a6ae95c5d6f58d3188 100644 (file)
@@ -121,7 +121,7 @@ unset ARVADOS_API_HOST_INSECURE`
                         COPY TO CLIPBOARD
                     </Button>
                 </CopyToClipboard>
-                <Button
+                { this.props.canCreateNewTokens && <Button
                     onClick={() => this.onGetNewToken()}
                     color="primary"
                     size="small"
@@ -129,7 +129,7 @@ unset ARVADOS_API_HOST_INSECURE`
                     className={classes.actionButton}
                 >
                     GET NEW TOKEN
-                </Button>
+                </Button> }
                 <Typography >
                     Arvados
                             <a href='http://doc.arvados.org/user/reference/api-tokens.html' target='blank' className={classes.link}>virtual machines</a>