-
-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Shorthand for disabling service methods #106
Shorthand for disabling service methods #106
Comments
I would think this is something the pre-build services or separate hooks should do. Probably be fairly simple, too: var onlyMixin = {
only: function(...names) {
var mixin = {};
for(let name of names) {
mixin[name] = function() {
var callback = arguments[arguments.length - 1];
callback(new errors.NotImplemented('Not allowed'));
}
}
return this.extend(mixin);
}
} |
Ya it's definitely the individual service's concern but I'd like to enforce that as a required method (ie. we'll need to document it for writing service plugins). I can go through and add the mixin to the services (since it is my feature request). You're right that it doesn't belong in feathers core. I just wanted to bring it up in this repo so that we could discuss it in a more central place. |
I think this needs to be in 1.1.0. It goes along great with what we were talking about in #108. I don't see why it shouldn't be in Feathers core. |
👍 |
I'm still a little hesitant about this but I can see the point and adding it as a plugin would be total overkill and somewhat pointless. I added it to 1.1.0 but suggest to go the other way around and disable methods (instead of telling it which ones to allow): var service = mongodb({ collection: 'users' });
app.use('/users', service);
app.service('users').disable('find', 'update'); In fact, we could even add the external flag mentioned in the FAQ app.use(function(req, res, next) {
req.feathers.external = 'rest';
next();
});
app.configure(feathers.socketio(function(io) {
io.use(function(socket, next) {
// For websockets the feathers object does not exist by default
if(!socket.feathers) {
socket.feathers = {};
}
socket.feathers.external = 'socketio';
next();
});
})); By default and then use app.service('users').disable('find', function(params, callback) {
if(params.external === 'rest') {
return callback(null, false);
}
return callback();
}); |
Sounds good. Adding the external flag by default will be quite convenient. 👍 |
I agree. Both sound great! |
I'm going to bump this to 1.2 (or 2.0 whichever one comes first) unless it is a must have feature for you guys for 1.1. If not I think we're feature complete and can focus on the website and the guides. |
We ended up having a private discussion in Slack and it looks like the interface will actually just utilize hooks. So it would look something like this: import { common as hooks } from 'feathers-hooks';
// disable socketio provider on all todo service methods
app.service('todos').before(hooks.disable('socketio'));
// or
app.service('todos').before({
all: hooks.disable('socketio')
});
// disable for other random use cases
app.service('todos').before(hooks.disable(function(hook) {
return true/false/promise
}));
// disable specific methods for specific transports
app.service('todos').before({
patch: hooks.disable('socketio'),
update: hooks.disable('socketio'),
remove: hooks.disable('rest')
}));
// disable any external transport calls (ie. REST, socket, or any future one)
app.service('todos').before({
remove: hooks.disable()
}));
// or
app.service('todos').before({
remove: hooks.disable('external')
}));
// disable any call including internal calls in code for remove
app.service('todos').before({
remove: hooks.disable('all')
})); |
How can hooks be disabled now?
does not seem to work. |
To disable methods use the disallow hook from feathers-hooks-common. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
I think it would be nice to be able to disable or specify that you only want certain default service methods to be enabled. Especially when using an existing service plugin (ie. mongoose, mongo, etc).
This can be obtained by extending the original service and then overriding the service methods and returning an error, like so:
However, I thought it would be really awesome to only enable certain service methods like this:
The text was updated successfully, but these errors were encountered: