Skip to content

Commit bb7ea1f

Browse files
authored
Update automations limitation (#1728)
1 parent 3118e41 commit bb7ea1f

File tree

8 files changed

+38
-38
lines changed

8 files changed

+38
-38
lines changed

backend/src/api/auth/authMe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export default async (req, res) => {
2929
...tenantUser.tenant.dataValues,
3030
csvExportCount: Number(await csvExportCountCache.get(tenantUser.tenant.id)) || 0,
3131
automationCount:
32-
Number(await AutomationRepository.countAll(req.database, tenantUser.tenant.id)) || 0,
32+
Number(await AutomationRepository.countAllActive(req.database, tenantUser.tenant.id)) ||
33+
0,
3334
memberEnrichmentCount:
3435
Number(await memberEnrichmentCountCache.get(tenantUser.tenant.id)) || 0,
3536
}

backend/src/api/automation/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import passport from 'passport'
22
import { safeWrap } from '../../middlewares/errorMiddleware'
3-
import { featureFlagMiddleware } from '../../middlewares/featureFlagMiddleware'
4-
import { FeatureFlag } from '../../types/common'
53
import { API_CONFIG } from '../../conf'
64
import { authMiddleware } from '../../middlewares/authMiddleware'
75
import TenantService from '../../services/tenantService'
@@ -31,11 +29,7 @@ export default (app) => {
3129
},
3230
safeWrap(require('./automationSlackCallback').default),
3331
)
34-
app.post(
35-
'/tenant/:tenantId/automation',
36-
featureFlagMiddleware(FeatureFlag.AUTOMATIONS, 'entities.automation.errors.planLimitExceeded'),
37-
safeWrap(require('./automationCreate').default),
38-
)
32+
app.post('/tenant/:tenantId/automation', safeWrap(require('./automationCreate').default))
3933
app.put(
4034
'/tenant/:tenantId/automation/:automationId',
4135
safeWrap(require('./automationUpdate').default),

backend/src/database/repositories/automationRepository.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ export default class AutomationRepository extends RepositoryBase<
256256
}
257257
}
258258

