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' | 'title' | 'description' | 'actions' | 'content';
36 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 // ...theme.mixins.gutters()
55 color: theme.palette.grey["600"]
59 justifyContent: 'flex-end'
62 // reserve space for the tab bar
63 height: `calc(100% - ${theme.spacing.unit * 7}px)`,
67 export interface UserProfilePanelRootActionProps {
68 openSetupShellAccount: (uuid: string) => void;
69 loginAs: (uuid: string) => void;
70 openDeactivateDialog: (uuid: string) => void;
73 export interface UserProfilePanelRootDataProps {
83 { key: 'Bio-informatician', value: 'Bio-informatician' },
84 { key: 'Data Scientist', value: 'Data Scientist' },
85 { key: 'Analyst', value: 'Analyst' },
86 { key: 'Researcher', value: 'Researcher' },
87 { key: 'Software Developer', value: 'Software Developer' },
88 { key: 'System Administrator', value: 'System Administrator' },
89 { key: 'Other', value: 'Other' }
92 type UserProfilePanelRootProps = InjectedFormProps<{}> & UserProfilePanelRootActionProps & UserProfilePanelRootDataProps & WithStyles<CssRules>;
94 export enum UserProfileGroupsColumnNames {
96 PERMISSION = "Permission",
97 VISIBLE = "Visible to other members",
102 export const userProfileGroupsColumns: DataColumns<string> = [
104 name: UserProfileGroupsColumnNames.NAME,
107 filters: createTree(),
108 render: uuid => <ResourceLinkHead uuid={uuid} />
111 name: UserProfileGroupsColumnNames.PERMISSION,
114 filters: createTree(),
115 render: uuid => <ResourceLinkHeadPermissionLevel uuid={uuid} />
118 name: UserProfileGroupsColumnNames.VISIBLE,
121 filters: createTree(),
122 render: uuid => <ResourceLinkTailIsVisible uuid={uuid} />
125 name: UserProfileGroupsColumnNames.UUID,
128 filters: createTree(),
129 render: uuid => <ResourceLinkHeadUuid uuid={uuid} />
132 name: UserProfileGroupsColumnNames.REMOVE,
135 filters: createTree(),
136 render: uuid => <ResourceLinkDelete uuid={uuid} />
140 export const UserProfilePanelRoot = withStyles(styles)(
141 class extends React.Component<UserProfilePanelRootProps> {
146 componentDidMount() {
147 this.setState({ value: 0 });
151 return <Paper className={this.props.classes.root}>
152 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
153 <Tab label="PROFILE" />
154 <Tab label="GROUPS" />
155 <Tab label="ADMIN" disabled={!this.props.isAdmin} />
157 {this.state.value === 0 &&
159 <form onSubmit={this.props.handleSubmit}>
160 <Grid container spacing={24}>
161 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
165 component={TextField as any}
169 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
173 component={TextField as any}
177 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
181 component={TextField as any}
185 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
189 component={TextField as any}
193 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
196 name="prefs.profile.organization"
197 component={TextField as any}
198 validate={MY_ACCOUNT_VALIDATION}
200 disabled={!this.props.isAdmin && !this.props.isSelf}
203 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
205 label="E-mail at Organization"
206 name="prefs.profile.organization_email"
207 component={TextField as any}
208 validate={MY_ACCOUNT_VALIDATION}
210 disabled={!this.props.isAdmin && !this.props.isSelf}
213 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
214 <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
216 id="prefs.profile.role"
217 name="prefs.profile.role"
218 component={NativeSelectField as any}
220 disabled={!this.props.isAdmin && !this.props.isSelf}
223 <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
226 name="prefs.profile.website_url"
227 component={TextField as any}
228 disabled={!this.props.isAdmin && !this.props.isSelf}
232 <Grid container direction="row" justify="flex-end">
233 <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
238 disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
247 {this.state.value === 1 &&
248 <div className={this.props.classes.content}>
250 id={USER_PROFILE_PANEL_ID}
252 onRowDoubleClick={noop}
253 contextMenuColumn={false}
259 dataTableDefaultView={
260 <DataTableDefaultView
262 messages={['Group list is empty.']} />
265 {this.state.value === 2 &&
266 <Paper elevation={0} className={this.props.classes.adminRoot}>
272 alignItems={'center'}>
274 <Typography variant="h6" className={this.props.classes.title}>
277 <Typography variant="body1" className={this.props.classes.description}>
278 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.
281 <Grid item sm={'auto'} xs={12}>
282 <Button variant="contained"
284 onClick={() => {this.props.openSetupShellAccount(this.props.initialValues.uuid)}}
297 alignItems={'center'}>
299 <Typography variant="h6" className={this.props.classes.title}>
302 <Typography variant="body1" className={this.props.classes.description}>
303 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.
306 <Grid item sm={'auto'} xs={12}>
307 <Button variant="contained"
309 onClick={() => {this.props.openDeactivateDialog(this.props.initialValues.uuid)}}
322 alignItems={'center'}>
324 <Typography variant="h6" className={this.props.classes.title}>
327 <Typography variant="body1" className={this.props.classes.description}>
328 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.
331 <Grid item sm={'auto'} xs={12}>
332 <Button variant="contained"
334 onClick={() => {this.props.loginAs(this.props.initialValues.uuid)}}
346 handleChange = (event: React.MouseEvent<HTMLElement>, value: number) => {
347 this.setState({ value });