Skip to content

findById does not include "options", but find does? #3209

Description

@DaGaMs

Description/Steps to reproduce

According to the new remoting context injection #3023 I expect to always get an options property in the current context of an operation hook. I have a mixin that will restrict the requested object to the current owner (and in the future other team members, so I can't use $owner):

module.exports=function(Model,options){Model.observe('access',functionlimitToTenant(ctx,next){varuserId=ctx.options.accessToken.userId;if(!userId){console.error("No user in context ",ctx.options);varerror=newError("Not authorized");error.statusCode=401;next(error);}if(_.has(ctx,'query')){if(_.has(ctx.query,'where')){varold=ctx.query.where;ctx.query.where={and: [old,{ownerId: userId}]};}else{ctx.query.where={ownerId: userId};}}next();});};

This works just fine when I do a request like this: /api/projects?filter[where][id]=1, but when I do a request like this: /api/projects/1, the options parameter is empty.

Expected result

I expect invocation of find and findById to both propagate the options to operation hooks.

Additional information

Here is the model definition file:

{
"name": "project",
"base": "PersistedModel",
"strict": true,
"idInjection": true,
"replaceOnPUT": false,
"options": {
"validateUpsert": true
},
"mixins": {
"AccessControl": {}
},
"mysql": {
"schema": "testdb",
"table": "Project"
},
"properties": {
"lastUpdated": {
"type": "date",
"required": true,
"length": null,
"dataType": "timestamp",
"nullable": "N"
},
"created": {
"type": "date",
"required": true,
"index": -1,
"dataType": "datetime",
"nullable": "N" },
"name": {
"type": "string",
"required": false,
"length": 256,
"index": 1,
"nullable": "Y"
}
},
"validations": [],
"relations": {
"owner": {
"model": "Person",
"type": "belongsTo"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "count"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": ["all", "find", "findOne", "findById", "findOrCreate", "create", "getIdName", "getSourceId"]
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": {
}
}

Versions

$ npm ls --prod --depth 0 | grep loopback
├── loopback@3.2.1
├── loopback-boot@2.23.0
├── loopback-component-explorer@4.0.0
├── loopback-component-passport@2.1.4 (git://github.com/dagams/loopback-component-passport.git#db99e72a8fcf7291c6803c70b7c4ebc256c0ea3e)
├── loopback-connector-mysql@3.0.0
├── loopback-datasource-juggler@3.2.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions