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

View File

@@ -47,9 +47,7 @@ export class FeatureManagementService {
return this.feature.listFeatureUsers(FeatureType.EarlyAccess); return this.feature.listFeatureUsers(FeatureType.EarlyAccess);
} }
/// check early access by email async isEarlyAccessUser(email: string) {
async canEarlyAccess(email: string) {
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
const user = await this.prisma.user.findFirst({ const user = await this.prisma.user.findFirst({
where: { where: {
email, email,
@@ -63,6 +61,12 @@ export class FeatureManagementService {
return canEarlyAccess; return canEarlyAccess;
} }
return false; return false;
}
/// check early access by email
async canEarlyAccess(email: string) {
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
return this.isEarlyAccessUser(email);
} else { } else {
return true; return true;
} }

View File

@@ -679,7 +679,7 @@ export class SubscriptionService {
user: User, user: User,
couponType: CouponType couponType: CouponType
): Promise<string | null> { ): Promise<string | null> {
const earlyAccess = await this.features.canEarlyAccess(user.email); const earlyAccess = await this.features.isEarlyAccessUser(user.email);
if (earlyAccess) { if (earlyAccess) {
try { try {
const coupon = await this.stripe.coupons.retrieve(couponType); const coupon = await this.stripe.coupons.retrieve(couponType);