Hi! I am trying to integrate casl into my microservice that is linked to a mongo databse.
Previously I was using aggregation to get the desired Gateway(the entity in question) and return the access_level:
const gatewayAgr = await this.gatewayModel.aggregate([
{
$match: {
_id: new Types.ObjectId(gatewayId)
}
},
{
$unwind: '$access'
},
{
$match: {
'access._id': new Types.ObjectId(relatedId)
}
},
{
$group: {
_id: '$_id',
gateway: { $first: '$$ROOT' },
access: { $first: '$access' }
}
},
{
$project: {
_id: '$gateway._id',
name: '$gateway.access.name',
access_user: '$gateway.access._id',
access_level: '$gateway.access.access_level'
}
}
]);
if (!gatewayAgr.length) throw new UnauthorizedException('Unauthorized access to this gateway');
const gateway: GatewayIntercept = gatewayAgr[0];
And I am trying to migrate to a casl policy.
Here is my gateway-casl.factory.ts:
The relatedId is the user id that makes the call.
Finally, inside an interceptor I am getting the gateway and I am checking as a test if I can update the gateway. And when I retrive this gateway:
{
_id: new ObjectId("67312444706512a8944dbf26"),
key: '5231db1f-b79a-4dc3-a387-6f08ad7b6857',
createdAt: 2024-11-10T21:23:16.146Z,
blocked: false,
access: [
{
_id: new ObjectId("664e641213be2c69abe6219e"),
name: 'Babylon Dev',
access_level: 'owner'
}
],
applied_decoders: [],
__v: 0
}
And create the activity with this ObjectId: 664e641213be2c69abe6219e, I am getting a false for the update test.
I am down for a call of any advice you have. Please! This integration is so bad giving the deprecated documentation.