Mutes: Add locks to prevent multiple simultaneous attempts to mute a user

This commit is contained in:
Dragory 2020-06-14 23:59:51 +03:00
parent 00aeab6cdd
commit b4e034e3d8
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -150,8 +150,11 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
reason: string = null,
muteOptions: MuteOptions = {},
): Promise<MuteResult> {
const lock = await this.locks.acquire(`mute-${userId}`);
const muteRole = this.getConfig().mute_role;
if (!muteRole) {
lock.unlock();
this.throwRecoverablePluginError(ERRORS.NO_MUTE_ROLE_IN_CONFIG);
}
@ -287,6 +290,8 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
});
}
lock.unlock();
return {
case: theCase,
notifyResult,