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

[NEW] Option to reset e2e key #12483

Merged
merged 6 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/rocketchat-authorization/server/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Meteor.startup(function() {
{ _id: 'mention-here', roles : ['admin', 'owner', 'moderator', 'user'] },
{ _id: 'mute-user', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'remove-user', roles : ['admin', 'owner', 'moderator'] },
{ _id: 'reset-other-user-e2e-key', roles : ['admin'] },
{ _id: 'run-import', roles : ['admin'] },
{ _id: 'run-migration', roles : ['admin'] },
{ _id: 'set-moderator', roles : ['admin', 'owner'] },
Expand Down
8 changes: 8 additions & 0 deletions packages/rocketchat-e2e/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ RocketChat.models.Users.findByIdsWithPublicE2EKey = function(ids, options) {

return this.find(query, options);
};

RocketChat.models.Users.resetE2EKey = function(userId) {
this.update({ _id: userId }, {
$unset: {
e2e: '',
},
});
};
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,8 @@
"Require_password_change": "Require password change",
"Resend_verification_email": "Resend verification email",
"Reset": "Reset",
"Reset_E2E_Key": "Reset E2E Key",
"reset-other-user-e2e-key": "Reset Other User E2E Key",
"Reset_password": "Reset password",
"Reset_section_settings": "Reset Section Settings",
"Reset_Connection": "Reset Connection",
Expand Down Expand Up @@ -2719,6 +2721,7 @@
"User_and_group_mentions_only": "User and group mentions only",
"User_default": "User default",
"User_doesnt_exist": "No user exists by the name of `@%s`.",
"User_e2e_key_was_reset": "User E2E key was reset successfully.",
"User_has_been_activated": "User has been activated",
"User_has_been_deactivated": "User has been deactivated",
"User_has_been_deleted": "User has been deleted",
Expand Down
15 changes: 15 additions & 0 deletions packages/rocketchat-ui-flextab/client/tabs/userActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,21 @@ export const getActions = function({ user, directActions, hideAdminControls }) {
name: t('Activate'),
action: prevent(getUser, ({ _id }) => Meteor.call('setUserActiveStatus', _id, true, success(() => toastr.success(t('User_has_been_activated'))))),
};
}, () => {
if (hideAdminControls || !hasPermission('reset-other-user-e2e-key')) {
return;
}
if (!RocketChat.settings.get('E2E_Enable')) {
return;
}

return {
group: 'admin',
icon: 'key',
id: 'reset-e2e',
name: t('Reset_E2E_Key'),
action: prevent(getUser, ({ _id }) => Meteor.call('resetUserE2EKey', _id, success(() => toastr.success(t('User_e2e_key_was_reset'))))),
};
}];
return actions;
};
20 changes: 20 additions & 0 deletions server/methods/resetUserE2EKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Meteor.methods({
resetUserE2EKey(userId) {
check(userId, String);

if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'resetUserE2EKey',
});
}

if (RocketChat.authz.hasPermission(Meteor.userId(), 'reset-other-user-e2e-key') !== true) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'resetUserE2EKey',
});
}

RocketChat.models.Users.resetE2EKey(userId);
Hudell marked this conversation as resolved.
Show resolved Hide resolved
return true;
},
});