Skip to content

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

feat: adds frontend hooks

Piyush Guptaeb1e890f2d07
diff --git a/backend/src/server/routes/v1/group-project-router.ts b/backend/src/server/routes/v1/group-project-router.ts
index 93caf50351..ab724228ed 100644
--- a/backend/src/server/routes/v1/group-project-router.ts
+++ b/backend/src/server/routes/v1/group-project-router.ts
@@ -347,6 +347,7 @@ export const registerGroupProjectRouter = async (server: FastifyZodProvider) =>
}
});
+ // Deprecated: Duplicate of /groups/:id/users, will be removed in the future
server.route({
method: "GET",
url: "/:projectId/groups/:groupId/users",
diff --git a/frontend/src/hooks/api/groups/mutations.tsx b/frontend/src/hooks/api/groups/mutations.tsx
index d45971995f..e461aedec6 100644
--- a/frontend/src/hooks/api/groups/mutations.tsx
+++ b/frontend/src/hooks/api/groups/mutations.tsx
@@ -5,7 +5,7 @@ import { apiRequest } from "@app/config/request";
import { organizationKeys } from "../organization/queries";
import { userKeys } from "../users/query-keys";
import { groupKeys } from "./queries";
-import { TGroup } from "./types";
+import { TGroup, TGroupIdentity } from "./types";
export const useCreateGroup = () => {
const queryClient = useQueryClient();
@@ -122,3 +122,49 @@ export const useRemoveUserFromGroup = () => {
}
});
};
+
+export const useAddIdentityToGroup = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async ({
+ groupId,
+ identityId
+ }: {
+ groupId: string;
+ identityId: string;
+ slug: string;
+ }) => {
+ const { data } = await apiRequest.post<Pick<TGroupIdentity, "id" | "name">>(
+ `/api/v1/groups/${groupId}/identities/${identityId}`
+ );
+
+ return data;
+ },
+ onSuccess: (_, { slug }) => {
+ queryClient.invalidateQueries({ queryKey: groupKeys.forGroupIdentitiesMemberships(slug) });
+ }
+ });
+};
+
+export const useRemoveIdentityFromGroup = () => {
+ const queryClient = useQueryClient();
+ return useMutation({
+ mutationFn: async ({
+ groupId,
+ identityId
+ }: {
+ groupId: string;
+ identityId: string;
+ slug: string;
+ }) => {
+ const { data } = await apiRequest.delete<Pick<TGroupIdentity, "id" | "name">>(
+ `/api/v1/groups/${groupId}/identities/${identityId}`
+ );
+
+ return data;
+ },
+ onSuccess: (_, { slug }) => {
+ queryClient.invalidateQueries({ queryKey: groupKeys.forGroupIdentitiesMemberships(slug) });
+ }
+ });
+};
diff --git a/frontend/src/hooks/api/groups/queries.tsx b/frontend/src/hooks/api/groups/queries.tsx
index 2e5b9f6841..f3581f99c3 100644
--- a/frontend/src/hooks/api/groups/queries.tsx
+++ b/frontend/src/hooks/api/groups/queries.tsx
@@ -4,9 +4,11 @@ import { apiRequest } from "@app/config/request";
import { OrderByDirection } from "../generic/types";
import {
+ EFilterReturnedIdentities,
EFilterReturnedProjects,
EFilterReturnedUsers,
TGroup,
+ TGroupIdentity,
TGroupProject,
TGroupUser
} from "./types";
@@ -29,8 +31,10 @@ export const groupKeys = {
search: string;
filter?: EFilterReturnedUsers;
}) => [...groupKeys.forGroupUserMemberships(slug), { offset, limit, search, filter }] as const,
- specificProjectGroupUserMemberships: ({
- projectId,
+ allGroupIdentitiesMemberships: () => ["group-identities-memberships"] as const,
+ forGroupIdentitiesMemberships: (slug: string) =>
+ [...groupKeys.allGroupIdentitiesMemberships(), slug] as const,
+ specificGroupIdentitiesMemberships: ({
slug,
offset,
limit,
@@ -38,17 +42,12 @@ export const groupKeys = {
filter
}: {
slug: string;
- projectId: string;
offset: number;
limit: number;
search: string;
- filter?: EFilterReturnedUsers;
+ filter?: EFilterReturnedIdentities;
}) =>
- [
- ...groupKeys.forGroupUserMemberships(slug),
- projectId,
- { offset, limit, search, filter }
- ] as const,
+ [...groupKeys.forGroupIdentitiesMemberships(slug), { offset, limit, search, filter }] as const,
allGroupProjects: () => ["group-projects"] as const,
forGroupProjects: (groupId: string) => [...groupKeys.allGroupProjects(), groupId] as const,
specificGroupProjects: ({
@@ -131,9 +130,8 @@ export const useListGroupUsers = ({
});
};
-export const useListProjectGroupUsers = ({
+export const useListGroupIdentities = ({
id,
- projectId,
groupSlug,
offset = 0,
limit = 10,
@@ -142,16 +140,14 @@ export const useListProjectGroupUsers = ({
}: {
id: string;
groupSlug: string;
- projectId: string;
offset: number;
limit: number;
search: string;
- filter?: EFilterReturnedUsers;
+ filter?: EFilterReturnedIdentities;
}) => {
return useQuery({
- queryKey: groupKeys.specificProjectGroupUserMemberships({
+ queryKey: groupKeys.specificGroupIdentitiesMemberships({
slug: groupSlug,
- projectId,
offset,
limit,
search,
@@ -167,8 +163,8 @@ export const useListProjectGroupUsers = ({
...(filter && { filter })
});
- const { data } = await apiRequest.get<{ users: TGroupUser[]; totalCount: number }>(
- `/api/v1/projects/${projectId}/groups/${id}/users`,
+ const { data } = await apiRequest.get<{ identities: TGroupIdentity[]; totalCount: number }>(
+ `/api/v1/groups/${id}/identities`,
{
params
}
diff --git a/frontend/src/hooks/api/groups/types.ts b/frontend/src/hooks/api/groups/types.ts
index 1c16a331b6..123a76b0d0 100644
--- a/frontend/src/hooks/api/groups/types.ts
+++ b/frontend/src/hooks/api/groups/types.ts
@@ -52,6 +52,13 @@ export type TGroupUser = {
joinedGroupAt: Date;
};
+export type TGroupIdentity = {
+ id: string;
+ name: string;
+ isPartOfGroup: boolean;
+ joinedGroupAt: Date;
+};
+
export type TGroupProject = {
id: string;
name: string;
@@ -66,6 +73,11 @@ export enum EFilterReturnedUsers {
NON_MEMBERS = "nonMembers"
}
+export enum EFilterReturnedIdentities {
+ ASSIGNED_IDENTITIES = "assignedIdentities",
+ NON_ASSIGNED_IDENTITIES = "nonAssignedIdentities"
+}
+
export enum EFilterReturnedProjects {
ASSIGNED_PROJECTS = "assignedProjects",
UNASSIGNED_PROJECTS = "unassignedProjects"
diff --git a/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx b/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
index aa025ec239..4df332fa3c 100644
--- a/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
+++ b/frontend/src/pages/project/GroupDetailsByIDPage/components/GroupMembersSection/GroupMembersTable.tsx
@@ -35,7 +35,7 @@ import { usePagination, usePopUp, useResetPageHelper } from "@app/hooks";
import { useAssumeProjectPrivileges } from "@app/hooks/api";
import { ActorType } from "@app/hooks/api/auditLogs/enums";
import { OrderByDirection } from "@app/hooks/api/generic/types";
-import { useListProjectGroupUsers } from "@app/hooks/api/groups/queries";
+import { useListGroupUsers } from "@app/hooks/api/groups/queries";
import { EFilterReturnedUsers, TGroupMembership } from "@app/hooks/api/groups/types";
import { GroupMembershipRow } from "./GroupMembershipRow";
@@ -89,10 +89,9 @@ export const GroupMembersTable = ({ groupMembership }: Props) => {
const { isSubOrganization, currentOrg } = useOrganization();
const { currentProject } = useProject();
- const { data: groupMemberships, isPending } = useListProjectGroupUsers({
+ const { data: groupMemberships, isPending } = useListGroupUsers({
id: groupMembership.group.id,
groupSlug: groupMembership.group.slug,
- projectId: currentProject.id,
offset,
limit: perPage,
search,