You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each remote model has a sharedClass property representing the remoting metadata. The find method allows you to look up the SharedMethod by name so that you can change the shared flag. The isStatic controls if the remote method is a static or prototype method.
What about the shared status of related models ? How can I (taking the mentioned User model as example) disable the find/deleteById/update method for the user's access tokens ??
Hello Raymond,
I know that they are internally added and that I can disable them by setting this methods to .shared = false. Problem is : There aren't any on that Models prototype 😄 . If you wan't to reproduce, try it in the loopback-example app: Add a customer.js and log out the Prototype.
e.g.
For some method, the shared property are not set correctly.
User.on('dataSourceAttached', function (obj) {
User.sharedClass.find('__findById__accessTokens').shared = false;
if (User.sharedClass.find('__findById__accessTokens').shared) {
throw new Error('Shared property have not be set correctly');
}
});
There is indeed racing condition happening as Feng suggested, at least for custom model.
I have a ResetKey model extending PersistedModel.
When I try to hide the "find" method inside "dataSourceAttached" event handler with code suggested above, it won't work, the method is still accessible.
If I move the code outside of 'dataSourceAttached' event, it worked.
But for built-in models, like User and AccessToken, one has to put the code inside 'dataSourceAttached' to make the disabling work.
It's a bit confusing and looks like a bug to me, thought?
Ps. I've upgraded to the latest version of everything.
—
Reply to this email directly or view it on GitHub.
I did more tests and seems one needs to wait a bit before setting those value, here's what I got so far, confirmed to work on both custom and built-in models.
The most interesting part is, if I run setup() before banMethods(), it won't work.
ResetKey.on('dataSourceAttached',function(obj){setTimeout(function(){promisifyMethods();banMethods();// set shared to false heresetup();modelDidAttach();},0)})functionbanMethods(){ResetKey.sharedClass.find('find',true).shared=false;}functionsetup(){ResetKey.base.setup.apply(ResetKey,arguments);}
In node, events are processed synchronously. Your listener and the loopback internal ones to set up relation methods are invoked by the order of registration. setTimeout defers your logic to future ticks and it sure helps. But the root problem is still there - dataSourceAttached event does not guarantee the model is fully configured.
I did more tests and seems one needs to wait a bit before setting those value, here's what I got so far, confirmed to work on both custom and built-in models.
ResetKey.on('dataSourceAttached', function(obj) {
setTimeout(function(){
promisifyMethods();
banMethods(); // set shared to false here
setup();
modelDidAttach();
},0)
})
—
Reply to this email directly or view it on GitHub.
While resolver() will eventually create a new branch of SharedMethods for each relation and scope everytime. That's why User.sharedClass.find('__destroyById__accessTokens', false).shared = false won't work.
Activity
sam-artuso commentedon Jul 29, 2014
same problem here.
ritch commentedon Jul 29, 2014
What version of loopback?
sam-artuso commentedon Jul 29, 2014
2.0 for me. I've posted more info here http://stackoverflow.com/questions/25002104/how-to-hide-rest-api-methods-in-loopback-2-0
coodoo commentedon Jul 30, 2014
v2.
kontza commentedon Jul 30, 2014
Ditto here, running version 2. Any workarounds available?
raymondfeng commentedon Jul 30, 2014
@ritch is working on a fix.
Thanks,
Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.
StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.
On Jul 30, 2014, at 3:12 AM, Juha Ruotsalainen notifications@github.com wrote:
ritch commentedon Jul 30, 2014
In 2.0, I'm trying to encourage people to use the strong remoting objects directly. Here is an example.
Take a look at the SharedClass documentation for more.
Edit: find is a static method
coodoo commentedon Jul 31, 2014
This would work, thanks for the tips.
Btw, should this go into documentation somewhere?
johnsoftek commentedon Jul 31, 2014
I am a little confused by the example. Isn't 'find' a static method? What does isStatic = false mean?
raymondfeng commentedon Jul 31, 2014
Each remote model has a sharedClass property representing the remoting metadata. The find method allows you to look up the SharedMethod by name so that you can change the shared flag. The isStatic controls if the remote method is a static or prototype method.
IMO, we should provide a helper method, such as:
Model.disableRemoteMethod(name, isStatic)
nvdnkpr commentedon Jul 31, 2014
What about the shared status of related models ? How can I (taking the mentioned User model as example) disable the find/deleteById/update method for the user's access tokens ??
raymondfeng commentedon Jul 31, 2014
At this moment, relation methods are internally added to the model prototype, for example,
You can use these names to disable the remoting.
lchenay commentedon Jul 31, 2014
I'm still unable to disable shared method with sharedClass:
Method is still accessible.
nvdnkpr commentedon Jul 31, 2014
Hello Raymond,
I know that they are internally added and that I can disable them by setting this methods to .shared = false. Problem is : There aren't any on that Models prototype 😄 . If you wan't to reproduce, try it in the loopback-example app: Add a customer.js and log out the Prototype.
e.g.
lchenay commentedon Jul 31, 2014
Try it inside a
Customer.on('dataSourceAttached', function (obj) {});to be sure that all data are attached.
16 remaining items
lchenay commentedon Jul 31, 2014
For some method, the shared property are not set correctly.
coodoo commentedon Aug 1, 2014
[edited]
False alarm, some how I can't reproduce the issue again after restarting the server and browser.
raymondfeng commentedon Aug 1, 2014
I'll create a different event to avoid racing conditions.
Sent from my iPhone 5
coodoo commentedon Aug 1, 2014
@raymondfeng I just edited the comment, seemed to be a false alarm, my apology.
coodoo commentedon Aug 1, 2014
I did more tests and seems one needs to wait a bit before setting those value, here's what I got so far, confirmed to work on both custom and built-in models.
The most interesting part is, if I run setup() before banMethods(), it won't work.
raymondfeng commentedon Aug 1, 2014
In node, events are processed synchronously. Your listener and the loopback internal ones to set up relation methods are invoked by the order of registration. setTimeout defers your logic to future ticks and it sure helps. But the root problem is still there - dataSourceAttached event does not guarantee the model is fully configured.
Sent from my iPhone 5
coodoo commentedon Aug 1, 2014
Agreed, there should be a better event, maybe "initialized", which guarantee the model is fully configured.
Emit dataAccessConfigured events during attach
ritch commentedon Aug 1, 2014
@lchenay Can you open a new issue with your circumstances? I have a feeling it is because you are extending a built in model.
clark0x commentedon Aug 9, 2014
I have the same problem.
shared = falsedoesn't work for all scope methods.clark0x commentedon Aug 9, 2014
check https://github.com/strongloop/strong-remoting/blob/master/lib/shared-class.js#L96
sharedClass.find()callssharedClass.methods(), which callsresolver()(https://github.com/strongloop/loopback/blob/master/lib/models/model.js#L187).While
resolver()will eventually create a new branch of SharedMethods for each relation and scope everytime. That's whyUser.sharedClass.find('__destroyById__accessTokens', false).shared = falsewon't work.nvdnkpr commentedon Aug 18, 2014
is there any update on this ??
clark0x commentedon Sep 1, 2014
@nvdnkpr @coodoo @lchenay I have made a PR to fix this issue, could you check if that works in your case? strongloop/strong-remoting#95
bajtos commentedon Nov 26, 2014
Hey everybody, the issue has been fixed since loopback 2.4.0. Now you can do:
See also #563, #595 and strongloop/strong-remoting#109.