Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: added change in user invitation mail for suborg and updated list operation for sub org

=0ecca6a312b1
diff --git a/backend/src/ee/services/sub-org/sub-org-service.ts b/backend/src/ee/services/sub-org/sub-org-service.ts
index db5b892441..fca60bb9b4 100644
--- a/backend/src/ee/services/sub-org/sub-org-service.ts
+++ b/backend/src/ee/services/sub-org/sub-org-service.ts
@@ -93,10 +93,10 @@ export const subOrgServiceFactory = ({
await permissionService.getOrgPermission({
actorId: permissionActor.id,
actor: permissionActor.type,
- orgId: permissionActor.parentOrgId,
+ orgId: permissionActor.rootOrgId,
actorOrgId: permissionActor.rootOrgId,
actorAuthMethod: permissionActor.authMethod,
- scope: OrganizationActionScope.ParentOrganization
+ scope: OrganizationActionScope.Any
});
const organizations = await orgDAL.listSubOrganizations({
diff --git a/backend/src/services/membership-user/org/org-membership-user-factory.ts b/backend/src/services/membership-user/org/org-membership-user-factory.ts
index 7aff052205..2da2634267 100644
--- a/backend/src/services/membership-user/org/org-membership-user-factory.ts
+++ b/backend/src/services/membership-user/org/org-membership-user-factory.ts
@@ -84,6 +84,7 @@ export const newOrgMembershipUserFactory = ({
message: "Failed to invite user due to org-level auth enforced for organization"
});
}
+
if (org.rootOrgId) {
const rootOrgMembership = await membershipUserDAL.find({
scope: AccessScope.Organization,
@@ -120,40 +121,52 @@ export const newOrgMembershipUserFactory = ({
const signUpTokens: { email: string; link: string }[] = [];
const orgDetails = await orgDAL.findById(dto.permission.orgId);
+ if (orgDetails.rootOrgId) {
+ const emails = newUsers.map((el) => el.email).filter(Boolean);
+ await smtpService.sendMail({
+ template: SmtpTemplates.SubOrgInvite,
+ subjectLine: "Infisical sub-organization invitation",
+ recipients: emails as string[],
+ substitutions: {
+ subOrganizationName: orgDetails.slug,
+ callback_url: `${appCfg.SITE_URL}/organization/projects?${orgDetails.slug}`
+ }
+ });
+ } else {
+ await Promise.allSettled(
+ newUsers.map(async (el) => {
+ const token = await tokenService.createTokenForUser({
+ type: TokenType.TOKEN_EMAIL_ORG_INVITATION,
+ userId: el.id,
+ orgId: dto.permission.orgId
+ });
- await Promise.allSettled(
- newUsers.map(async (el) => {
- const token = await tokenService.createTokenForUser({
- type: TokenType.TOKEN_EMAIL_ORG_INVITATION,
- userId: el.id,
- orgId: dto.permission.orgId
- });
+ if (el.email) {
+ if (!appCfg.isSmtpConfigured) {
+ signUpTokens.push({
+ email: el.email,
+ link: `${appCfg.SITE_URL}/signupinvite?token=${token}&to=${el.email}&organization_id=${dto.permission.orgId}`
+ });
+ }
- if (el.email) {
- if (!appCfg.isSmtpConfigured) {
- signUpTokens.push({
- email: el.email,
- link: `${appCfg.SITE_URL}/signupinvite?token=${token}&to=${el.email}&organization_id=${dto.permission.orgId}`
+ await smtpService.sendMail({
+ template: SmtpTemplates.OrgInvite,
+ subjectLine: "Infisical organization invitation",
+ recipients: [el.email],
+ substitutions: {
+ inviterFirstName: actorDetails?.firstName,
+ inviterUsername: actorDetails?.email,
+ organizationName: orgDetails?.name,
+ email: el.email,
+ organizationId: orgDetails?.id.toString(),
+ token,
+ callback_url: `${appCfg.SITE_URL}/signupinvite`
+ }
});
}
-
- await smtpService.sendMail({
- template: SmtpTemplates.OrgInvite,
- subjectLine: "Infisical organization invitation",
- recipients: [el.email],
- substitutions: {
- inviterFirstName: actorDetails?.firstName,
- inviterUsername: actorDetails?.email,
- organizationName: orgDetails?.name,
- email: el.email,
- organizationId: orgDetails?.id.toString(),
- token,
- callback_url: `${appCfg.SITE_URL}/signupinvite`
- }
- });
- }
- })
- );
+ })
+ );
+ }
return { signUpTokens };
};
diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts
index 76c1fb8014..6334322eb9 100644
--- a/backend/src/services/org/org-service.ts
+++ b/backend/src/services/org/org-service.ts
@@ -346,7 +346,7 @@ export const orgServiceFactory = ({
orgId,
actorAuthMethod,
actorOrgId,
- scope: OrganizationActionScope.Any
+ scope: OrganizationActionScope.ParentOrganization
});
if (!hasRole(OrgMembershipRole.Admin)) {
@@ -418,7 +418,7 @@ export const orgServiceFactory = ({
orgId,
actorAuthMethod,
actorOrgId,
- scope: OrganizationActionScope.Any
+ scope: OrganizationActionScope.ParentOrganization
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Edit, OrgPermissionSubjects.Settings);
@@ -878,7 +878,7 @@ export const orgServiceFactory = ({
orgId,
actorAuthMethod,
actorOrgId,
- scope: OrganizationActionScope.Any
+ scope: OrganizationActionScope.ParentOrganization
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Member);
@@ -1172,7 +1172,7 @@ export const orgServiceFactory = ({
orgId,
actorAuthMethod,
actorOrgId,
- scope: OrganizationActionScope.Any
+ scope: OrganizationActionScope.ParentOrganization
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.IncidentAccount);
const doesIncidentContactExist = await incidentContactDAL.findOne(orgId, { email });
@@ -1200,7 +1200,7 @@ export const orgServiceFactory = ({
orgId,
actorAuthMethod,
actorOrgId,
- scope: OrganizationActionScope.Any
+ scope: OrganizationActionScope.ParentOrganization
});
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Delete, OrgPermissionSubjects.IncidentAccount);
diff --git a/backend/src/services/smtp/emails/SubOrganizationInvitationTemplate.tsx b/backend/src/services/smtp/emails/SubOrganizationInvitationTemplate.tsx
new file mode 100644
index 0000000000..e0b347dae0
--- /dev/null
+++ b/backend/src/services/smtp/emails/SubOrganizationInvitationTemplate.tsx
@@ -0,0 +1,50 @@
+import { Heading, Section, Text } from "@react-email/components";
+import React from "react";
+
+import { BaseButton } from "./BaseButton";
+import { BaseEmailWrapper, BaseEmailWrapperProps } from "./BaseEmailWrapper";
+
+interface SubOrganizationInvitationTemplateProps extends Omit<BaseEmailWrapperProps, "preview" | "title"> {
+ callback_url: string;
+ subOrganizationName: string;
+}
+
+export const SubOrganizationInvitationTemplate = ({
+ callback_url,
+ subOrganizationName,
+ siteUrl
+}: SubOrganizationInvitationTemplateProps) => {
+ return (
+ <BaseEmailWrapper
+ title="Sub-Organization Invitation"
+ preview="You've been invited to join a suborganization on Infisical."
+ siteUrl={siteUrl}
+ >
+ <Heading className="text-black text-[18px] leading-[28px] text-center font-normal p-0 mx-0">
+ You've been invited to join a suborganization on Infisical
+ </Heading>
+ <Section className="px-[24px] mb-[28px] mt-[36px] pt-[12px] pb-[8px] border text-center border-solid border-gray-200 rounded-md bg-gray-50">
+ <Text className="text-black text-[14px] leading-[24px]">
+ You've been invited to join the suborganization <strong>{subOrganizationName}</strong>.
+ </Text>
+ </Section>
+ <Section className="text-center">
+ <BaseButton href={callback_url}>Join Suborganization</BaseButton>
+ </Section>
+ <Section className="mt-[24px] bg-gray-50 pt-[2px] pb-[16px] border border-solid border-gray-200 px-[24px] rounded-md text-gray-800">
+ <Text className="mb-[0px]">
+ <strong>About Infisical:</strong> Infisical is an all-in-one platform to securely manage application secrets,
+ certificates, SSH keys, and configurations across your team and infrastructure.
+ </Text>
+ </Section>
+ </BaseEmailWrapper>
+ );
+};
+
+export default SubOrganizationInvitationTemplate;
+
+SubOrganizationInvitationTemplate.PreviewProps = {
+ subOrganizationName: "Example Project",
+ siteUrl: "https://infisical.com",
+ callback_url: "https://app.infisical.com"
+} as SubOrganizationInvitationTemplateProps;
diff --git a/backend/src/services/smtp/emails/index.ts b/backend/src/services/smtp/emails/index.ts
index 06ac31ab69..78e4158321 100644
--- a/backend/src/services/smtp/emails/index.ts
+++ b/backend/src/services/smtp/emails/index.ts
@@ -32,3 +32,4 @@ export * from "./SecretSyncFailedTemplate";
export * from "./ServiceTokenExpiryNoticeTemplate";
export * from "./SignupEmailVerificationTemplate";
export * from "./UnlockAccountTemplate";
+export * from "./SubOrganizationInvitationTemplate";
diff --git a/backend/src/services/smtp/smtp-service.ts b/backend/src/services/smtp/smtp-service.ts
index 652f565679..e5f83f66c4 100644
--- a/backend/src/services/smtp/smtp-service.ts
+++ b/backend/src/services/smtp/smtp-service.ts
@@ -40,7 +40,8 @@ import {
SecretSyncFailedTemplate,
ServiceTokenExpiryNoticeTemplate,
SignupEmailVerificationTemplate,
- UnlockAccountTemplate
+ UnlockAccountTemplate,
+ SubOrganizationInvitationTemplate
} from "./emails";
export type TSmtpConfig = SMTPTransport.Options;
@@ -65,6 +66,7 @@ export enum SmtpTemplates {
// HistoricalSecretList = "historicalSecretLeakIncident", not used anymore?
NewDeviceJoin = "newDevice",
OrgInvite = "organizationInvitation",
+ SubOrgInvite = "subOrganizationInvitation",
OrgAssignment = "organizationAssignment",
OAuthPasswordReset = "oAuthPasswordReset",
ResetPassword = "passwordReset",
@@ -102,6 +104,7 @@ export enum SmtpHost {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const EmailTemplateMap: Record<SmtpTemplates, React.FC<any>> = {
[SmtpTemplates.OrgInvite]: OrganizationInvitationTemplate,
+ [SmtpTemplates.SubOrgInvite]: SubOrganizationInvitationTemplate,
[SmtpTemplates.OrgAssignment]: OrganizationAssignmentTemplate,
[SmtpTemplates.NewDeviceJoin]: NewDeviceLoginTemplate,
[SmtpTemplates.SignupEmailVerification]: SignupEmailVerificationTemplate,
diff --git a/frontend/src/context/OrganizationContext/OrganizationContext.tsx b/frontend/src/context/OrganizationContext/OrganizationContext.tsx
index 79c004e1fa..b657a827d6 100644
--- a/frontend/src/context/OrganizationContext/OrganizationContext.tsx
+++ b/frontend/src/context/OrganizationContext/OrganizationContext.tsx
@@ -2,6 +2,7 @@ import { useSuspenseQuery } from "@tanstack/react-query";
import { useRouteContext, useSearch } from "@tanstack/react-router";
import { fetchOrganizationById, organizationKeys } from "@app/hooks/api/organization/queries";
+import { useMemo } from "react";
export const useOrganization = () => {
const organizationId = useRouteContext({
@@ -20,13 +21,18 @@ export const useOrganization = () => {
staleTime: Infinity
});
- return {
- currentOrg: {
- ...currentOrg,
- id: currentOrg?.subOrganization?.id || currentOrg?.id,
- parentOrgId: currentOrg.id
- },
- isSubOrganization: Boolean(currentOrg.subOrganization),
- isRootOrganization: !currentOrg.subOrganization
- };
+ const org = useMemo(
+ () => ({
+ currentOrg: {
+ ...currentOrg,
+ id: currentOrg?.subOrganization?.id || currentOrg?.id,
+ parentOrgId: currentOrg.id
+ },
+ isSubOrganization: Boolean(currentOrg.subOrganization),
+ isRootOrganization: !currentOrg.subOrganization
+ }),
+ [currentOrg]
+ );
+
+ return org;
};
diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
index 09bf597943..0bc4439ae8 100644
--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx
@@ -131,14 +131,14 @@ export const INFISICAL_SUPPORT_OPTIONS = [
export const Navbar = () => {
const { user } = useUser();
const { subscription } = useSubscription();
- const { currentOrg, isSubOrganization } = useOrganization();
+ const { currentOrg } = useOrganization();
const [showAdminsModal, setShowAdminsModal] = useState(false);
const [showSubOrgForm, setShowSubOrgForm] = useState(false);
const [showCardDeclinedModal, setShowCardDeclinedModal] = useState(false);
const { data: subOrganizations = [] } = useQuery({
...subOrganizationsQuery.list({ limit: 500 }),
- enabled: Boolean(subscription.subOrganization) && !isSubOrganization
+ enabled: Boolean(subscription.subOrganization)
});
useEffect(() => {
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx
index 9b6323c2e4..766a221588 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgNameChangeSection/OrgNameChangeSection.tsx
@@ -41,21 +41,19 @@ export const OrgNameChangeSection = (): JSX.Element => {
const [isFormInitialized, setIsFormInitialized] = useState(false);
useEffect(() => {
- if (currentOrg) {
- reset({
- name: currentOrg.name,
- slug: currentOrg.slug,
- ...(canReadOrgRoles &&
- roles?.length && {
- // will always be present, can't remove role if default
- defaultMembershipRole: isCustomOrgRole(currentOrg.defaultMembershipRole)
- ? roles?.find((role) => currentOrg.defaultMembershipRole === role.id)?.slug || ""
- : currentOrg.defaultMembershipRole
- })
- });
- setIsFormInitialized(true);
- }
- }, [currentOrg, roles]);
+ reset({
+ name: currentOrg.name,
+ slug: currentOrg.slug,
+ ...(canReadOrgRoles &&
+ roles?.length && {
+ // will always be present, can't remove role if default
+ defaultMembershipRole: isCustomOrgRole(currentOrg.defaultMembershipRole)
+ ? roles?.find((role) => currentOrg.defaultMembershipRole === role.id)?.slug || ""
+ : currentOrg.defaultMembershipRole
+ })
+ });
+ setIsFormInitialized(true);
+ }, [roles]);
const onFormSubmit = async ({ name, slug, defaultMembershipRole }: FormData) => {
try {
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgProductSelectSection/OrgProductSelectSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgProductSelectSection/OrgProductSelectSection.tsx
index 61ee0c6e96..5be15edadb 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgProductSelectSection/OrgProductSelectSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgProductSelectSection/OrgProductSelectSection.tsx
@@ -50,7 +50,7 @@ export const OrgProductSelectSection = () => {
}));
}
});
- }, [currentOrg]);
+ }, [currentOrg?.id]);
const onProductToggle = async (value: boolean, key: string) => {
setIsLoading(true);