18559: Disable user profile form fields when not admin or self
authorStephen Smith <stephen@curii.com>
Wed, 2 Mar 2022 22:22:22 +0000 (17:22 -0500)
committerStephen Smith <stephen@curii.com>
Wed, 2 Mar 2022 22:22:22 +0000 (17:22 -0500)
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen@curii.com>

src/components/select-field/select-field.tsx
src/views/user-profile-panel/user-profile-panel-root.tsx
src/views/user-profile-panel/user-profile-panel.tsx

index e4dcad6c109fdd75cfb2cb14102d161272ceb649..6fa7ddea626396494cc6f3cc5a2e01887a15da7d 100644 (file)
@@ -35,14 +35,18 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     }
 });
 
+interface NativeSelectFieldProps {
+    disabled?: boolean;
+}
+
 export const NativeSelectField = withStyles(styles)
-    ((props: WrappedFieldProps & WithStyles<CssRules> & { items: any[] }) =>
+    ((props: WrappedFieldProps & NativeSelectFieldProps & WithStyles<CssRules> & { items: any[] }) =>
         <FormControl className={props.classes.formControl}>
             <Select className={props.classes.selectWrapper}
                 native
                 value={props.input.value}
                 onChange={props.input.onChange}
-                disabled={props.meta.submitting}
+                disabled={props.meta.submitting || props.disabled}
                 name={props.input.name}
                 inputProps={{
                     id: `id-${props.input.name}`,
@@ -81,4 +85,4 @@ export const SelectField = withStyles(selectFieldStyles)(
             </Select>
             <FormHelperText>{props.meta.error}</FormHelperText>
         </FormControl>
-);
\ No newline at end of file
+);
index a725333d1b1712673a498be0597f77f4a9de6147..76cad8a508063a016f07a08602a9313b4955b5cd 100644 (file)
@@ -71,6 +71,8 @@ export interface UserProfilePanelRootActionProps {
 }
 
 export interface UserProfilePanelRootDataProps {
+    isAdmin: boolean;
+    isSelf: boolean;
     isPristine: boolean;
     isValid: boolean;
     initialValues?: User;
@@ -150,95 +152,97 @@ export const UserProfilePanelRoot = withStyles(styles)(
                 <Tabs value={this.state.value} onChange={this.handleChange} variant={"fullWidth"}>
                     <Tab label="PROFILE" />
                     <Tab label="GROUPS" />
-                    <Tab label="ADMIN" />
+                    <Tab label="ADMIN" disabled={!this.props.isAdmin} />
                 </Tabs>
                 {this.state.value === 0 &&
-                    // <Card className={this.props.classes.root}>
-                        <CardContent>
-                            <form onSubmit={this.props.handleSubmit}>
-                                <Grid container spacing={24}>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="First name"
-                                            name="firstName"
-                                            component={TextField as any}
-                                            disabled
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="Last name"
-                                            name="lastName"
-                                            component={TextField as any}
-                                            disabled
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="E-mail"
-                                            name="email"
-                                            component={TextField as any}
-                                            disabled
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="Username"
-                                            name="username"
-                                            component={TextField as any}
-                                            disabled
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="Organization"
-                                            name="prefs.profile.organization"
-                                            component={TextField as any}
-                                            validate={MY_ACCOUNT_VALIDATION}
-                                            required
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="E-mail at Organization"
-                                            name="prefs.profile.organization_email"
-                                            component={TextField as any}
-                                            validate={MY_ACCOUNT_VALIDATION}
-                                            required
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
-                                        <Field
-                                            id="prefs.profile.role"
-                                            name="prefs.profile.role"
-                                            component={NativeSelectField as any}
-                                            items={RoleTypes}
-                                        />
-                                    </Grid>
-                                    <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
-                                        <Field
-                                            label="Website"
-                                            name="prefs.profile.website_url"
-                                            component={TextField as any}
-                                        />
-                                    </Grid>
-                                    <Grid item sm={12}>
-                                        <Grid container direction="row" justify="flex-end">
-                                            <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
-                                            <Button
-                                                color="primary"
-                                                variant="contained"
-                                                type="submit"
-                                                disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
-                                                Save changes
-                                            </Button>
-                                        </Grid>
+                    <CardContent>
+                        <form onSubmit={this.props.handleSubmit}>
+                            <Grid container spacing={24}>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="First name"
+                                        name="firstName"
+                                        component={TextField as any}
+                                        disabled
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="Last name"
+                                        name="lastName"
+                                        component={TextField as any}
+                                        disabled
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="E-mail"
+                                        name="email"
+                                        component={TextField as any}
+                                        disabled
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="Username"
+                                        name="username"
+                                        component={TextField as any}
+                                        disabled
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="Organization"
+                                        name="prefs.profile.organization"
+                                        component={TextField as any}
+                                        validate={MY_ACCOUNT_VALIDATION}
+                                        required
+                                        disabled={!this.props.isAdmin && !this.props.isSelf}
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="E-mail at Organization"
+                                        name="prefs.profile.organization_email"
+                                        component={TextField as any}
+                                        validate={MY_ACCOUNT_VALIDATION}
+                                        required
+                                        disabled={!this.props.isAdmin && !this.props.isSelf}
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <InputLabel className={this.props.classes.label} htmlFor="prefs.profile.role">Role</InputLabel>
+                                    <Field
+                                        id="prefs.profile.role"
+                                        name="prefs.profile.role"
+                                        component={NativeSelectField as any}
+                                        items={RoleTypes}
+                                        disabled={!this.props.isAdmin && !this.props.isSelf}
+                                    />
+                                </Grid>
+                                <Grid item className={this.props.classes.gridItem} sm={6} xs={12}>
+                                    <Field
+                                        label="Website"
+                                        name="prefs.profile.website_url"
+                                        component={TextField as any}
+                                        disabled={!this.props.isAdmin && !this.props.isSelf}
+                                    />
+                                </Grid>
+                                <Grid item sm={12}>
+                                    <Grid container direction="row" justify="flex-end">
+                                        <Button color="primary" onClick={this.props.reset} disabled={this.props.isPristine}>Discard changes</Button>
+                                        <Button
+                                            color="primary"
+                                            variant="contained"
+                                            type="submit"
+                                            disabled={this.props.isPristine || this.props.invalid || this.props.submitting}>
+                                            Save changes
+                                        </Button>
                                     </Grid>
                                 </Grid>
-                            </form >
-                        </CardContent>
-                    // </Card>
+                            </Grid>
+                        </form >
+                    </CardContent>
                 }
                 {this.state.value === 1 &&
                     <div className={this.props.classes.content}>
index caac3e8cd4abca9511dfc423755457484a7eafe5..2bafd9faf9b45f57cea8cef8934e4f37265aebc1 100644 (file)
@@ -23,7 +23,8 @@ const mapStateToProps = (state: RootState): UserProfilePanelRootDataProps => {
   // const subprocesses = getSubprocesses(uuid)(resources);
 
   return {
-
+    isAdmin: state.auth.user!.isAdmin,
+    isSelf: state.auth.user!.uuid === uuid,
     isPristine: isPristine(USER_PROFILE_FORM)(state),
     isValid: isValid(USER_PROFILE_FORM)(state),
     initialValues: user,