1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Field, InjectedFormProps } from "redux-form";
7 import { TextField } from "components/text-field/text-field";
8 import { DataExplorer } from "views-components/data-explorer/data-explorer";
9 import { NativeSelectField } from "components/select-field/select-field";
22 } from '@material-ui/core';
23 import { ArvadosTheme } from 'common/custom-theme';
24 import { User } from "models/user";
25 import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
26 import { MY_ACCOUNT_VALIDATION } from "validators/validators";
27 import { USER_PROFILE_PANEL_ID } from 'store/user-profile/user-profile-actions';
28 import { noop } from 'lodash';
29 import { GroupsIcon } from 'components/icon/icon';
30 import { DataColumns } from 'components/data-table/data-table';
31 import { ResourceLinkHeadUuid, ResourceLinkHeadPermissionLevel, ResourceLinkHead, ResourceLinkDelete, ResourceLinkTailIsVisible } from 'views-components/data-explorer/renderers';
32 import { createTree } from 'models/tree';
34 type CssRules = 'root' | 'adminRoot' | 'gridItem' | 'label' | 'readOnlyValue' | 'title' | 'description' | 'actions' | 'content';
36 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 // ...theme.mixins.gutters()
50 color: theme.palette.grey['600']
59 color: theme.palette.grey["600"]
63 justifyContent: 'flex-end'
66 // reserve space for the tab bar
67 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
71 export interface UserProfilePanelRootActionProps {
72 openSetupShellAccount: (uuid: string) => void;
73 loginAs: (uuid: string) => void;
74 openDeactivateDialog: (uuid: string) => void;
77 export interface UserProfilePanelRootDataProps {
87 { key: 'Bio-informatician', value: 'Bio-informatician' },
88 { key: 'Data Scientist', value: 'Data Scientist' },
89 { key: 'Analyst', value: 'Analyst' },
90 { key: 'Researcher', value: 'Researcher' },
91 { key: 'Software Developer', value: 'Software Developer' },
92 { key: 'System Administrator', value: 'System Administrator' },
93 { key: 'Other', value: 'Other' }
96 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & WithStyles<CssRules>;
98 export enum UserProfileGroupsColumnNames {
100 PERMISSION = "Permission",
101 VISIBLE = "Visible to other members",
113 export const userProfileGroupsColumns: DataColumns<string> = [
115 name: UserProfileGroupsColumnNames.NAME,
118 filters: createTree(),
119 render: uuid => <ResourceLinkHead uuid={uuid} />
122 name: UserProfileGroupsColumnNames.PERMISSION,
125 filters: createTree(),
126 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
129 name: UserProfileGroupsColumnNames.VISIBLE,
132 filters: createTree(),
133 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
136 name: UserProfileGroupsColumnNames.UUID,
139 filters: createTree(),
140 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
143 name: UserProfileGroupsColumnNames.REMOVE,
146 filters: createTree(),
147 render: uuid => <ResourceLinkDelete uuid={uuid} />
151 const ReadOnlyField = withStyles(styles)(
152 (props: ({ label: string, input: {value: string} }) & WithStyles<CssRules> ) => (
154 <Typography className={props.classes.label}>
157 <Typography className={props.classes.readOnlyValue}>
164 export const UserProfilePanelRoot = withStyles(styles)(
165 class extends React.Component<UserProfilePanelRootProps> {
170 componentDidMount() {
171 this.setState({ value: TABS.PROFILE});
175 return <Paper className={this.props.classes.root}>
176 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
177 <Tab label={TABS.PROFILE} value={TABS.PROFILE} />
178 <Tab label={TABS.GROUPS} value={TABS.GROUPS} />
179 {this.props.isAdmin && <Tab label={TABS.ADMIN} value={TABS.ADMIN} />}
181 {this.state.value === TABS.PROFILE &&
183 <form onSubmit={this.props.handleSubmit}>
184 <Grid container spacing={24}>
185 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
189 component={ReadOnlyField as any}
193 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
197 component={ReadOnlyField as any}
201 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
205 component={ReadOnlyField as any}
209 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
213 component={ReadOnlyField as any}
217 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
220 name="prefs.profile.organization"
221 component={TextField as any}
222 validate={MY_ACCOUNT_VALIDATION}
223 disabled={!this.props.isAdmin && !this.props.isSelf}
226 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
228 label="E-mail at Organization"
229 name="prefs.profile.organization_email"
230 component={TextField as any}
231 validate={MY_ACCOUNT_VALIDATION}
232 disabled={!this.props.isAdmin && !this.props.isSelf}
235 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
236 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
238 id="prefs.profile.role"
239 name="prefs.profile.role"
240 component={NativeSelectField as any}
242 disabled={!this.props.isAdmin && !this.props.isSelf}
245 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
248 name="prefs.profile.website_url"
249 component={TextField as any}
250 disabled={!this.props.isAdmin && !this.props.isSelf}
254 <Grid container direction="row" justify="flex-end">
255 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
260 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
269 {this.state.value === TABS.GROUPS &&
270 <div className={this.props.classes.content}>
272 id={USER_PROFILE_PANEL_ID}
274 onRowDoubleClick={noop}
275 contextMenuColumn={false}
281 dataTableDefaultView={
282 <DataTableDefaultView
284 messages={['Group list is empty.']} />
287 {this.props.isAdmin && this.state.value === TABS.ADMIN &&
288 <Paper elevation={0} className={this.props.classes.adminRoot}>
294 alignItems={'center'}>
296 <Typography variant="h6" className={this.props.classes.title}>
299 <Typography variant="body1" className={this.props.classes.description}>
300 This button sets up a user. After setup, they will be able use Arvados. This dialog box also allows you to optionally set up a shell account for this user. The login name is automatically generated from the user's e-mail address.
303 <Grid item sm={'auto'} xs={12}>
304 <Button variant="contained"
306 onClick={() => {this.props.openSetupShellAccount(this.props.initialValues.uuid)}}
319 alignItems={'center'}>
321 <Typography variant="h6" className={this.props.classes.title}>
324 <Typography variant="body1" className={this.props.classes.description}>
325 As an admin, you can deactivate and reset this user. This will remove all repository/VM permissions for the user. If you "setup" the user again, the user will have to sign the user agreement again. You may also want to reassign data ownership.
328 <Grid item sm={'auto'} xs={12}>
329 <Button variant="contained"
331 onClick={() => {this.props.openDeactivateDialog(this.props.initialValues.uuid)}}
344 alignItems={'center'}>
346 <Typography variant="h6" className={this.props.classes.title}>
349 <Typography variant="body1" className={this.props.classes.description}>
350 As an admin, you can log in as this user. When you’ve finished, you will need to log out and log in again with your own account.
353 <Grid item sm={'auto'} xs={12}>
354 <Button variant="contained"
356 onClick={() => {this.props.loginAs(this.props.initialValues.uuid)}}
368 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
369 this.setState({ value });