mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: rework documents limits logic (#1836)
This commit is contained in:
@ -66,7 +66,7 @@ export const getServerLimits = async ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If plan expired.
|
// Early return for users with an expired subscription.
|
||||||
if (subscription && subscription.status !== SubscriptionStatus.ACTIVE) {
|
if (subscription && subscription.status !== SubscriptionStatus.ACTIVE) {
|
||||||
return {
|
return {
|
||||||
quota: INACTIVE_PLAN_LIMITS,
|
quota: INACTIVE_PLAN_LIMITS,
|
||||||
@ -74,52 +74,46 @@ export const getServerLimits = async ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscription && organisation.organisationClaim.flags.unlimitedDocuments) {
|
// Allow unlimited documents for users with an unlimited documents claim.
|
||||||
|
// This also allows "free" claim users without subscriptions if they have this flag.
|
||||||
|
if (organisation.organisationClaim.flags.unlimitedDocuments) {
|
||||||
return {
|
return {
|
||||||
quota: PAID_PLAN_LIMITS,
|
quota: PAID_PLAN_LIMITS,
|
||||||
remaining: PAID_PLAN_LIMITS,
|
remaining: PAID_PLAN_LIMITS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If free tier or plan does not have unlimited documents.
|
const [documents, directTemplates] = await Promise.all([
|
||||||
if (!subscription || !organisation.organisationClaim.flags.unlimitedDocuments) {
|
prisma.document.count({
|
||||||
const [documents, directTemplates] = await Promise.all([
|
where: {
|
||||||
prisma.document.count({
|
team: {
|
||||||
where: {
|
organisationId: organisation.id,
|
||||||
team: {
|
|
||||||
organisationId: organisation.id,
|
|
||||||
},
|
|
||||||
createdAt: {
|
|
||||||
gte: DateTime.utc().startOf('month').toJSDate(),
|
|
||||||
},
|
|
||||||
source: {
|
|
||||||
not: DocumentSource.TEMPLATE_DIRECT_LINK,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
createdAt: {
|
||||||
prisma.template.count({
|
gte: DateTime.utc().startOf('month').toJSDate(),
|
||||||
where: {
|
|
||||||
team: {
|
|
||||||
organisationId: organisation.id,
|
|
||||||
},
|
|
||||||
directLink: {
|
|
||||||
isNot: null,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
source: {
|
||||||
]);
|
not: DocumentSource.TEMPLATE_DIRECT_LINK,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
prisma.template.count({
|
||||||
|
where: {
|
||||||
|
team: {
|
||||||
|
organisationId: organisation.id,
|
||||||
|
},
|
||||||
|
directLink: {
|
||||||
|
isNot: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
remaining.documents = Math.max(remaining.documents - documents, 0);
|
remaining.documents = Math.max(remaining.documents - documents, 0);
|
||||||
remaining.directTemplates = Math.max(remaining.directTemplates - directTemplates, 0);
|
remaining.directTemplates = Math.max(remaining.directTemplates - directTemplates, 0);
|
||||||
|
|
||||||
return {
|
|
||||||
quota,
|
|
||||||
remaining,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
quota: PAID_PLAN_LIMITS,
|
quota,
|
||||||
remaining: PAID_PLAN_LIMITS,
|
remaining,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user