requested changes

This commit is contained in:
Daniel Hougaard
2025-05-15 16:55:36 +04:00
parent aaeb6e73fe
commit be26dc9872
4 changed files with 15 additions and 8 deletions
@@ -121,7 +121,7 @@ export const dynamicSecretServiceFactory = ({
if (inputs && typeof inputs === "object" && "gatewayId" in inputs && inputs.gatewayId) { if (inputs && typeof inputs === "object" && "gatewayId" in inputs && inputs.gatewayId) {
const gatewayId = inputs.gatewayId as string; const gatewayId = inputs.gatewayId as string;
const [gateway] = await gatewayDAL.find({ id: gatewayId }); const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: actorOrgId });
if (!gateway) { if (!gateway) {
throw new NotFoundError({ throw new NotFoundError({
@@ -275,7 +275,7 @@ export const dynamicSecretServiceFactory = ({
if (updatedInput && typeof updatedInput === "object" && "gatewayId" in updatedInput && updatedInput?.gatewayId) { if (updatedInput && typeof updatedInput === "object" && "gatewayId" in updatedInput && updatedInput?.gatewayId) {
const gatewayId = updatedInput.gatewayId as string; const gatewayId = updatedInput.gatewayId as string;
const [gateway] = await gatewayDAL.find({ id: gatewayId }); const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: actorOrgId });
if (!gateway) { if (!gateway) {
throw new NotFoundError({ throw new NotFoundError({
message: `Gateway with ID ${gatewayId} not found` message: `Gateway with ID ${gatewayId} not found`
@@ -8,11 +8,14 @@ export type TGatewayDALFactory = ReturnType<typeof gatewayDALFactory>;
export const gatewayDALFactory = (db: TDbClient) => { export const gatewayDALFactory = (db: TDbClient) => {
const orm = ormify(db, TableName.Gateway); const orm = ormify(db, TableName.Gateway);
const find = async (filter: TFindFilter<TGateways>, { offset, limit, sort, tx }: TFindOpt<TGateways> = {}) => { const find = async (
filter: TFindFilter<TGateways> & { orgId?: string },
{ offset, limit, sort, tx }: TFindOpt<TGateways> = {}
) => {
try { try {
const query = (tx || db)(TableName.Gateway) const query = (tx || db)(TableName.Gateway)
// eslint-disable-next-line @typescript-eslint/no-misused-promises // eslint-disable-next-line @typescript-eslint/no-misused-promises
.where(buildFindFilter(filter, TableName.Gateway)) .where(buildFindFilter(filter, TableName.Gateway, ["orgId"]))
.join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.Gateway}.identityId`) .join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.Gateway}.identityId`)
.join( .join(
TableName.IdentityOrgMembership, TableName.IdentityOrgMembership,
@@ -22,6 +25,10 @@ export const gatewayDALFactory = (db: TDbClient) => {
.select(selectAllTableCols(TableName.Gateway)) .select(selectAllTableCols(TableName.Gateway))
.select(db.ref("orgId").withSchema(TableName.IdentityOrgMembership).as("identityOrgId")) .select(db.ref("orgId").withSchema(TableName.IdentityOrgMembership).as("identityOrgId"))
.select(db.ref("name").withSchema(TableName.Identity).as("identityName")); .select(db.ref("name").withSchema(TableName.Identity).as("identityName"));
if (filter.orgId) {
void query.where(`${TableName.IdentityOrgMembership}.orgId`, filter.orgId);
}
if (limit) void query.limit(limit); if (limit) void query.limit(limit);
if (offset) void query.offset(offset); if (offset) void query.offset(offset);
if (sort) { if (sort) {
+2 -2
View File
@@ -32,13 +32,13 @@ export const buildFindFilter =
<R extends object = object>( <R extends object = object>(
{ $in, $notNull, $search, $complex, ...filter }: TFindFilter<R>, { $in, $notNull, $search, $complex, ...filter }: TFindFilter<R>,
tableName?: TableName, tableName?: TableName,
excludeKeys?: Array<keyof R> excludeKeys?: string[]
) => ) =>
(bd: Knex.QueryBuilder<R, R>) => { (bd: Knex.QueryBuilder<R, R>) => {
const processedFilter = tableName const processedFilter = tableName
? Object.fromEntries( ? Object.fromEntries(
Object.entries(filter) Object.entries(filter)
.filter(([key]) => !excludeKeys || !excludeKeys.includes(key as keyof R)) .filter(([key]) => !excludeKeys || !excludeKeys.includes(key))
.map(([key, value]) => [`${tableName}.${key}`, value]) .map(([key, value]) => [`${tableName}.${key}`, value])
) )
: filter; : filter;
@@ -350,7 +350,7 @@ export const identityKubernetesAuthServiceFactory = ({
}); });
if (gatewayId) { if (gatewayId) {
const [gateway] = await gatewayDAL.find({ id: gatewayId }); const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: identityMembershipOrg.orgId });
if (!gateway) { if (!gateway) {
throw new NotFoundError({ throw new NotFoundError({
message: `Gateway with ID ${gatewayId} not found` message: `Gateway with ID ${gatewayId} not found`
@@ -466,7 +466,7 @@ export const identityKubernetesAuthServiceFactory = ({
}); });
if (gatewayId) { if (gatewayId) {
const [gateway] = await gatewayDAL.find({ id: gatewayId }); const [gateway] = await gatewayDAL.find({ id: gatewayId, orgId: identityMembershipOrg.orgId });
if (!gateway) { if (!gateway) {
throw new NotFoundError({ throw new NotFoundError({
message: `Gateway with ID ${gatewayId} not found` message: `Gateway with ID ${gatewayId} not found`