mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-14 21:31:30 +08:00
fix(server): standalone early access users detection (#5601)
This commit is contained in:
@@ -47,22 +47,26 @@ export class FeatureManagementService {
|
|||||||
return this.feature.listFeatureUsers(FeatureType.EarlyAccess);
|
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
|
/// check early access by email
|
||||||
async canEarlyAccess(email: string) {
|
async canEarlyAccess(email: string) {
|
||||||
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
|
if (this.config.featureFlags.earlyAccessPreview && !this.isStaff(email)) {
|
||||||
const user = await this.prisma.user.findFirst({
|
return this.isEarlyAccessUser(email);
|
||||||
where: {
|
|
||||||
email,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (user) {
|
|
||||||
const canEarlyAccess = await this.feature
|
|
||||||
.hasUserFeature(user.id, FeatureType.EarlyAccess)
|
|
||||||
.catch(() => false);
|
|
||||||
|
|
||||||
return canEarlyAccess;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user