fix(server): standalone early access users detection (#5601)

This commit is contained in:
liuyi
2024-01-16 03:27:44 +00:00
parent 2fb0e3ef15
commit 75fb0a9f1a
2 changed files with 18 additions and 14 deletions
@@ -47,22 +47,26 @@ export class FeatureManagementService {
return this.feature.listFeatureUsers(FeatureType.EarlyAccess);
}
async isEarlyAccessUser(email: string) {
const user = await this.prisma.user.findFirst({
where: {
email,
},
});
if (user) {
const canEarlyAccess = await this.feature
.hasUserFeature(user.id, FeatureType.EarlyAccess)
.catch(() => false);
return canEarlyAccess;
}
return false;
}
/// check early access by email
async canEarlyAccess(email: string) {
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
const user = await this.prisma.user.findFirst({
where: {
email,
},
});
if (user) {
const canEarlyAccess = await this.feature
.hasUserFeature(user.id, FeatureType.EarlyAccess)
.catch(() => false);
return canEarlyAccess;
}
return false;
return this.isEarlyAccessUser(email);
} else {
return true;
}
@@ -679,7 +679,7 @@ export class SubscriptionService {
user: User,
couponType: CouponType
): Promise<string | null> {
const earlyAccess = await this.features.canEarlyAccess(user.email);
const earlyAccess = await this.features.isEarlyAccessUser(user.email);
if (earlyAccess) {
try {
const coupon = await this.stripe.coupons.retrieve(couponType);