Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: Admin user can use reset-password without email settings #7650

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/app/public/static/locales/en_US/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,9 @@
},
"reset_password": "Reset Password",
"reset_password_modal": {
"reset_password_info": "When a password is reset, a newly password is sent to the target user.",
"password_reset_message": "The temporary password was sent to the below user and strongly recommend to change another one immediately.",
"reset_password_alert": "If the e-mail transmission fails, please make sure that e-mail settings are correct and reset password again.",
"password_never_seen": "The temporary password can never be retrieved after this screen is closed.",
"password_reset_message": "Let the user know the new password below and strongly recommend to change another one immediately.",
"send_new_password": "Please send the new password to the user.",
"target_user": "Target User",
"new_password": "New Password"
},
Expand Down
6 changes: 3 additions & 3 deletions apps/app/public/static/locales/ja_JP/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@
},
"reset_password": "パスワードのリセット",
"reset_password_modal": {
"reset_password_info": "パスワードをリセットすると新規発行したパスワードを対象ユーザーに送信します。",
"password_reset_message": "対象ユーザーに一時的なパスワードを送信しました。新しく別のパスワードを設定するよう伝えてください。",
"reset_password_alert": "送信に失敗した場合はメール設定が正しいことを確認し再度パスワードのリセットを行ってください",
"password_never_seen": "表示されたパスワードはこの画面を閉じると二度と表示できませんのでご注意ください。",
"password_reset_message": "対象ユーザーに下記のパスワードを伝え、すぐに新しく別のパスワードを設定するよう伝えてください。",
"send_new_password": "新規発行したパスワードを、対象ユーザーへ連絡してください。",
"target_user": "対象ユーザー",
"new_password": "新しいパスワード"
},
Expand Down
6 changes: 3 additions & 3 deletions apps/app/public/static/locales/zh_CN/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@
},
"reset_password": "重置密码",
"reset_password_modal": {
"reset_password_info": "When a password is reset, a newly password is sent to the target user.",
"password_reset_message": "The temporary password was sent to the below user and strongly recommend to change another one immediately.",
"reset_password_alert": "If the e-mail transmission fails, please make sure that e-mail settings are correct and reset password again.",
"password_never_seen": "The temporary password can never be retrieved after this screen is closed.",
"password_reset_message": "Let the user know the new password below and strongly recommend to change another one immediately.",
"send_new_password": "Please send the new password to the user.",
"target_user": "Target User",
"new_password": "New Password"
},
Expand Down
11 changes: 0 additions & 11 deletions apps/app/resource/locales/en_US/admin/userResetPassword.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後続タスクで使うので残す

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました

This file was deleted.

12 changes: 0 additions & 12 deletions apps/app/resource/locales/ja_JP/admin/userResetPassword.txt

This file was deleted.

11 changes: 0 additions & 11 deletions apps/app/resource/locales/zh_CN/admin/userResetPassword.txt

This file was deleted.

13 changes: 9 additions & 4 deletions apps/app/src/components/Admin/Users/PasswordResetModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PasswordResetModal extends React.Component {
super(props);

this.state = {
temporaryPassword: [],
isPasswordResetDone: false,
};

Expand All @@ -25,8 +26,9 @@ class PasswordResetModal extends React.Component {
async resetPassword() {
const { t, userForPasswordResetModal } = this.props;
try {
await apiv3Put('/users/reset-password', { id: userForPasswordResetModal._id });
this.setState({ isPasswordResetDone: true });
const res = await apiv3Put('/users/reset-password', { id: userForPasswordResetModal._id });
const { newPassword } = res.data;
this.setState({ temporaryPassword: newPassword, isPasswordResetDone: true });
}
catch (err) {
toastError(err);
Expand All @@ -39,8 +41,8 @@ class PasswordResetModal extends React.Component {
return (
<>
<p>
{t('user_management.reset_password_modal.reset_password_info')}<br />
<span className="text-danger">{t('user_management.reset_password_modal.reset_password_alert')}</span>
{t('user_management.reset_password_modal.password_never_seen')}<br />
<span className="text-danger">{t('user_management.reset_password_modal.send_new_password')}</span>
</p>
<p>
{t('user_management.reset_password_modal.target_user')}: <code>{userForPasswordResetModal.email}</code>
Expand All @@ -58,6 +60,9 @@ class PasswordResetModal extends React.Component {
<p>
{t('user_management.reset_password_modal.target_user')}: <code>{userForPasswordResetModal.email}</code>
</p>
<p>
{t('user_management.reset_password_modal.new_password')}: <code>{this.state.temporaryPassword}</code>
</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

欲を言えば collapse で隠したい

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後続ストーリーに記載しました。

</>
);
}
Expand Down
37 changes: 7 additions & 30 deletions apps/app/src/server/routes/apiv3/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,52 +835,29 @@ module.exports = (crowi) => {
* application/json:
* schema:
* properties:
* id:
* newPassword:
* type: string
* user:
* type: string
* description: user id for reset password
* responses:
* 200:
* description: success resrt password
*/
router.put('/reset-password', loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
const { appService, mailService } = crowi;
const { id } = req.body;

let newPassword;
let user;

try {
[newPassword, user] = await Promise.all([
const [newPassword, user] = await Promise.all([
await User.resetPasswordByRandomString(id),
await User.findById(id)]);

activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_ADMIN_USERS_PASSWORD_RESET });
return res.apiv3({ newPassword, user });
}
catch (err) {
const msg = 'Error occurred during password reset request procedure.';
logger.error(err);
return res.apiv3Err(`${msg} Cause: ${err}`);
}

try {
await mailService.send({
to: user.email,
subject: 'Your password has been reset by the administrator',
template: path.join(crowi.localeDir, 'en_US/admin/userResetPassword.txt'),
vars: {
email: user.email,
password: newPassword,
url: crowi.appService.getSiteUrl(),
appTitle: appService.getAppTitle(),
},
});

return res.apiv3({});
}
catch (err) {
const msg = 'Error occurred during password reset send e-mail.';
logger.error(err);
return res.apiv3Err(`${msg} Cause: ${err}`);
logger.error('Error', err);
return res.apiv3Err(new ErrorV3(err));
}
});

Expand Down