Compare commits

...

1 Commits

Author SHA1 Message Date
Daniel Hougaard
8bc9a5efcd Fix: SCIM Groups find by filter 2024-06-11 00:00:16 +02:00
4 changed files with 21 additions and 16 deletions

View File

@@ -362,6 +362,7 @@ export const registerScimRouter = async (server: FastifyZodProvider) => {
const groups = await req.server.services.scim.listScimGroups({ const groups = await req.server.services.scim.listScimGroups({
orgId: req.permission.orgId, orgId: req.permission.orgId,
startIndex: req.query.startIndex, startIndex: req.query.startIndex,
filter: req.query.filter,
limit: req.query.count limit: req.query.count
}); });

View File

@@ -18,6 +18,20 @@ export const buildScimUserList = ({
}; };
}; };
export const parseScimFilter = (filterToParse: string | undefined) => {
if (!filterToParse) return {};
const [parsedName, parsedValue] = filterToParse.split("eq").map((s) => s.trim());
let attributeName = parsedName;
if (parsedName === "userName") {
attributeName = "email";
} else if (parsedName === "displayName") {
attributeName = "name";
}
return { [attributeName]: parsedValue.replace(/"/g, "") };
};
export const buildScimUser = ({ export const buildScimUser = ({
orgMembershipId, orgMembershipId,
username, username,

View File

@@ -30,7 +30,7 @@ import { UserAliasType } from "@app/services/user-alias/user-alias-types";
import { TLicenseServiceFactory } from "../license/license-service"; import { TLicenseServiceFactory } from "../license/license-service";
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission"; import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
import { TPermissionServiceFactory } from "../permission/permission-service"; import { TPermissionServiceFactory } from "../permission/permission-service";
import { buildScimGroup, buildScimGroupList, buildScimUser, buildScimUserList } from "./scim-fns"; import { buildScimGroup, buildScimGroupList, buildScimUser, buildScimUserList, parseScimFilter } from "./scim-fns";
import { import {
TCreateScimGroupDTO, TCreateScimGroupDTO,
TCreateScimTokenDTO, TCreateScimTokenDTO,
@@ -184,18 +184,6 @@ export const scimServiceFactory = ({
status: 403 status: 403
}); });
const parseFilter = (filterToParse: string | undefined) => {
if (!filterToParse) return {};
const [parsedName, parsedValue] = filterToParse.split("eq").map((s) => s.trim());
let attributeName = parsedName;
if (parsedName === "userName") {
attributeName = "email";
}
return { [attributeName]: parsedValue.replace(/"/g, "") };
};
const findOpts = { const findOpts = {
...(startIndex && { offset: startIndex - 1 }), ...(startIndex && { offset: startIndex - 1 }),
...(limit && { limit }) ...(limit && { limit })
@@ -204,7 +192,7 @@ export const scimServiceFactory = ({
const users = await orgDAL.findMembership( const users = await orgDAL.findMembership(
{ {
[`${TableName.OrgMembership}.orgId` as "id"]: orgId, [`${TableName.OrgMembership}.orgId` as "id"]: orgId,
...parseFilter(filter) ...parseScimFilter(filter)
}, },
findOpts findOpts
); );
@@ -557,7 +545,7 @@ export const scimServiceFactory = ({
return {}; // intentionally return empty object upon success return {}; // intentionally return empty object upon success
}; };
const listScimGroups = async ({ orgId, startIndex, limit }: TListScimGroupsDTO) => { const listScimGroups = async ({ orgId, startIndex, limit, filter }: TListScimGroupsDTO) => {
const plan = await licenseService.getPlan(orgId); const plan = await licenseService.getPlan(orgId);
if (!plan.groups) if (!plan.groups)
throw new BadRequestError({ throw new BadRequestError({
@@ -580,7 +568,8 @@ export const scimServiceFactory = ({
const groups = await groupDAL.findGroups( const groups = await groupDAL.findGroups(
{ {
orgId orgId,
...(filter && parseScimFilter(filter))
}, },
{ {
offset: startIndex - 1, offset: startIndex - 1,

View File

@@ -66,6 +66,7 @@ export type TDeleteScimUserDTO = {
export type TListScimGroupsDTO = { export type TListScimGroupsDTO = {
startIndex: number; startIndex: number;
filter?: string;
limit: number; limit: number;
orgId: string; orgId: string;
}; };