@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.14 kB
Source Map (JSON)
{"version":3,"file":"check-user-access.mjs","names":[],"sources":["../../../../src/services/users/checks/check-user-access.ts"],"sourcesContent":["import { copy } from \"../../../libs/i18n/index.js\";\nimport { UsersRepository } from \"../../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\n\n/**\n * Confirms users are visible in the current tenant scope before writes.\n * Users without tenant memberships remain global and visible to tenants.\n */\nconst checkUserAccess: ServiceFn<\n\t[\n\t\t{\n\t\t\tid?: number;\n\t\t\tids?: number[];\n\t\t\twhere?: Parameters<UsersRepository[\"selectMultipleByIds\"]>[0][\"where\"];\n\t\t},\n\t],\n\tundefined\n> = async (context, data) => {\n\tconst ids = Array.from(\n\t\tnew Set(data.ids ?? (data.id !== undefined ? [data.id] : [])),\n\t);\n\n\tif (ids.length === 0) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst Users = new UsersRepository(context.db.client, context.config.db);\n\tconst usersRes = await Users.selectMultipleByIds({\n\t\tids,\n\t\ttenantKey: context.request.tenantKey,\n\t\twhere: data.where,\n\t\tvalidation: {\n\t\t\tenabled: true,\n\t\t},\n\t});\n\tif (usersRes.error) return usersRes;\n\n\tif (usersRes.data.length !== ids.length) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tmessage: copy(\"server:core.user.not.found.message\"),\n\t\t\t\tstatus: 404,\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default checkUserAccess;\n"],"mappings":"uGAQA,MAAM,EASF,MAAO,EAAS,IAAS,CAC5B,IAAM,EAAM,MAAM,KACjB,IAAI,IAAI,EAAK,MAAQ,EAAK,KAAO,IAAA,GAAwB,CAAC,EAAb,CAAC,EAAK,EAAE,EAAO,CAC7D,EAEA,GAAI,EAAI,SAAW,EAClB,MAAO,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,EAID,IAAM,EAAW,MAAM,IADL,EAAgB,EAAQ,GAAG,OAAQ,EAAQ,OAAO,EACzC,CAAC,CAAC,oBAAoB,CAChD,MACA,UAAW,EAAQ,QAAQ,UAC3B,MAAO,EAAK,MACZ,WAAY,CACX,QAAS,EACV,CACD,CAAC,EAcD,OAbI,EAAS,MAAc,EAEvB,EAAS,KAAK,SAAW,EAAI,OAW1B,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,EAbQ,CACN,MAAO,CACN,KAAM,QACN,QAAS,EAAK,oCAAoC,EAClD,OAAQ,GACT,EACA,KAAM,IAAA,EACP,CAOF"}