feat: moved trusted ips anmd assume privilege to new /projects

This commit is contained in:
=
2025-09-11 20:02:34 +05:30
parent d3acc90d6a
commit 024e16ac60
4 changed files with 31 additions and 37 deletions

View File

@@ -52,8 +52,6 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
async (projectRouter) => {
await projectRouter.register(registerDepreciatedProjectRoleRouter);
await projectRouter.register(registerProjectRouter);
await projectRouter.register(registerTrustedIpRouter);
await projectRouter.register(registerAssumePrivilegeRouter);
},
{ prefix: "/workspace" }
);
@@ -61,6 +59,8 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
await server.register(
async (projectRouter) => {
await projectRouter.register(registerProjectRoleRouter);
await projectRouter.register(registerTrustedIpRouter);
await projectRouter.register(registerAssumePrivilegeRouter);
},
{ prefix: "/projects" }
);

View File

@@ -9,13 +9,13 @@ import { AuthMode } from "@app/services/auth/auth-type";
export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
server.route({
method: "GET",
url: "/:workspaceId/trusted-ips",
url: "/:projectId/trusted-ips",
config: {
rateLimit: readLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
projectId: z.string().trim()
}),
response: {
200: z.object({
@@ -27,7 +27,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
const trustedIps = await server.services.trustedIp.listIpsByProjectId({
actorAuthMethod: req.permission.authMethod,
projectId: req.params.workspaceId,
projectId: req.params.projectId,
actor: req.permission.type,
actorId: req.permission.id,
actorOrgId: req.permission.orgId
@@ -38,13 +38,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
server.route({
method: "POST",
url: "/:workspaceId/trusted-ips",
url: "/:projectId/trusted-ips",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim()
projectId: z.string().trim()
}),
body: z.object({
ipAddress: z.string().trim(),
@@ -61,7 +61,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
const { trustedIp, project } = await server.services.trustedIp.addProjectIp({
actorAuthMethod: req.permission.authMethod,
projectId: req.params.workspaceId,
projectId: req.params.projectId,
actor: req.permission.type,
actorId: req.permission.id,
actorOrgId: req.permission.orgId,
@@ -86,13 +86,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
server.route({
method: "PATCH",
url: "/:workspaceId/trusted-ips/:trustedIpId",
url: "/:projectId/trusted-ips/:trustedIpId",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim(),
projectId: z.string().trim(),
trustedIpId: z.string().trim()
}),
body: z.object({
@@ -108,7 +108,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { trustedIp, project } = await server.services.trustedIp.updateProjectIp({
projectId: req.params.workspaceId,
projectId: req.params.projectId,
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,
@@ -135,13 +135,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
server.route({
method: "DELETE",
url: "/:workspaceId/trusted-ips/:trustedIpId",
url: "/:projectId/trusted-ips/:trustedIpId",
config: {
rateLimit: writeLimit
},
schema: {
params: z.object({
workspaceId: z.string().trim(),
projectId: z.string().trim(),
trustedIpId: z.string().trim()
}),
response: {
@@ -153,7 +153,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
const { trustedIp, project } = await server.services.trustedIp.deleteProjectIp({
projectId: req.params.workspaceId,
projectId: req.params.projectId,
actor: req.permission.type,
actorId: req.permission.id,
actorAuthMethod: req.permission.authMethod,

View File

@@ -8,7 +8,7 @@ export const useAssumeProjectPrivileges = () =>
useMutation({
mutationFn: async ({ projectId, actorId, actorType }: TProjectAssumePrivilegesDTO) => {
const { data } = await apiRequest.post<{ message: string }>(
`/api/v1/workspace/${projectId}/assume-privileges`,
`/api/v1/projects/${projectId}/assume-privileges`,
{ actorId, actorType }
);
@@ -20,7 +20,7 @@ export const useRemoveAssumeProjectPrivilege = () =>
useMutation({
mutationFn: async ({ projectId }: { projectId: string }) => {
const { data } = await apiRequest.delete<{ message: string }>(
`/api/v1/workspace/${projectId}/assume-privileges`
`/api/v1/projects/${projectId}/assume-privileges`
);
return data;

View File

@@ -5,15 +5,15 @@ import { apiRequest } from "@app/config/request";
import { TrustedIp } from "./types";
const trustedIps = {
getTrustedIps: (workspaceId: string) => [{ workspaceId }, "trusted-ips"] as const
getTrustedIps: (projectId: string) => [{ projectId }, "trusted-ips"] as const
};
export const useGetTrustedIps = (workspaceId: string) => {
export const useGetTrustedIps = (projectId: string) => {
return useQuery({
queryKey: trustedIps.getTrustedIps(workspaceId),
queryKey: trustedIps.getTrustedIps(projectId),
queryFn: async () => {
const { data } = await apiRequest.get<{ trustedIps: TrustedIp[] }>(
`/api/v1/workspace/${workspaceId}/trusted-ips`
`/api/v1/projects/${projectId}/trusted-ips`
);
return data.trustedIps;
@@ -25,17 +25,17 @@ export const useAddTrustedIp = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
workspaceId,
projectId,
ipAddress,
comment,
isActive
}: {
workspaceId: string;
projectId: string;
ipAddress: string;
comment?: string;
isActive: boolean;
}) => {
const { data } = await apiRequest.post(`/api/v1/workspace/${workspaceId}/trusted-ips`, {
const { data } = await apiRequest.post(`/api/v1/projects/${projectId}/trusted-ips`, {
ipAddress,
...(comment ? { comment } : {}),
isActive
@@ -44,7 +44,7 @@ export const useAddTrustedIp = () => {
return data;
},
onSuccess(_, dto) {
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
}
});
};
@@ -53,20 +53,20 @@ export const useUpdateTrustedIp = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
workspaceId,
projectId,
trustedIpId,
ipAddress,
comment,
isActive
}: {
workspaceId: string;
projectId: string;
trustedIpId: string;
ipAddress: string;
comment?: string;
isActive: boolean;
}) => {
const { data } = await apiRequest.patch(
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`,
`/api/v1/projects/${projectId}/trusted-ips/${trustedIpId}`,
{
ipAddress,
...(comment ? { comment } : {}),
@@ -77,7 +77,7 @@ export const useUpdateTrustedIp = () => {
return data;
},
onSuccess(_, dto) {
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
}
});
};
@@ -85,21 +85,15 @@ export const useUpdateTrustedIp = () => {
export const useDeleteTrustedIp = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async ({
workspaceId,
trustedIpId
}: {
workspaceId: string;
trustedIpId: string;
}) => {
mutationFn: async ({ projectId, trustedIpId }: { projectId: string; trustedIpId: string }) => {
const { data } = await apiRequest.delete(
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`
`/api/v1/projects/${projectId}/trusted-ips/${trustedIpId}`
);
return data;
},
onSuccess(_, dto) {
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
}
});
};