-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow glob-style patterns for remote options #3504
Conversation
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
Can one of the admins verify this patch? |
3 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
@slnode ok to test |
Hello @zbarbuto, thank you for the pull request! The proposed changes make sense at high level. Could you please add few tests to verify them? Also, I think it's not enough to replace |
@bajtos Have sanitized incoming strings for reserved regex characters (excluding Have added tests but this has revealed a problem that the globs still don't seem to be working for related methods. I can't figure out why. In debugging I can see that it's definitely setting the correct methods to Possibly something further down the chain is re-enabling them again (such as |
}) | ||
.map(function(m) { | ||
return m.stringName.replace(/^[^.]+\./, ''); // drop the class name | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extract these 8 lines of code into a shared helper function. E.g. listPublicMethods(TestModel)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Remoting metadata for relation methods is defined via strong-remoting "resolver", which is a function called by The part in strong-remoting: https://github.com/strongloop/strong-remoting/blob/5b89fb2ab79a77c5b4d25b4009e8033951eb4852/lib/shared-class.js#L133-L136 The part in LoopBack: Lines 261 to 296 in 839c586
As I understand this code, the BTW similar issue exists for methods with remoting metadata defined via function properties, e.g. You may be wondering why we don't define relation remote methods immediately at model setup time, similarly how regular PersistedModel methods are defined. So am I :) I think the original reason was that relations are defined by connectors when the model is attached to a datasource, which typically happens later, possibly even asynchronously (e.g. for connectors like SOAP or Swagger that need to fetch WSDL/Swagger description of the API first). I am not sure if that's still relevant though. As a short-term workaround, perhaps you could use a different approach for disabling remote methods and call Thoughts? cc @ritch as the original author of strong-remoting resolvers (IIRC) |
8376601
to
07349b6
Compare
@bajtos Sorry for the delay in updating this. Finally managed to get it working with |
if (settings[methodName] === false) { | ||
sharedMethod.sharedClass.disableMethodByName(methodName); | ||
} else { | ||
sharedMethod.shared = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR - this line needed to be added otherwise tests relating to default definitions in model-config.json
were failing.
if (glob.setting === false) { | ||
sharedMethod.sharedClass.disableMethodByName(methodName); | ||
} else { | ||
sharedMethod.shared = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same again here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! The changes LGTM now. Could you please squash the commits into a single one and provide a descriptive commit message following our 50/72 rule?
If you are not familiar with git history rewriting, here are the commands to run:
git rebase -i master
git push -f
07349b6
to
7e9108e
Compare
@bajtos No problems. Done. |
7e9108e
to
724a7d1
Compare
Rebased off latest master. |
Landed, thank you for the contribution! 🎉 |
Description
This PR achieves two things:
setSharedMethodSharedProperties
to after registry configuration, shared methods on model relations can correctly be disabled (White/Black listing methods generated by relations #2860)__*__someRelation
to disable all remote methods of a model relationship)Note, the reason I used string replacement for
*
instead of straight regular expressions is to make it backwards compatible ('*' will still enable/disable all methods)Related issues
Checklist
guide