Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/src/api/auth/authMe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default async (req, res) => {
...tenantUser.tenant.dataValues,
csvExportCount: Number(await csvExportCountCache.get(tenantUser.tenant.id)) || 0,
automationCount:
Number(await AutomationRepository.countAll(req.database, tenantUser.tenant.id)) || 0,
Number(await AutomationRepository.countAllActive(req.database, tenantUser.tenant.id)) ||
0,
memberEnrichmentCount:
Number(await memberEnrichmentCountCache.get(tenantUser.tenant.id)) || 0,
}
Expand Down
8 changes: 1 addition & 7 deletions backend/src/api/automation/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import passport from 'passport'
import { safeWrap } from '../../middlewares/errorMiddleware'
import { featureFlagMiddleware } from '../../middlewares/featureFlagMiddleware'
import { FeatureFlag } from '../../types/common'
import { API_CONFIG } from '../../conf'
import { authMiddleware } from '../../middlewares/authMiddleware'
import TenantService from '../../services/tenantService'
Expand Down Expand Up @@ -31,11 +29,7 @@ export default (app) => {
},
safeWrap(require('./automationSlackCallback').default),
)
app.post(
'/tenant/:tenantId/automation',
featureFlagMiddleware(FeatureFlag.AUTOMATIONS, 'entities.automation.errors.planLimitExceeded'),
safeWrap(require('./automationCreate').default),
)
app.post('/tenant/:tenantId/automation', safeWrap(require('./automationCreate').default))
app.put(
'/tenant/:tenantId/automation/:automationId',
safeWrap(require('./automationUpdate').default),
Expand Down
3 changes: 2 additions & 1 deletion backend/src/database/repositories/automationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ export default class AutomationRepository extends RepositoryBase<
}
}

static async countAll(database: any, tenantId: string): Promise<number> {
static async countAllActive(database: any, tenantId: string): Promise<number> {
const automationCount = await database.automation.count({
where: {
tenantId,
state: AutomationState.ACTIVE,
},
useMaster: true,
})
Expand Down
2 changes: 1 addition & 1 deletion backend/src/feature-flags/getFeatureFlagTenantContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function getFeatureFlagTenantContext(
redis: RedisClient,
log: Logger,
) {
const automationCount = await AutomationRepository.countAll(database, tenant.id)
const automationCount = await AutomationRepository.countAllActive(database, tenant.id)
const csvExportCountCache = new RedisCache(FeatureFlagRedisKey.CSV_EXPORT_COUNT, redis, log)
const memberEnrichmentCountCache = new RedisCache(
FeatureFlagRedisKey.MEMBER_ENRICHMENT_COUNT,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/automationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class AutomationService extends ServiceBase<
const txOptions = await this.getTxRepositoryOptions()

try {
// create an active automation
// create an automation
const result = await new AutomationRepository(txOptions).create({
...req,
state: AutomationState.ACTIVE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:model-value="props.automation.state === 'active'"
class="!grow-0 !ml-0"
:disabled="!canEnable"
:before-change="beforeChange"
@change="handleChange"
/>
<span class="ml-2 text-gray-900 text-sm">
Expand All @@ -16,6 +17,9 @@
import { computed, defineProps } from 'vue';
import { useAutomationStore } from '@/modules/automation/store';
import { useStore } from 'vuex';
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';
import { mapGetters } from '@/shared/vuex/vuex.helpers';
import { FeatureFlag } from '@/utils/featureFlag';
import { automationTypes } from '../config/automation-types';

const props = defineProps({
Expand All @@ -29,14 +33,38 @@ const store = useStore();

const { changePublishState } = useAutomationStore();

const { currentTenant } = mapGetters('auth');

const canEnable = computed(() => {
const { type } = props.automation;

if (automationTypes[type]?.enableGuard) {
return props.automation.state === 'active' || automationTypes[type]?.enableGuard(props.automation, store);
}

return true;
});

const beforeChange = () => {
if (props.automation.state === 'active') {
return true;
}

const isFeatureEnabled = FeatureFlag.isFlagEnabled(
FeatureFlag.flags.automations,
);

if (!isFeatureEnabled) {
const planWorkflowCountMax = getWorkflowMax(
currentTenant.value.plan,
);

showWorkflowLimitDialog({ planWorkflowCountMax });
}

return isFeatureEnabled;
};

const handleChange = (value) => {
changePublishState(props.automation.id, value);
};
Expand Down
27 changes: 0 additions & 27 deletions frontend/src/modules/automation/pages/automation-list-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ import { storeToRefs } from 'pinia';
import pluralize from 'pluralize';
import AppAutomationForm from '@/modules/automation/components/automation-form.vue';
import AppAutomationListTable from '@/modules/automation/components/list/automation-list-table.vue';
import { mapGetters } from '@/shared/vuex/vuex.helpers';
import AppAutomationExecutions from '@/modules/automation/components/automation-executions.vue';
import { FeatureFlag } from '@/utils/featureFlag';
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';

import { useStore } from 'vuex';
import config from '@/config';
Expand All @@ -158,40 +156,15 @@ const {
} = storeToRefs(automationStore);
const { getAutomations, changeAutomationFilter } = automationStore;

const { currentTenant } = mapGetters('auth');

const store = useStore();
const fetchIntegrations = () => store.dispatch('integration/doFetch');

/**
* Check if tenant has feature flag enabled
*/
const canAddAutomation = () => {
const isFeatureEnabled = FeatureFlag.isFlagEnabled(
FeatureFlag.flags.automations,
);

if (!isFeatureEnabled) {
const planWorkflowCountMax = getWorkflowMax(
currentTenant.value.plan,
);

showWorkflowLimitDialog({ planWorkflowCountMax });
}

return isFeatureEnabled;
};

// Executions drawer
const createAutomation = (type) => {
if (!automationTypes[type].canCreate(store)) {
return;
}

if (!canAddAutomation()) {
return;
}

openAutomationForm.value = true;
editAutomation.value = null;
automationFormType.value = type;
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/modules/automation/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
state: published ? 'active' : 'disabled',
})
.then((res) => {
// Make sure that feature flags are updated for automationsCount
store.dispatch('auth/doRefreshCurrentUser');

this.getAutomations();
return Promise.resolve(res);
});
Expand Down