mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 20:25:43 +00:00
@@ -15,6 +15,7 @@ import {
|
||||
} from "@app/hooks/api/dashboard/types";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { mergePersonalSecrets } from "@app/hooks/api/secrets/queries";
|
||||
import { unique } from "@app/lib/fn/array";
|
||||
|
||||
export const dashboardKeys = {
|
||||
all: () => ["dashboard"] as const,
|
||||
@@ -154,10 +155,20 @@ export const useGetProjectSecretsOverview = (
|
||||
},
|
||||
select: useCallback((data: Awaited<ReturnType<typeof fetchProjectSecretsOverview>>) => {
|
||||
const { secrets, ...select } = data;
|
||||
const uniqueSecrets = secrets ? unique(secrets, (i) => i.secretKey) : [];
|
||||
|
||||
const uniqueFolders = select.folders ? unique(select.folders, (i) => i.name) : [];
|
||||
|
||||
const uniqueDynamicSecrets = select.dynamicSecrets
|
||||
? unique(select.dynamicSecrets, (i) => i.name)
|
||||
: [];
|
||||
|
||||
return {
|
||||
...select,
|
||||
secrets: secrets ? mergePersonalSecrets(secrets) : undefined
|
||||
secrets: secrets ? mergePersonalSecrets(secrets) : undefined,
|
||||
totalUniqueSecretsInPage: uniqueSecrets.length,
|
||||
totalUniqueDynamicSecretsInPage: uniqueDynamicSecrets.length,
|
||||
totalUniqueFoldersInPage: uniqueFolders.length
|
||||
};
|
||||
}, []),
|
||||
keepPreviousData: true
|
||||
|
||||
@@ -12,6 +12,9 @@ export type DashboardProjectSecretsOverviewResponse = {
|
||||
totalFolderCount?: number;
|
||||
totalDynamicSecretCount?: number;
|
||||
totalCount: number;
|
||||
totalUniqueSecretsInPage: number;
|
||||
totalUniqueDynamicSecretsInPage: number;
|
||||
totalUniqueFoldersInPage: number;
|
||||
};
|
||||
|
||||
export type DashboardProjectSecretsDetailsResponse = {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { packRules } from "@casl/ability/extra";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
@@ -16,10 +15,7 @@ export const useCreateProjectUserAdditionalPrivilege = () => {
|
||||
|
||||
return useMutation<{ privilege: TProjectUserPrivilege }, {}, TCreateProjectUserPrivilegeDTO>({
|
||||
mutationFn: async (dto) => {
|
||||
const { data } = await apiRequest.post("/api/v1/additional-privilege/users/permanent", {
|
||||
...dto,
|
||||
permissions: packRules(dto.permissions)
|
||||
});
|
||||
const { data } = await apiRequest.post("/api/v1/additional-privilege/users/permanent", dto);
|
||||
return data.privilege;
|
||||
},
|
||||
onSuccess: (_, { projectMembershipId }) => {
|
||||
@@ -35,7 +31,7 @@ export const useUpdateProjectUserAdditionalPrivilege = () => {
|
||||
mutationFn: async (dto) => {
|
||||
const { data } = await apiRequest.patch(
|
||||
`/api/v1/additional-privilege/users/${dto.privilegeId}`,
|
||||
{ ...dto, permissions: dto.permissions ? packRules(dto.permissions) : undefined }
|
||||
dto
|
||||
);
|
||||
return data.privilege;
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { PackRule, unpackRules } from "@casl/ability/extra";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
@@ -18,10 +17,7 @@ const fetchProjectUserPrivilegeDetails = async (privilegeId: string) => {
|
||||
} = await apiRequest.get<{
|
||||
privilege: Omit<TProjectUserPrivilege, "permissions"> & { permissions: unknown };
|
||||
}>(`/api/v1/additional-privilege/users/${privilegeId}`);
|
||||
return {
|
||||
...privilege,
|
||||
permissions: unpackRules(privilege.permissions as PackRule<TProjectPermission>[])
|
||||
};
|
||||
return privilege;
|
||||
};
|
||||
|
||||
export const useGetProjectUserPrivilegeDetails = (privilegeId: string) => {
|
||||
@@ -44,7 +40,7 @@ export const useListProjectUserPrivileges = (projectMembershipId: string) => {
|
||||
}>("/api/v1/additional-privilege/users", { params: { projectMembershipId } });
|
||||
return privileges.map((el) => ({
|
||||
...el,
|
||||
permissions: unpackRules(el.permissions as PackRule<TProjectPermission>[])
|
||||
permissions: el.permissions as TProjectPermission[]
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,6 +4,15 @@ export enum ProjectUserAdditionalPrivilegeTemporaryMode {
|
||||
Relative = "relative"
|
||||
}
|
||||
|
||||
export type TProjectSpecificPrivilegePermission = {
|
||||
conditions: {
|
||||
environment: string;
|
||||
secretPath?: { $glob: string };
|
||||
};
|
||||
actions: string[];
|
||||
subject: string;
|
||||
};
|
||||
|
||||
export type TProjectUserPrivilege = {
|
||||
projectMembershipId: string;
|
||||
slug: string;
|
||||
@@ -12,21 +21,21 @@ export type TProjectUserPrivilege = {
|
||||
updatedAt: Date;
|
||||
permissions?: TProjectPermission[];
|
||||
} & (
|
||||
| {
|
||||
| {
|
||||
isTemporary: true;
|
||||
temporaryMode: string;
|
||||
temporaryRange: string;
|
||||
temporaryAccessStartTime: string;
|
||||
temporaryAccessEndTime?: string;
|
||||
}
|
||||
| {
|
||||
| {
|
||||
isTemporary: false;
|
||||
temporaryMode?: null;
|
||||
temporaryRange?: null;
|
||||
temporaryAccessStartTime?: null;
|
||||
temporaryAccessEndTime?: null;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
export type TCreateProjectUserPrivilegeDTO = {
|
||||
projectMembershipId: string;
|
||||
@@ -35,7 +44,7 @@ export type TCreateProjectUserPrivilegeDTO = {
|
||||
temporaryMode?: ProjectUserAdditionalPrivilegeTemporaryMode;
|
||||
temporaryRange?: string;
|
||||
temporaryAccessStartTime?: string;
|
||||
permissions: TProjectPermission[];
|
||||
permissions: TProjectSpecificPrivilegePermission;
|
||||
};
|
||||
|
||||
export type TUpdateProjectUserPrivlegeDTO = {
|
||||
|
||||
@@ -22,7 +22,7 @@ export const useCreateProjectRole = () => {
|
||||
mutationFn: async ({ projectSlug, ...dto }: TCreateProjectRoleDTO) => {
|
||||
const {
|
||||
data: { role }
|
||||
} = await apiRequest.post(`/api/v1/workspace/${projectSlug}/roles`, dto);
|
||||
} = await apiRequest.post(`/api/v2/workspace/${projectSlug}/roles`, dto);
|
||||
return role;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
@@ -38,7 +38,7 @@ export const useUpdateProjectRole = () => {
|
||||
mutationFn: async ({ id, projectSlug, ...dto }: TUpdateProjectRoleDTO) => {
|
||||
const {
|
||||
data: { role }
|
||||
} = await apiRequest.patch(`/api/v1/workspace/${projectSlug}/roles/${id}`, dto);
|
||||
} = await apiRequest.patch(`/api/v2/workspace/${projectSlug}/roles/${id}`, dto);
|
||||
return role;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
@@ -53,7 +53,7 @@ export const useDeleteProjectRole = () => {
|
||||
mutationFn: async ({ projectSlug, id }: TDeleteProjectRoleDTO) => {
|
||||
const {
|
||||
data: { role }
|
||||
} = await apiRequest.delete(`/api/v1/workspace/${projectSlug}/roles/${id}`);
|
||||
} = await apiRequest.delete(`/api/v2/workspace/${projectSlug}/roles/${id}`);
|
||||
return role;
|
||||
},
|
||||
onSuccess: (_, { projectSlug }) => {
|
||||
|
||||
@@ -7,6 +7,8 @@ import picomatch from "picomatch";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { OrgPermissionSet } from "@app/context/OrgPermissionContext/types";
|
||||
import { ProjectPermissionSet } from "@app/context/ProjectPermissionContext/types";
|
||||
import { groupBy } from "@app/lib/fn/array";
|
||||
import { omit } from "@app/lib/fn/object";
|
||||
|
||||
import { OrgUser, TProjectMembership } from "../users/types";
|
||||
import {
|
||||
@@ -49,7 +51,7 @@ export const roleQueryKeys = {
|
||||
|
||||
export const getProjectRoles = async (projectId: string) => {
|
||||
const { data } = await apiRequest.get<{ roles: Array<Omit<TProjectRole, "permissions">> }>(
|
||||
`/api/v1/workspace/${projectId}/roles`
|
||||
`/api/v2/workspace/${projectId}/roles`
|
||||
);
|
||||
return data.roles;
|
||||
};
|
||||
@@ -66,7 +68,7 @@ export const useGetProjectRoleBySlug = (projectSlug: string, roleSlug: string) =
|
||||
queryKey: roleQueryKeys.getProjectRoleBySlug(projectSlug, roleSlug),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ role: TProjectRole }>(
|
||||
`/api/v1/workspace/${projectSlug}/roles/slug/${roleSlug}`
|
||||
`/api/v2/workspace/${projectSlug}/roles/slug/${roleSlug}`
|
||||
);
|
||||
return data.role;
|
||||
},
|
||||
@@ -134,7 +136,7 @@ const getUserProjectPermissions = async ({ workspaceId }: TGetUserProjectPermiss
|
||||
permissions: PackRule<RawRuleOf<MongoAbility<OrgPermissionSet>>>[];
|
||||
membership: Omit<TProjectMembership, "roles"> & { roles: { role: string }[] };
|
||||
};
|
||||
}>(`/api/v1/workspace/${workspaceId}/permissions`, {});
|
||||
}>(`/api/v2/workspace/${workspaceId}/permissions`, {});
|
||||
|
||||
return data.data;
|
||||
};
|
||||
@@ -146,8 +148,32 @@ export const useGetUserProjectPermissions = ({ workspaceId }: TGetUserProjectPer
|
||||
enabled: Boolean(workspaceId),
|
||||
select: (data) => {
|
||||
const rule = unpackRules<RawRuleOf<MongoAbility<ProjectPermissionSet>>>(data.permissions);
|
||||
const ability = createMongoAbility<ProjectPermissionSet>(rule, { conditionsMatcher });
|
||||
const negatedRules = groupBy(
|
||||
rule.filter((i) => i.inverted && i.conditions),
|
||||
(i) => `${i.subject}-${JSON.stringify(i.conditions)}`
|
||||
);
|
||||
const ability = createMongoAbility<ProjectPermissionSet>(rule, {
|
||||
// this allows in frontend to skip some rules using *
|
||||
conditionsMatcher: (rules) => {
|
||||
return (entity) => {
|
||||
// skip validation if its negated rules
|
||||
const isNegatedRule =
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
negatedRules?.[`${entity.__caslSubjectType__}-${JSON.stringify(rules)}`];
|
||||
if (isNegatedRule) {
|
||||
const baseMatcher = conditionsMatcher(rules);
|
||||
return baseMatcher(entity);
|
||||
}
|
||||
|
||||
const rulesStrippedOfWildcard = omit(
|
||||
rules,
|
||||
Object.keys(entity).filter((el) => entity[el]?.includes("*"))
|
||||
);
|
||||
const baseMatcher = conditionsMatcher(rulesStrippedOfWildcard);
|
||||
return baseMatcher(entity);
|
||||
};
|
||||
}
|
||||
});
|
||||
const membership = {
|
||||
...data.membership,
|
||||
roles: data.membership.roles.map(({ role }) => role)
|
||||
|
||||
@@ -40,6 +40,7 @@ export type TPermission = {
|
||||
|
||||
export type TProjectPermission = {
|
||||
conditions?: Record<string, any>;
|
||||
inverted?: boolean;
|
||||
action: string | string[];
|
||||
subject: string | string[];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user