Skip to content

Commit

Permalink
feat: enabled password reset during user creation
Browse files Browse the repository at this point in the history
Ticket: MEN-7192
Changelog: Title
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
  • Loading branch information
mzedel committed May 15, 2024
1 parent cab752c commit 3c6c02c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
22 changes: 12 additions & 10 deletions src/js/actions/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,18 @@ const actions = {

const userActionErrorHandler = (err, type, dispatch) => commonErrorHandler(err, `There was an error ${actions[type].errorMessage} the user.`, dispatch);

export const createUser = userData => dispatch =>
GeneralApi.post(`${useradmApiUrl}/users`, userData)
.then(() =>
Promise.all([
dispatch({ type: UserConstants.CREATED_USER, user: userData }),
dispatch(getUserList()),
dispatch(setSnackbar(actions.create.successMessage))
])
)
.catch(err => userActionErrorHandler(err, 'create', dispatch));
export const createUser =
({ shouldResetPassword, ...userData }) =>
dispatch =>
GeneralApi.post(`${useradmApiUrl}/users`, { ...userData, send_reset_password: shouldResetPassword })
.then(() =>
Promise.all([
dispatch({ type: UserConstants.CREATED_USER, user: userData }),
dispatch(getUserList()),
dispatch(setSnackbar(actions.create.successMessage))
])
)
.catch(err => userActionErrorHandler(err, 'create', dispatch));

export const removeUser = userId => dispatch =>
GeneralApi.delete(`${useradmApiUrl}/users/${userId}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ label[data-shrink=false]+.MuiInputBase-formControl .emotion-32:focus::-ms-input-
<input
class="PrivateSwitchBase-input emotion-25"
data-indeterminate="false"
name="shouldResetPassword"
type="checkbox"
/>
<svg
Expand Down
11 changes: 2 additions & 9 deletions src/js/components/settings/user-management/userform.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
DialogContent,
DialogTitle,
FormControl,
FormControlLabel,
FormHelperText,
InputLabel,
ListItemText,
Expand All @@ -34,9 +33,9 @@ import pluralize from 'pluralize';

import { BENEFITS } from '../../../constants/appConstants';
import { rolesById, rolesByName, uiPermissionsById } from '../../../constants/userConstants';
import { toggle } from '../../../helpers';
import EnterpriseNotification from '../../common/enterpriseNotification';
import Form from '../../common/forms/form';
import FormCheckbox from '../../common/forms/formcheckbox';
import PasswordInput from '../../common/forms/passwordinput';
import TextInput from '../../common/forms/textinput';

Expand Down Expand Up @@ -138,7 +137,6 @@ const PasswordLabel = () => (
export const UserForm = ({ closeDialog, currentUser, canManageUsers, isEnterprise, roles, submit }) => {
const [hadRoleChanges, setHadRoleChanges] = useState(false);
const [selectedRoles, setSelectedRoles] = useState();
const [shouldResetPassword, setShouldResetPassword] = useState(false);

const onSelect = (newlySelectedRoles, hadRoleChanges) => {
setSelectedRoles(newlySelectedRoles);
Expand All @@ -151,8 +149,6 @@ export const UserForm = ({ closeDialog, currentUser, canManageUsers, isEnterpris
return submit({ ...remainder, ...roleData, password }, 'create');
};

const togglePasswordReset = () => setShouldResetPassword(toggle);

return (
<Dialog open={true} fullWidth={true} maxWidth="sm">
<DialogTitle>Create new user</DialogTitle>
Expand All @@ -171,10 +167,7 @@ export const UserForm = ({ closeDialog, currentUser, canManageUsers, isEnterpris
placeholder="Password"
validations="isLength:8"
/>
<FormControlLabel
control={<Checkbox checked={shouldResetPassword} onChange={togglePasswordReset} />}
label="Send an email to the user containing a link to reset the password"
/>
<FormCheckbox id="shouldResetPassword" label="Send an email to the user containing a link to reset the password" />
<UserRolesSelect currentUser={currentUser} disabled={!(canManageUsers && isEnterprise)} onSelect={onSelect} roles={roles} user={{}} />
</Form>
</DialogContent>
Expand Down

0 comments on commit 3c6c02c

Please sign in to comment.