improvements: address feedback

This commit is contained in:
Scott Wilson
2025-09-15 17:58:40 -07:00
parent feb234ddcc
commit c730b6fff4
3 changed files with 34 additions and 29 deletions
@@ -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,7 +741,18 @@ 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 { permission: orgPermission } = await permissionService.getOrgPermission(
actor.type,
actor.id,
actor.orgId,
actor.authMethod,
actor.orgId
);
let availableProjectConnections: TAppConnections[] = [];
if (projectId) {
const project = await projectDAL.findProjectById(projectId); const project = await projectDAL.findProjectById(projectId);
if (!project) throw new BadRequestError({ message: `Could not find project with ID ${projectId}` }); if (!project) throw new BadRequestError({ message: `Could not find project with ID ${projectId}` });
@@ -760,13 +771,15 @@ export const appConnectionServiceFactory = ({
ProjectPermissionSub.AppConnections ProjectPermissionSub.AppConnections
); );
const { permission: orgPermission } = await permissionService.getOrgPermission( const projectAppConnections = await appConnectionDAL.find({ app, projectId });
actor.type,
actor.id, availableProjectConnections = projectAppConnections.filter((connection) =>
actor.orgId, projectPermission.can(
actor.authMethod, ProjectPermissionAppConnectionActions.Connect,
actor.orgId 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 });
@@ -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">[];
@@ -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>
)} )}