Skip to content
Snippets Groups Projects
Commit 470e60cf authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

feat(component-user): fix token issue and allow user to authenticate himself

parent 64412045
No related branches found
No related tags found
3 merge requests!222Sprint #26,!217Sprint #26,!200Component user add user
...@@ -27,6 +27,7 @@ import { ...@@ -27,6 +27,7 @@ import {
} from 'pubsweet-component-faraday-ui' } from 'pubsweet-component-faraday-ui'
const FormModal = ({ const FormModal = ({
edit,
roles, roles,
title, title,
titles, titles,
...@@ -39,10 +40,16 @@ const FormModal = ({ ...@@ -39,10 +40,16 @@ const FormModal = ({
initialValues, initialValues,
confirmText = 'OK', confirmText = 'OK',
cancelText = 'Cancel', cancelText = 'Cancel',
user,
}) => ( }) => (
<Root> <Root>
<IconButton icon="x" onClick={onClose} right={5} secondary top={5} /> <IconButton icon="x" onClick={onClose} right={5} secondary top={5} />
<H2>{title}</H2> <H2>{title}</H2>
{edit && (
<Text mb={1} secondary>
{get(user, 'email', '')}
</Text>
)}
<Formik <Formik
initialValues={initialValues} initialValues={initialValues}
onSubmit={onSubmit} onSubmit={onSubmit}
...@@ -53,30 +60,28 @@ const FormModal = ({ ...@@ -53,30 +60,28 @@ const FormModal = ({
errors.email = 'Required' errors.email = 'Required'
} }
if (get(values, 'affiliation', '') === '') {
errors.affiliation = 'Required'
}
return errors return errors
}} }}
> >
{({ handleSubmit, ...rest }) => ( {({ handleSubmit, ...rest }) => (
<Fragment> <Fragment>
<Row alignItems="baseline" mb={1} mt={1}> {!edit && (
<ItemOverrideAlert mr={1} vertical> <Row alignItems="baseline" mb={1} mt={1}>
<Label required>Email</Label> <ItemOverrideAlert mr={1} vertical>
<ValidatedFieldFormik <Label required>Email</Label>
component={TextField} <ValidatedFieldFormik
inline component={TextField}
name="email" inline
validate={[required]} name="email"
/> validate={[required]}
</ItemOverrideAlert> />
<ItemOverrideAlert ml={1} vertical> </ItemOverrideAlert>
<Label required>Role</Label> <ItemOverrideAlert ml={1} vertical>
<ValidatedMenuField name="role" options={roles} /> <Label required>Role</Label>
</ItemOverrideAlert> <ValidatedMenuField name="role" options={roles} />
</Row> </ItemOverrideAlert>
</Row>
)}
<Row mb={2}> <Row mb={2}>
<Item mr={1} vertical> <Item mr={1} vertical>
...@@ -109,8 +114,14 @@ const FormModal = ({ ...@@ -109,8 +114,14 @@ const FormModal = ({
</RowOverrideAlert> </RowOverrideAlert>
<Row mb={3}> <Row mb={3}>
<Item vertical> {edit && (
<Label required>Affiliation</Label> <ItemOverrideAlert mr={1} vertical>
<Label required>Role</Label>
<ValidatedMenuField name="role" options={roles} />
</ItemOverrideAlert>
)}
<Item ml={edit && 1} vertical>
<Label>Affiliation</Label>
<ValidatedFieldFormik <ValidatedFieldFormik
component={TextField} component={TextField}
inline inline
......
...@@ -26,7 +26,7 @@ module.exports = { ...@@ -26,7 +26,7 @@ module.exports = {
}, },
}, },
accessTokens: { accessTokens: {
confirmation: chance.hash(), passwordReset: chance.hash(),
unsubscribe: chance.hash(), unsubscribe: chance.hash(),
}, },
} }
......
...@@ -206,6 +206,14 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) { ...@@ -206,6 +206,14 @@ async function applyAuthenticatedUserPolicy(user, operation, object, context) {
) { ) {
return helpers.isOwner({ user, object: object.fragment }) return helpers.isOwner({ user, object: object.fragment })
} }
// allow user to authenticate itself
if (
get(object, 'type') === 'user' &&
get(object, 'id') === get(user, 'id')
) {
return true
}
} }
if (operation === 'PATCH') { if (operation === 'PATCH') {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment