mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 07:26:34 +00:00
feat: updated cloud functions for quantity change made
This commit is contained in:
@@ -4,6 +4,7 @@ import { getConfig } from "@app/lib/config/env";
|
|||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
|
|
||||||
import { TFeatureSet } from "./license-types";
|
import { TFeatureSet } from "./license-types";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
export const getDefaultOnPremFeatures = (): TFeatureSet => ({
|
export const getDefaultOnPremFeatures = (): TFeatureSet => ({
|
||||||
_id: null,
|
_id: null,
|
||||||
@@ -98,9 +99,10 @@ export const setupLicenseRequestWithStore = (baseURL: string, refreshUrl: string
|
|||||||
(response) => response,
|
(response) => response,
|
||||||
async (err) => {
|
async (err) => {
|
||||||
const originalRequest = (err as AxiosError).config;
|
const originalRequest = (err as AxiosError).config;
|
||||||
|
const errStatusCode = Number((err as AxiosError)?.response?.status);
|
||||||
|
logger.error((err as AxiosError)?.response?.data, "License server call error");
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
if ((err as AxiosError)?.response?.status === 401 && !(originalRequest as any)._retry) {
|
if (errStatusCode > 400 && errStatusCode < 500 && !(originalRequest as any)._retry) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
(originalRequest as any)._retry = true; // injected
|
(originalRequest as any)._retry = true; // injected
|
||||||
|
|
||||||
|
|||||||
@@ -348,8 +348,8 @@ export const licenseServiceFactory = ({
|
|||||||
} = await licenseServerCloudApi.request.post(
|
} = await licenseServerCloudApi.request.post(
|
||||||
`/api/license-server/v1/customers/${organization.customerId}/billing-details/payment-methods`,
|
`/api/license-server/v1/customers/${organization.customerId}/billing-details/payment-methods`,
|
||||||
{
|
{
|
||||||
success_url: `${appCfg.SITE_URL}/dashboard`,
|
success_url: `${appCfg.SITE_URL}/organization/billing`,
|
||||||
cancel_url: `${appCfg.SITE_URL}/dashboard`
|
cancel_url: `${appCfg.SITE_URL}/organization/billing`
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ export const licenseServiceFactory = ({
|
|||||||
} = await licenseServerCloudApi.request.post(
|
} = await licenseServerCloudApi.request.post(
|
||||||
`/api/license-server/v1/customers/${organization.customerId}/billing-details/billing-portal`,
|
`/api/license-server/v1/customers/${organization.customerId}/billing-details/billing-portal`,
|
||||||
{
|
{
|
||||||
return_url: `${appCfg.SITE_URL}/dashboard`
|
return_url: `${appCfg.SITE_URL}/organization/billing`
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -407,11 +407,38 @@ export const licenseServiceFactory = ({
|
|||||||
message: `Organization with ID '${orgId}' not found`
|
message: `Organization with ID '${orgId}' not found`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orgMembersUsed = await orgDAL.countAllOrgMembers(orgId);
|
||||||
|
const identityUsed = await identityOrgMembershipDAL.countAllOrgIdentities({ orgId });
|
||||||
|
const projects = await projectDAL.find({ orgId });
|
||||||
|
const projectCount = projects.length;
|
||||||
|
|
||||||
if (instanceType !== InstanceType.OnPrem && instanceType !== InstanceType.EnterpriseOnPremOffline) {
|
if (instanceType !== InstanceType.OnPrem && instanceType !== InstanceType.EnterpriseOnPremOffline) {
|
||||||
const { data } = await licenseServerCloudApi.request.get(
|
const { data } = await licenseServerCloudApi.request.get<{
|
||||||
`/api/license-server/v1/customers/${organization.customerId}/cloud-plan/table`
|
head: { name: string }[];
|
||||||
);
|
rows: { name: string; allowed: boolean }[];
|
||||||
return data;
|
}>(`/api/license-server/v1/customers/${organization.customerId}/cloud-plan/table`);
|
||||||
|
|
||||||
|
const formattedData = {
|
||||||
|
head: data.head,
|
||||||
|
rows: data.rows.map((el) => {
|
||||||
|
let used = "-";
|
||||||
|
|
||||||
|
if (el.name === BillingPlanRows.MemberLimit.name) {
|
||||||
|
used = orgMembersUsed.toString();
|
||||||
|
} else if (el.name === BillingPlanRows.WorkspaceLimit.name) {
|
||||||
|
used = projectCount.toString();
|
||||||
|
} else if (el.name === BillingPlanRows.IdentityLimit.name) {
|
||||||
|
used = (identityUsed + orgMembersUsed).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...el,
|
||||||
|
used
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
return formattedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mappedRows = await Promise.all(
|
const mappedRows = await Promise.all(
|
||||||
@@ -420,14 +447,11 @@ export const licenseServiceFactory = ({
|
|||||||
let used = "-";
|
let used = "-";
|
||||||
|
|
||||||
if (field === BillingPlanRows.MemberLimit.field) {
|
if (field === BillingPlanRows.MemberLimit.field) {
|
||||||
const orgMemberships = await orgDAL.countAllOrgMembers(orgId);
|
used = orgMembersUsed.toString();
|
||||||
used = orgMemberships.toString();
|
|
||||||
} else if (field === BillingPlanRows.WorkspaceLimit.field) {
|
} else if (field === BillingPlanRows.WorkspaceLimit.field) {
|
||||||
const projects = await projectDAL.find({ orgId });
|
used = projectCount.toString();
|
||||||
used = projects.length.toString();
|
|
||||||
} else if (field === BillingPlanRows.IdentityLimit.field) {
|
} else if (field === BillingPlanRows.IdentityLimit.field) {
|
||||||
const identities = await identityOrgMembershipDAL.countAllOrgIdentities({ orgId });
|
used = identityUsed.toString();
|
||||||
used = identities.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
||||||
.count("*")
|
.count("*")
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.where({ isGhost: false })
|
.where({ isGhost: false, [`${TableName.OrgMembership}.isActive` as "isActive"]: true })
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
return parseInt((count as unknown as CountResult).count || "0", 10);
|
return parseInt((count as unknown as CountResult).count || "0", 10);
|
||||||
|
|||||||
+24
-2
@@ -1,4 +1,9 @@
|
|||||||
import { faCircleCheck, faCircleXmark, faFileInvoice } from "@fortawesome/free-solid-svg-icons";
|
import {
|
||||||
|
faCircleCheck,
|
||||||
|
faCircleXmark,
|
||||||
|
faFileInvoice,
|
||||||
|
faInfoCircle
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -10,6 +15,7 @@ import {
|
|||||||
Td,
|
Td,
|
||||||
Th,
|
Th,
|
||||||
THead,
|
THead,
|
||||||
|
Tooltip,
|
||||||
Tr
|
Tr
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useOrganization } from "@app/context";
|
import { useOrganization } from "@app/context";
|
||||||
@@ -48,9 +54,25 @@ export const CurrentPlanSection = () => {
|
|||||||
data &&
|
data &&
|
||||||
data?.rows?.length > 0 &&
|
data?.rows?.length > 0 &&
|
||||||
data.rows.map(({ name, allowed, used }) => {
|
data.rows.map(({ name, allowed, used }) => {
|
||||||
|
let toolTipText = null;
|
||||||
|
if (name === "Organization identity limit") {
|
||||||
|
toolTipText = "Identity refers to as user and machine identities.";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tr key={`current-plan-row-${name}`} className="h-12">
|
<Tr key={`current-plan-row-${name}`} className="h-12">
|
||||||
<Td>{name}</Td>
|
<Td>
|
||||||
|
{name}
|
||||||
|
{toolTipText && (
|
||||||
|
<Tooltip content={toolTipText}>
|
||||||
|
<FontAwesomeIcon
|
||||||
|
icon={faInfoCircle}
|
||||||
|
className="relative bottom-2 left-2"
|
||||||
|
size="xs"
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
</Td>
|
||||||
<Td>{displayCell(allowed)}</Td>
|
<Td>{displayCell(allowed)}</Td>
|
||||||
<Td>{used}</Td>
|
<Td>{used}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user