isAdmin prop
authorPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 29 Nov 2018 11:32:06 +0000 (12:32 +0100)
committerPawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>
Thu, 29 Nov 2018 11:32:06 +0000 (12:32 +0100)
Feature #14498

Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk <pawel.kowalczyk@contractors.roche.com>

1  2 
src/services/auth-service/auth-service.ts
src/store/virtual-machines/virtual-machines-actions.ts
src/views/virtual-machine-panel/virtual-machine-panel.tsx

index 247869e191316f2527ffb2f9b11aaa09109f2ebe,397b31938a74411a57b506646ba3dfe0af77a98f..8221e489de7f8b63a6e1569596cabbc48d70f1ad
@@@ -4,7 -4,7 +4,7 @@@
  
  import { User } from "~/models/user";
  import { AxiosInstance } from "axios";
--import { ApiActions, ProgressFn } from "~/services/api/api-actions";
++import { ApiActions } from "~/services/api/api-actions";
  import * as uuid from "uuid/v4";
  
  export const API_TOKEN_KEY = 'apiToken';
@@@ -57,9 -61,9 +61,10 @@@ export class AuthService 
          const lastName = localStorage.getItem(USER_LAST_NAME_KEY);
          const uuid = localStorage.getItem(USER_UUID_KEY);
          const ownerUuid = localStorage.getItem(USER_OWNER_UUID_KEY);
-         const isAdmin = Boolean(localStorage.getItem(USER_IS_ADMIN));
+         const isAdmin = this.getIsAdmin();
++        console.log(isAdmin);
  
-         return email && firstName && lastName && uuid && ownerUuid && isAdmin
+         return email && firstName && lastName && uuid && ownerUuid
              ? { email, firstName, lastName, uuid, ownerUuid, isAdmin }
              : undefined;
      }
index ae753562170099f7972d6a9cebf99f26493ff944,9bd79884ff470e86e4bb9d08c79d53c5867989c3..6f59c9109ef597b1961ee73a3dc275b909183875
@@@ -47,6 -48,6 +47,9 @@@ export const loadVirtualMachinesData = 
          });
          dispatch(virtualMachinesActions.SET_VIRTUAL_MACHINES(virtualMachines));
          dispatch(virtualMachinesActions.SET_LINKS(links));
++        const getAllLogins = await services.virtualMachineService.getAllLogins();
++        console.log(getAllLogins);  
++        dispatch(virtualMachinesActions.SET_LOGINS(getAllLogins));
      };
  
  export const saveRequestedDate = () =>
index 5eb9b191944ef362249167fc0296fafaf72fb5ed,c94c3a74bb956a2506be60cfb762f1ad6f354571..504910e0f738537c7392d8c5d485210ced3b88b3
@@@ -76,7 -75,6 +76,7 @@@ interface VirtualMachinesPanelDataProp
      virtualMachines: ListResults<any>;
      logins: VirtualMachinesLoginsResource[];
      links: ListResults<any>;
-     isAdmin: string;
++    isAdmin: boolean;
  }
  
  interface VirtualMachinesPanelActionProps {
@@@ -149,34 -147,34 +149,64 @@@ const CardContentWithVirtualMachines = 
                          </Tooltip>
                      </a>
                  </div>
--                <Table>
--                    <TableHead>
--                        <TableRow>
--                            <TableCell>Host name</TableCell>
--                            <TableCell>Login name</TableCell>
--                            <TableCell>Command line</TableCell>
--                            <TableCell>Web shell</TableCell>
--                        </TableRow>
--                    </TableHead>
--                    <TableBody>
--                        {props.virtualMachines.items.map((it, index) =>
--                            <TableRow key={index}>
--                                <TableCell>{it.hostname}</TableCell>
--                                <TableCell>{getUsername(props.links, it)}</TableCell>
--                                <TableCell>ssh {getUsername(props.links, it)}@shell.arvados</TableCell>
--                                <TableCell>
--                                    <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${getUsername(props.links, it)}`} target="_blank" className={props.classes.link}>
--                                        Log in as {getUsername(props.links, it)}
--                                    </a>
--                                </TableCell>
--                            </TableRow>
--                        )}
--                    </TableBody>
--                </Table>
++                {console.log(props.isAdmin)}
++                {props.isAdmin ? adminVirtualMachinesTable(props) : userVirtualMachinesTable(props)}
              </CardContent>
          </Card>
      </Grid>;
  
++const userVirtualMachinesTable = (props: VirtualMachineProps) =>
++    <Table>
++        <TableHead>
++            <TableRow>
++                <TableCell>Host name</TableCell>
++                <TableCell>Login name</TableCell>
++                <TableCell>Command line</TableCell>
++                <TableCell>Web shell</TableCell>
++            </TableRow>
++        </TableHead>
++        <TableBody>
++            {props.virtualMachines.items.map((it, index) =>
++                <TableRow key={index}>
++                    <TableCell>{it.hostname}</TableCell>
++                    <TableCell>{getUsername(props.links, it)}</TableCell>
++                    <TableCell>ssh {getUsername(props.links, it)}@shell.arvados</TableCell>
++                    <TableCell>
++                        <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${getUsername(props.links, it)}`} target="_blank" className={props.classes.link}>
++                            Log in as {getUsername(props.links, it)}
++                        </a>
++                    </TableCell>
++                </TableRow>
++            )}
++        </TableBody>
++    </Table>;
++
++const adminVirtualMachinesTable = (props: VirtualMachineProps) =>
++    <Table>
++        <TableHead>
++            <TableRow>
++                <TableCell>Uuid</TableCell>
++                <TableCell>Host name</TableCell>
++                <TableCell>Logins</TableCell>
++                <TableCell/>
++            </TableRow>
++        </TableHead>
++        <TableBody>
++            {props.virtualMachines.items.map((it, index) =>
++                <TableRow key={index}>
++                    <TableCell>{it.uuid}</TableCell>
++                    <TableCell>shell</TableCell>
++                    <TableCell>ssh {getUsername(props.links, it)}@shell.arvados</TableCell>
++                    <TableCell>
++                        <a href={`https://workbench.c97qk.arvadosapi.com${it.href}/webshell/${getUsername(props.links, it)}`} target="_blank" className={props.classes.link}>
++                            Log in as {getUsername(props.links, it)}
++                        </a>
++                    </TableCell>
++                </TableRow>
++            )}
++        </TableBody>
++    </Table>;
++
  const getUsername = (links: ListResults<any>, virtualMachine: VirtualMachinesResource) => {
      const link = links.items.find((item: any) => item.headUuid === virtualMachine.uuid);
      return link.properties.username || undefined;