The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/app/invites/server/functions/removeInvite.ts

35 lines
959 B

import { Meteor } from 'meteor/meteor';
import { Invites } from '@rocket.chat/models';
import type { IInvite } from '@rocket.chat/core-typings';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
export const removeInvite = async (userId: string, invite: Pick<IInvite, '_id'>) => {
if (!userId || !invite) {
return false;
}
if (!(await hasPermissionAsync(userId, 'create-invite-links'))) {
throw new Meteor.Error('not_authorized');
}
if (!invite._id) {
throw new Meteor.Error('error-the-field-is-required', 'The field _id is required', {
method: 'removeInvite',
field: '_id',
});
}
// Before anything, let's check if there's an existing invite
const existing = await Invites.findOneById(invite._id);
if (!existing) {
throw new Meteor.Error('invalid-invitation-id', 'Invalid Invitation _id', {
method: 'removeInvite',
});
}
await Invites.removeById(invite._id);
return true;
};