mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 22:27:48 +00:00
improvements: address feedback
This commit is contained in:
@@ -94,7 +94,7 @@ export const registerAppConnectionEndpoints = <T extends TAppConnection, I exten
|
|||||||
tags: [ApiDocsTags.AppConnections],
|
tags: [ApiDocsTags.AppConnections],
|
||||||
description: `List the ${appName} Connections the current user has permission to establish connections within this project.`,
|
description: `List the ${appName} Connections the current user has permission to establish connections within this project.`,
|
||||||
querystring: z.object({
|
querystring: z.object({
|
||||||
projectId: z.string().describe(AppConnections.LIST(app).projectId)
|
projectId: z.string().optional().describe(AppConnections.LIST(app).projectId)
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
|
|||||||
@@ -741,25 +741,7 @@ export const appConnectionServiceFactory = ({
|
|||||||
return appConnection;
|
return appConnection;
|
||||||
};
|
};
|
||||||
|
|
||||||
const listAvailableAppConnectionsForUser = async (app: AppConnection, actor: OrgServiceActor, projectId: string) => {
|
const listAvailableAppConnectionsForUser = async (app: AppConnection, actor: OrgServiceActor, projectId?: string) => {
|
||||||
const project = await projectDAL.findProjectById(projectId);
|
|
||||||
|
|
||||||
if (!project) throw new BadRequestError({ message: `Could not find project with ID ${projectId}` });
|
|
||||||
|
|
||||||
const { permission: projectPermission } = await permissionService.getProjectPermission({
|
|
||||||
actor: actor.type,
|
|
||||||
actorId: actor.id,
|
|
||||||
projectId,
|
|
||||||
actorAuthMethod: actor.authMethod,
|
|
||||||
actorOrgId: actor.orgId,
|
|
||||||
actionProjectType: ActionProjectType.Any
|
|
||||||
});
|
|
||||||
|
|
||||||
ForbiddenError.from(projectPermission).throwUnlessCan(
|
|
||||||
ProjectPermissionAppConnectionActions.Connect,
|
|
||||||
ProjectPermissionSub.AppConnections
|
|
||||||
);
|
|
||||||
|
|
||||||
const { permission: orgPermission } = await permissionService.getOrgPermission(
|
const { permission: orgPermission } = await permissionService.getOrgPermission(
|
||||||
actor.type,
|
actor.type,
|
||||||
actor.id,
|
actor.id,
|
||||||
@@ -768,6 +750,37 @@ export const appConnectionServiceFactory = ({
|
|||||||
actor.orgId
|
actor.orgId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let availableProjectConnections: TAppConnections[] = [];
|
||||||
|
|
||||||
|
if (projectId) {
|
||||||
|
const project = await projectDAL.findProjectById(projectId);
|
||||||
|
|
||||||
|
if (!project) throw new BadRequestError({ message: `Could not find project with ID ${projectId}` });
|
||||||
|
|
||||||
|
const { permission: projectPermission } = await permissionService.getProjectPermission({
|
||||||
|
actor: actor.type,
|
||||||
|
actorId: actor.id,
|
||||||
|
projectId,
|
||||||
|
actorAuthMethod: actor.authMethod,
|
||||||
|
actorOrgId: actor.orgId,
|
||||||
|
actionProjectType: ActionProjectType.Any
|
||||||
|
});
|
||||||
|
|
||||||
|
ForbiddenError.from(projectPermission).throwUnlessCan(
|
||||||
|
ProjectPermissionAppConnectionActions.Connect,
|
||||||
|
ProjectPermissionSub.AppConnections
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectAppConnections = await appConnectionDAL.find({ app, projectId });
|
||||||
|
|
||||||
|
availableProjectConnections = projectAppConnections.filter((connection) =>
|
||||||
|
projectPermission.can(
|
||||||
|
ProjectPermissionAppConnectionActions.Connect,
|
||||||
|
subject(ProjectPermissionSub.AppConnections, { connectionId: connection.id })
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const orgAppConnections = await appConnectionDAL.find({ app, orgId: actor.orgId, projectId: null });
|
const orgAppConnections = await appConnectionDAL.find({ app, orgId: actor.orgId, projectId: null });
|
||||||
|
|
||||||
const availableOrgConnections = orgAppConnections.filter((connection) =>
|
const availableOrgConnections = orgAppConnections.filter((connection) =>
|
||||||
@@ -777,15 +790,6 @@ export const appConnectionServiceFactory = ({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const projectAppConnections = await appConnectionDAL.find({ app, projectId });
|
|
||||||
|
|
||||||
const availableProjectConnections = projectAppConnections.filter((connection) =>
|
|
||||||
projectPermission.can(
|
|
||||||
ProjectPermissionAppConnectionActions.Connect,
|
|
||||||
subject(ProjectPermissionSub.AppConnections, { connectionId: connection.id })
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return [...availableOrgConnections, ...availableProjectConnections].sort((a, b) =>
|
return [...availableOrgConnections, ...availableProjectConnections].sort((a, b) =>
|
||||||
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
|
a.name.toLowerCase().localeCompare(b.name.toLowerCase())
|
||||||
) as Omit<TAppConnection, "credentials">[];
|
) as Omit<TAppConnection, "credentials">[];
|
||||||
|
|||||||
+1
@@ -601,6 +601,7 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
placeholder="Select connection..."
|
placeholder="Select connection..."
|
||||||
getOptionLabel={(option) => option.name}
|
getOptionLabel={(option) => option.name}
|
||||||
getOptionValue={(option) => option.id}
|
getOptionValue={(option) => option.id}
|
||||||
|
components={{ Option: AppConnectionOption }}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user