refactor: User permission and limits to run flows
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { ValidationError } from 'objection';
|
||||
import type { ModelOptions, QueryContext, StaticHookArguments } from 'objection';
|
||||
import appConfig from '../config/app';
|
||||
import type {
|
||||
ModelOptions,
|
||||
QueryContext,
|
||||
StaticHookArguments,
|
||||
} from 'objection';
|
||||
import ExtendedQueryBuilder from './query-builder';
|
||||
import Base from './base';
|
||||
import Step from './step';
|
||||
import User from './user';
|
||||
import Execution from './execution';
|
||||
import Telemetry from '../helpers/telemetry';
|
||||
import QuotaExceededError from '../errors/quote-exceeded';
|
||||
|
||||
class Flow extends Base {
|
||||
id!: string;
|
||||
@@ -155,36 +157,7 @@ class Flow extends Base {
|
||||
|
||||
async isPaused() {
|
||||
const user = await this.$relatedQuery('user');
|
||||
const currentUsageData = await user.$relatedQuery('currentUsageData');
|
||||
|
||||
return await currentUsageData.checkIfLimitExceeded();
|
||||
}
|
||||
|
||||
async checkIfQuotaExceeded() {
|
||||
if (!appConfig.isCloud) return;
|
||||
|
||||
const user = await this.$relatedQuery('user');
|
||||
const usageData = await user.$relatedQuery('currentUsageData');
|
||||
|
||||
const hasExceeded = await usageData.checkIfLimitExceeded();
|
||||
|
||||
if (hasExceeded) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async throwIfQuotaExceeded() {
|
||||
if (!appConfig.isCloud) return;
|
||||
|
||||
const hasExceeded = await this.checkIfQuotaExceeded();
|
||||
|
||||
if (hasExceeded) {
|
||||
throw new QuotaExceededError();
|
||||
}
|
||||
|
||||
return this;
|
||||
return await user.isAllowedToRunFlows();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user