feat: prevent posts for disabled accounts

This commit is contained in:
Nevo David 2024-03-10 21:18:17 +07:00
parent 5114ea88f7
commit 44a0a77615
5 changed files with 39 additions and 5 deletions

View File

@ -95,7 +95,7 @@ export class UsersController {
@Get('/organizations')
async getOrgs(@GetUserFromRequest() user: User) {
return this._orgService.getOrgsByUserId(user.id);
return (await this._orgService.getOrgsByUserId(user.id)).filter(f => !f.users[0].disabled);
}
@Post('/change-org')

View File

@ -24,7 +24,7 @@ export class AuthMiddleware implements NestMiddleware {
}
delete user.password;
const organization = await this._organizationService.getOrgsByUserId(user.id);
const organization = (await this._organizationService.getOrgsByUserId(user.id)).filter(f => !f.users[0].disabled);
const setOrg = organization.find((org) => org.id === orgHeader) || organization[0];

View File

@ -222,11 +222,29 @@ export const NoBillingComponent: FC<{
const moveToCheckout = useCallback(
(billing: 'STANDARD' | 'PRO' | 'FREE') => async () => {
const messages = [];
const beforeTotalChannels = pricing[billing].channel || initialChannels;
if (totalChannels < beforeTotalChannels) {
messages.push(
`Some of the channels will be disabled`
);
}
if (
!pricing[billing].team_members &&
pricing[subscription?.subscriptionTier!]?.team_members
) {
messages.push(
`Your team members will be removed from your organization`
);
}
if (billing === 'FREE') {
if (
subscription?.cancelAt ||
(await deleteDialog(
'Are you sure you want to cancel your subscription?',
`Are you sure you want to cancel your subscription? ${messages.join(', ')}`,
'Yes, cancel',
'Cancel Subscription'
))
@ -247,6 +265,11 @@ export const NoBillingComponent: FC<{
}
return;
}
if (messages.length && !await deleteDialog(messages.join(', '), 'Yes, continue')) {
return ;
}
setLoading(true);
const { url, portal } = await (
await fetch('/billing/subscribe', {
@ -299,7 +322,7 @@ export const NoBillingComponent: FC<{
setLoading(false);
},
[monthlyOrYearly, totalChannels]
[monthlyOrYearly, totalChannels, subscription, user]
);
return (

View File

@ -27,6 +27,7 @@ export class OrganizationRepository {
userId,
},
select: {
disabled: true,
role: true,
},
},

View File

@ -67,6 +67,16 @@ export class PostsService {
return;
}
if (firstPost.integration?.disabled) {
await this._notificationService.inAppNotification(
firstPost.organizationId,
`We couldn't post to ${firstPost.integration?.providerIdentifier} for ${firstPost?.integration?.name}`,
`We couldn't post to ${firstPost.integration?.providerIdentifier} for ${firstPost?.integration?.name} because it's disabled. Please enable it and try again.`,
true
);
return;
}
try {
if (firstPost.integration?.type === 'article') {
await this.postArticle(firstPost.integration!, [
@ -74,7 +84,7 @@ export class PostsService {
...morePosts,
]);
return ;
return;
}
await this.postSocial(firstPost.integration!, [firstPost, ...morePosts]);