Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: refresh channel fix

Nevo Davidf55253d1abc0
diff --git a/apps/backend/src/services/auth/permissions/permissions.guard.ts b/apps/backend/src/services/auth/permissions/permissions.guard.ts
index 986662580..e3a4d98ca 100644
--- a/apps/backend/src/services/auth/permissions/permissions.guard.ts
+++ b/apps/backend/src/services/auth/permissions/permissions.guard.ts
@@ -44,8 +44,10 @@ export class PoliciesGuard implements CanActivate {
// @ts-expect-error
const { org }: { org: Organization } = request;
+ const refreshChannelId = typeof request.query?.refresh === 'string' ? request.query.refresh : undefined;
+
// @ts-ignore
- const ability = await this._authorizationService.check(org.id, org.createdAt, org.users[0].role, policyHandlers);
+ const ability = await this._authorizationService.check(org.id, org.createdAt, org.users[0].role, policyHandlers, refreshChannelId);
const item = policyHandlers.find(
(handler) => !this.execPolicyHandler(handler, ability)
diff --git a/apps/backend/src/services/auth/permissions/permissions.service.ts b/apps/backend/src/services/auth/permissions/permissions.service.ts
index 78af31237..75223fbbf 100644
--- a/apps/backend/src/services/auth/permissions/permissions.service.ts
+++ b/apps/backend/src/services/auth/permissions/permissions.service.ts
@@ -40,7 +40,8 @@ export class PermissionsService {
orgId: string,
created_at: Date,
permission: 'USER' | 'ADMIN' | 'SUPERADMIN',
- requestedPermission: Array<[AuthorizationActions, Sections]>
+ requestedPermission: Array<[AuthorizationActions, Sections]>,
+ refreshChannelId?: string
) {
const { can, build } = new AbilityBuilder<
Ability<[AuthorizationActions, Sections]>
@@ -65,6 +66,20 @@ export class PermissionsService {
for (const [action, section] of requestedPermission) {
// check for the amount of channels
if (section === Sections.CHANNEL) {
+ // Refreshing an existing channel doesn't add a new one, so skip the limit check
+ // but only if the channel actually belongs to this org
+ if (refreshChannelId) {
+ const existingIntegration =
+ await this._integrationService.getIntegrationById(
+ orgId,
+ refreshChannelId
+ );
+ if (existingIntegration) {
+ can(action, section);
+ continue;
+ }
+ }
+
const totalChannels = (
await this._integrationService.getIntegrationsList(orgId)
).filter((f) => !f.refreshNeeded).length;