mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 12:27:31 +00:00
feat: resolved permission rendering for sub org
This commit is contained in:
@@ -3,12 +3,35 @@ import { z } from "zod";
|
|||||||
|
|
||||||
import { AccessScope, OrgMembershipRole, OrgRolesSchema } from "@app/db/schemas";
|
import { AccessScope, OrgMembershipRole, OrgRolesSchema } from "@app/db/schemas";
|
||||||
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
|
||||||
import { OrgPermissionSchema } from "@app/ee/services/permission/org-permission";
|
import { OrgPermissionSchema, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||||
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||||
import { slugSchema } from "@app/server/lib/schemas";
|
import { slugSchema } from "@app/server/lib/schemas";
|
||||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
|
||||||
|
const INVALID_SUBORG_PERMISSIONS = [
|
||||||
|
OrgPermissionSubjects.Sso,
|
||||||
|
OrgPermissionSubjects.Ldap,
|
||||||
|
OrgPermissionSubjects.Scim,
|
||||||
|
OrgPermissionSubjects.GithubOrgSync,
|
||||||
|
OrgPermissionSubjects.GithubOrgSyncManual,
|
||||||
|
OrgPermissionSubjects.Billing,
|
||||||
|
OrgPermissionSubjects.SubOrganization
|
||||||
|
];
|
||||||
|
|
||||||
|
const validateSubOrganizationSubjects = (permissions: unknown) => {
|
||||||
|
const invalidPermissionSubjects = (permissions as { subject: OrgPermissionSubjects }[])
|
||||||
|
.filter((el) => INVALID_SUBORG_PERMISSIONS.includes(el.subject))
|
||||||
|
.map((el) => el.subject);
|
||||||
|
if (invalidPermissionSubjects.length) {
|
||||||
|
const deduplication = Array.from(new Set(invalidPermissionSubjects));
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Suborganization contains invalid permission subjects: ${deduplication.join(",")}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -37,6 +60,11 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
|
const isSubOrganization = req.permission.rootOrgId !== req.permission.orgId;
|
||||||
|
if (isSubOrganization) {
|
||||||
|
validateSubOrganizationSubjects(req.body.permissions);
|
||||||
|
}
|
||||||
|
|
||||||
const stringifiedPermissions = JSON.stringify(packRules(req.body.permissions));
|
const stringifiedPermissions = JSON.stringify(packRules(req.body.permissions));
|
||||||
const role = await server.services.role.createRole({
|
const role = await server.services.role.createRole({
|
||||||
permission: req.permission,
|
permission: req.permission,
|
||||||
@@ -133,6 +161,11 @@ export const registerOrgRoleRouter = async (server: FastifyZodProvider) => {
|
|||||||
},
|
},
|
||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
|
const isSubOrganization = req.permission.rootOrgId !== req.permission.orgId;
|
||||||
|
if (isSubOrganization && req.body.permissions) {
|
||||||
|
validateSubOrganizationSubjects(req.body.permissions);
|
||||||
|
}
|
||||||
|
|
||||||
const stringifiedPermissions = req.body.permissions ? JSON.stringify(packRules(req.body.permissions)) : undefined;
|
const stringifiedPermissions = req.body.permissions ? JSON.stringify(packRules(req.body.permissions)) : undefined;
|
||||||
const role = await server.services.role.updateRole({
|
const role = await server.services.role.updateRole({
|
||||||
permission: req.permission,
|
permission: req.permission,
|
||||||
|
|||||||
+1
-1
@@ -28,8 +28,8 @@ import { OrgUser } from "@app/hooks/api/users/types";
|
|||||||
import { usePopUp } from "@app/hooks/usePopUp";
|
import { usePopUp } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
import { AddOrgMemberModal } from "./AddOrgMemberModal";
|
import { AddOrgMemberModal } from "./AddOrgMemberModal";
|
||||||
import { OrgMembersTable } from "./OrgMembersTable";
|
|
||||||
import { AddSubOrgMemberModal } from "./AddSubOrgMemberModal";
|
import { AddSubOrgMemberModal } from "./AddSubOrgMemberModal";
|
||||||
|
import { OrgMembersTable } from "./OrgMembersTable";
|
||||||
|
|
||||||
export const OrgMembersSection = () => {
|
export const OrgMembersSection = () => {
|
||||||
const { subscription } = useSubscription();
|
const { subscription } = useSubscription();
|
||||||
|
|||||||
+30
-12
@@ -77,8 +77,18 @@ type Props = {
|
|||||||
roleId: string;
|
roleId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const INVALID_SUBORG_PERMISSIONS = [
|
||||||
|
OrgPermissionSubjects.Sso,
|
||||||
|
OrgPermissionSubjects.Ldap,
|
||||||
|
OrgPermissionSubjects.Scim,
|
||||||
|
OrgPermissionSubjects.GithubOrgSync,
|
||||||
|
OrgPermissionSubjects.GithubOrgSyncManual,
|
||||||
|
OrgPermissionSubjects.Billing,
|
||||||
|
OrgPermissionSubjects.SubOrganization
|
||||||
|
];
|
||||||
|
|
||||||
export const RolePermissionsSection = ({ roleId }: Props) => {
|
export const RolePermissionsSection = ({ roleId }: Props) => {
|
||||||
const { currentOrg } = useOrganization();
|
const { currentOrg, isRootOrganization } = useOrganization();
|
||||||
const orgId = currentOrg?.id || "";
|
const orgId = currentOrg?.id || "";
|
||||||
|
|
||||||
const { data: role } = useGetOrgRole(orgId, roleId);
|
const { data: role } = useGetOrgRole(orgId, roleId);
|
||||||
@@ -153,7 +163,11 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
|
|||||||
<TableContainer>
|
<TableContainer>
|
||||||
<Table>
|
<Table>
|
||||||
<TBody>
|
<TBody>
|
||||||
{SIMPLE_PERMISSION_OPTIONS.map((permission) => {
|
{SIMPLE_PERMISSION_OPTIONS.filter((el) =>
|
||||||
|
isRootOrganization
|
||||||
|
? true
|
||||||
|
: !INVALID_SUBORG_PERMISSIONS.includes(el.formName as OrgPermissionSubjects)
|
||||||
|
).map((permission) => {
|
||||||
return (
|
return (
|
||||||
<RolePermissionRow
|
<RolePermissionRow
|
||||||
title={permission.title}
|
title={permission.title}
|
||||||
@@ -195,11 +209,13 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
|
|||||||
setValue={setValue}
|
setValue={setValue}
|
||||||
isEditable={isCustomRole}
|
isEditable={isCustomRole}
|
||||||
/>
|
/>
|
||||||
<OrgPermissionBillingRow
|
{isRootOrganization && (
|
||||||
control={control}
|
<OrgPermissionBillingRow
|
||||||
setValue={setValue}
|
control={control}
|
||||||
isEditable={isCustomRole}
|
setValue={setValue}
|
||||||
/>
|
isEditable={isCustomRole}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<OrgPermissionSecretShareRow
|
<OrgPermissionSecretShareRow
|
||||||
control={control}
|
control={control}
|
||||||
setValue={setValue}
|
setValue={setValue}
|
||||||
@@ -225,11 +241,13 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
|
|||||||
setValue={setValue}
|
setValue={setValue}
|
||||||
isEditable={isCustomRole}
|
isEditable={isCustomRole}
|
||||||
/>
|
/>
|
||||||
<OrgPermissionSubOrgRow
|
{isRootOrganization && (
|
||||||
control={control}
|
<OrgPermissionSubOrgRow
|
||||||
setValue={setValue}
|
control={control}
|
||||||
isEditable={isCustomRole}
|
setValue={setValue}
|
||||||
/>
|
isEditable={isCustomRole}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</TBody>
|
</TBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user