Improved handling of tiers, made guest tier funcitonal, improved invites

This commit is contained in:
Thaum Rystra
2020-05-12 15:28:43 +02:00
parent bbda0ea1b6
commit b6c7ea8c4f
9 changed files with 126 additions and 69 deletions

View File

@@ -145,7 +145,41 @@ const acceptInviteToken = new ValidatedMethod({
},
});
const revokeInvite = new ValidatedMethod({
name: 'Invites.methods.revokeInvite',
validate: new SimpleSchema({
inviteId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
},
}).validator(),
run({inviteId}) {
if (!this.userId) {
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
'You need to be the logged in to revoke a token');
}
if (Meteor.isClient) return;
let invite = Invites.findOne(inviteId);
if (!invite){
throw new Meteor.Error('Invites.methods.revokeInvite.notFound',
'No invite could be found for this id');
}
if (this.userId !== invite.inviter) {
throw new Meteor.Error('Invites.methods.revokeInvite.denied',
'You are not the owner of this invite');
}
// If the invitee is empty, the token has already been revoked
if (!invite.invitee){
return;
}
Invites.update(invite._id, {
$unset: {invitee: 1, dateConfirmed: 1},
});
},
});
Invites.attachSchema(InviteSchema);
export default Invites;
export { alignInvitesWithPatreonTier, getInviteToken, acceptInviteToken };
export { alignInvitesWithPatreonTier, getInviteToken, acceptInviteToken, revokeInvite };