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

Prevent admin from invalidating their own password #708

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/user/row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ except according to the terms contained in the LICENSE file.
{{ $t('action.editProfile') }}
</router-link>
</li>
<li>
<li :class="{ disabled }">
<a class="reset-password" href="#"
v-tooltip.aria-describedby="disabled ? $t('cannotResetPassword') : null"
@click.prevent="$emit('reset-password', user)">
Comment on lines +49 to 52
Copy link
Member Author

Choose a reason for hiding this comment

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

This is very similar to how we disable the retire button directly below.

{{ $t('action.resetPassword') }}&hellip;
</a>
Expand Down Expand Up @@ -158,6 +159,9 @@ export default {
"field": {
"sitewideRole": "Sitewide Role"
},
// An Administrator may reset the password for another Web User, but not for
// their own account.
"cannotResetPassword": "You may not reset your own password on this page. To change your password, edit your profile.",
// An Administrator may retire other Web Users, but not their own account.
"cannotRetire": "You may not retire yourself.",
"action": {
Expand Down
22 changes: 16 additions & 6 deletions test/components/user/reset-password.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ describe('UserResetPassword', () => {
mockLogin({ email: '[email protected]', displayName: 'Alice' });
});

it('toggles the modal', () =>
load('/users', { root: false }).testModalToggles({
modal: UserResetPassword,
show: '.user-row .reset-password',
hide: '.btn-link'
}));
describe('reset password button', () => {
it('toggles the modal', () =>
load('/users', { root: false }).testModalToggles({
modal: UserResetPassword,
show: '.user-row .reset-password',
hide: '.btn-link'
}));

it('is disabled for the current user', async () => {
const component = await load('/users', { root: false });
const a = component.get('.user-row .reset-password');
a.element.parentNode.classList.contains('disabled').should.be.true();
a.should.have.ariaDescription(/^You may not reset your own password/);
await a.should.have.tooltip();
});
Comment on lines +24 to +30
Copy link
Member Author

Choose a reason for hiding this comment

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

This is very similar to the test in test/components/user/retire.spec.js that the retire button is disabled for the current user.

});

it('sends the correct request', () =>
mockHttp()
Expand Down
4 changes: 4 additions & 0 deletions transifex/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3852,6 +3852,10 @@
"developer_comment": "This is the text of a form field."
}
},
"cannotResetPassword": {
"string": "You may not reset your own password on this page. To change your password, edit your profile.",
"developer_comment": "An Administrator may reset the password for another Web User, but not for their own account."
},
"cannotRetire": {
"string": "You may not retire yourself.",
"developer_comment": "An Administrator may retire other Web Users, but not their own account."
Expand Down