loopback icon indicating copy to clipboard operation
loopback copied to clipboard

custom role resolver not getting executed for related model

Open vnathalye opened this issue 11 years ago • 7 comments

I've defined a custom role resolver that is not getting executed when I try to access the model via relationship. E.g.- Project - Team - Tasks Project has many TeamMembers. TeamMember can belong to many Projects. Project has many Tasks. Task belong to a Project.

I'm trying to setup a scenario such that, basic project info is accessible (READ) to all authenticated users, but Tasks are accessible only to TeamMembers of that project.

ACL for project has:

{ "principalType": "ROLE", "principalId": "TeamMember", "permission": "ALLOW", "property": "__get__Tasks" }

I'm accessing tasks (from AngularJS Client) as shown below:

Project.findOne({ filter: { where: {id: 123}, include: "Tasks" } });

I was expecting that it will execute the role resolver for TeamMember, but it isn't. Is there something that I'm missing?

vnathalye avatar Dec 01 '15 02:12 vnathalye

@vnathalye : Hi Vivek, I'm looking into this issue. Could you please provide me with a sample repo to reproduce it as it will help me in the triaging process. Thank you. Please see:https://github.com/strongloop/loopback/wiki/Reporting-issues

gunjpan avatar Dec 01 '15 03:12 gunjpan

@gunjpan Hi Gunjan, Please check the sample repo @ https://github.com/vnathalye/loopback-sandbox

When you access index.html, it will show you list of projects. When you click on a project it shows basic details of the project along with the tasks associated with that project. Shouldn't the role resolver get executed before these tasks are fetched using include filter?

vnathalye avatar Dec 01 '15 07:12 vnathalye

@vnathalye :Thank you Vivek for providing with the repo. Will look into it and update you.

gunjpan avatar Dec 01 '15 17:12 gunjpan

@gunjpan: Hi Gunjan, any update on this?

vnathalye avatar Dec 09 '15 05:12 vnathalye

@vnathalye : Hi Vivek, will look into it sooner!

gunjpan avatar Dec 10 '15 07:12 gunjpan

@gunjpan Hi Gunjan,, its been a while now and I'm still waiting for update from you.

vnathalye avatar Dec 23 '15 05:12 vnathalye

@vnathalye : Hey Vivek, after extensive debugging, I found out that custom roleResolver is being called, but you won't see results as there is a Typo at controllers.js#L25. It should be :

filter: {
            where: { id: $stateParams.id },
            include: [
              'task' // model name to include - Singular version of model name - Plural is used in REST endpoints
            ]
        }

Change as above and it should work. I tried to push a branch with the change, but didn't have permission to do so. I am closing this issue. Should you need further assistance on it, feel free to comment, will be happy to help.

gunjpan avatar Dec 31 '15 18:12 gunjpan