[NEW] Option to reset e2e key (#12483)
* Added option to reset e2e key * Reset e2e keypull/12684/head
parent
2882438c04
commit
9289e5b7be
@ -0,0 +1,33 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { RocketChat } from 'meteor/rocketchat:lib'; |
||||
|
||||
Meteor.methods({ |
||||
'e2e.requestSubscriptionKeys'() { |
||||
if (!Meteor.userId()) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { |
||||
method: 'requestSubscriptionKeys', |
||||
}); |
||||
} |
||||
|
||||
// Get all encrypted rooms that the user is subscribed to
|
||||
|
||||
const subscriptions = RocketChat.models.Subscriptions.findByUserId(Meteor.userId()); |
||||
const roomIds = subscriptions.map((subscription) => subscription.rid); |
||||
|
||||
const query = { |
||||
e2eKeyId : { |
||||
$exists: true, |
||||
}, |
||||
_id : { |
||||
$in: roomIds, |
||||
}, |
||||
}; |
||||
|
||||
const rooms = RocketChat.models.Rooms.find(query); |
||||
rooms.forEach((room) => { |
||||
RocketChat.Notifications.notifyRoom('e2e.keyRequest', room._id, room.e2eKeyId); |
||||
}); |
||||
|
||||
return true; |
||||
}, |
||||
}); |
@ -0,0 +1,25 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { RocketChat } from 'meteor/rocketchat:lib'; |
||||
|
||||
Meteor.methods({ |
||||
'e2e.resetUserE2EKey'(userId) { |
||||
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); |
||||
RocketChat.models.Subscriptions.resetUserE2EKey(userId); |
||||
|
||||
// Force the user to logout, so that the keys can be generated again
|
||||
RocketChat.models.Users.removeResumeService(userId); |
||||
return true; |
||||
}, |
||||
}); |
Loading…
Reference in new issue