refactor: User permission and limits to run flows
This commit is contained in:
@@ -165,18 +165,24 @@ class User extends Base {
|
||||
this.trialExpiryDate = DateTime.now().plus({ days: 30 }).toISODate();
|
||||
}
|
||||
|
||||
async hasActiveSubscription() {
|
||||
if (!appConfig.isCloud) {
|
||||
return false;
|
||||
async isAllowedToRunFlows() {
|
||||
if (appConfig.isSelfHosted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const subscription = await this.$relatedQuery('currentSubscription');
|
||||
if (await this.inTrial()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return subscription?.isActive;
|
||||
if ((await this.hasActiveSubscription()) && (await this.withinLimits())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async inTrial() {
|
||||
if (!appConfig.isCloud) {
|
||||
if (appConfig.isSelfHosted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -196,6 +202,24 @@ class User extends Base {
|
||||
return now < expiryDate;
|
||||
}
|
||||
|
||||
async hasActiveSubscription() {
|
||||
if (!appConfig.isCloud) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const subscription = await this.$relatedQuery('currentSubscription');
|
||||
|
||||
return subscription?.isActive;
|
||||
}
|
||||
|
||||
async withinLimits() {
|
||||
const currentSubscription = await this.$relatedQuery('currentSubscription');
|
||||
const plan = currentSubscription.plan;
|
||||
const currentUsageData = await this.$relatedQuery('currentUsageData');
|
||||
|
||||
return currentUsageData.consumedTaskCount >= plan.quota;
|
||||
}
|
||||
|
||||
async $beforeInsert(queryContext: QueryContext) {
|
||||
await super.$beforeInsert(queryContext);
|
||||
await this.generateHash();
|
||||
|
Reference in New Issue
Block a user