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 };

View File

@@ -1,5 +1,6 @@
import { findLast } from 'lodash';
import getEntitledCents from '/imports/api/users/patreon/getEntitledCents.js';
import Invites from '/imports/api/users/Invites.js';
const TIERS = [
{
@@ -62,7 +63,14 @@ export function getUserTier(user){
if (!user) throw 'User not found';
}
const entitledCents = getEntitledCents(user);
return getTierByEntitledCents(entitledCents);
const tier = getTierByEntitledCents(entitledCents);
if (tier.paidBenefits) return tier;
let invite = Invites.findOne({invitee: user._id, isFunded: true});
if (invite){
return GUEST_TIER;
} else {
return tier;
}
}
export default TIERS;