259-
static async countAll(database: any, tenantId: string): Promise<number> {
259+
static async countAllActive(database: any, tenantId: string): Promise<number> {
260260
const automationCount = await database.automation.count({
261261
where: {
262262
tenantId,
263+
state: AutomationState.ACTIVE,
263264
},
264265
useMaster: true,
265266
})

backend/src/feature-flags/getFeatureFlagTenantContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function getFeatureFlagTenantContext(
1010
redis: RedisClient,
1111
log: Logger,
1212
) {
13-
const automationCount = await AutomationRepository.countAll(database, tenant.id)
13+
const automationCount = await AutomationRepository.countAllActive(database, tenant.id)
1414
const csvExportCountCache = new RedisCache(FeatureFlagRedisKey.CSV_EXPORT_COUNT, redis, log)
1515
const memberEnrichmentCountCache = new RedisCache(
1616
FeatureFlagRedisKey.MEMBER_ENRICHMENT_COUNT,

backend/src/services/automationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class AutomationService extends ServiceBase<
3939
const txOptions = await this.getTxRepositoryOptions()
4040

4141
try {
42-
// create an active automation
42+
// create an automation
4343
const result = await new AutomationRepository(txOptions).create({
4444
...req,
4545
state: AutomationState.ACTIVE,

frontend/src/modules/automation/components/automation-toggle.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:model-value="props.automation.state === 'active'"
55
class="!grow-0 !ml-0"
66
:disabled="!canEnable"
7+
:before-change="beforeChange"
78
@change="handleChange"
89
/>
910
<span class="ml-2 text-gray-900 text-sm">
@@ -16,6 +17,9 @@
1617
import { computed, defineProps } from 'vue';
1718
import { useAutomationStore } from '@/modules/automation/store';
1819
import { useStore } from 'vuex';
20+
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';
21+
import { mapGetters } from '@/shared/vuex/vuex.helpers';
22+
import { FeatureFlag } from '@/utils/featureFlag';
1923
import { automationTypes } from '../config/automation-types';
2024
2125
const props = defineProps({
@@ -29,14 +33,38 @@ const store = useStore();
2933
3034
const { changePublishState } = useAutomationStore();
3135
36+
const { currentTenant } = mapGetters('auth');
37+
3238
const canEnable = computed(() => {
3339
const { type } = props.automation;
40+
3441
if (automationTypes[type]?.enableGuard) {
3542
return props.automation.state === 'active' || automationTypes[type]?.enableGuard(props.automation, store);
3643
}
44+
3745
return true;
3846
});
3947
48+
const beforeChange = () => {
49+
if (props.automation.state === 'active') {
50+
return true;
51+
}
52+
53+
const isFeatureEnabled = FeatureFlag.isFlagEnabled(
54+
FeatureFlag.flags.automations,
55+
);
56+
57+
if (!isFeatureEnabled) {
58+
const planWorkflowCountMax = getWorkflowMax(
59+
currentTenant.value.plan,
60+
);
61+
62+
showWorkflowLimitDialog({ planWorkflowCountMax });
63+
}
64+
65+
return isFeatureEnabled;
66+
};
67+
4068
const handleChange = (value) => {
4169
changePublishState(props.automation.id, value);
4270
};

frontend/src/modules/automation/pages/automation-list-page.vue

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ import { storeToRefs } from 'pinia';
128128
import pluralize from 'pluralize';
129129
import AppAutomationForm from '@/modules/automation/components/automation-form.vue';
130130
import AppAutomationListTable from '@/modules/automation/components/list/automation-list-table.vue';
131-
import { mapGetters } from '@/shared/vuex/vuex.helpers';
132131
import AppAutomationExecutions from '@/modules/automation/components/automation-executions.vue';
133132
import { FeatureFlag } from '@/utils/featureFlag';
134-
import { getWorkflowMax, showWorkflowLimitDialog } from '@/modules/automation/automation-limit';
135133
136134
import { useStore } from 'vuex';
137135
import config from '@/config';
@@ -158,40 +156,15 @@ const {
158156
} = storeToRefs(automationStore);
159157
const { getAutomations, changeAutomationFilter } = automationStore;
160158
161-
const { currentTenant } = mapGetters('auth');
162-
163159
const store = useStore();
164160
const fetchIntegrations = () => store.dispatch('integration/doFetch');
165161
166-
/**
167-
* Check if tenant has feature flag enabled
168-
*/
169-
const canAddAutomation = () => {
170-
const isFeatureEnabled = FeatureFlag.isFlagEnabled(
171-
FeatureFlag.flags.automations,
172-
);
173-
174-
if (!isFeatureEnabled) {
175-
const planWorkflowCountMax = getWorkflowMax(
176-
currentTenant.value.plan,
177-
);
178-
179-
showWorkflowLimitDialog({ planWorkflowCountMax });
180-
}
181-
182-
return isFeatureEnabled;
183-
};
184-
185162
// Executions drawer
186163
const createAutomation = (type) => {
187164
if (!automationTypes[type].canCreate(store)) {
188165
return;
189166
}
190167
191-
if (!canAddAutomation()) {
192-
return;
193-
}
194-
195168
openAutomationForm.value = true;
196169
editAutomation.value = null;
197170
automationFormType.value = type;

frontend/src/modules/automation/store/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export default {
2626
state: published ? 'active' : 'disabled',
2727
})
2828
.then((res) => {
29+
// Make sure that feature flags are updated for automationsCount
30+
store.dispatch('auth/doRefreshCurrentUser');
31+
2932
this.getAutomations();
3033
return Promise.resolve(res);
3134
});

0 commit comments

Comments
 (0)