WordPoints / hooks-api

A basic API for hooking into user actions https://github.com/WordPoints/wordpoints/issues/321
GNU General Public License v2.0
0 stars 0 forks source link

API for getting only reactions that can target a specific entity #58

Closed JDGrimes closed 8 years ago

JDGrimes commented 8 years ago

57 introduces an issue related to #51 that has been tucked away at the back of my mind for quite some time:

For example, say that we have a site that has trainers and trainees. We want to be able to allow the trainers to create reactions that are exclusive to their trainees. This would probably be similar to standard reactions, except that they'd have a special restriction: they'd only be active when the current user was one of the trainees of the trainer who created the reaction.

Now, we could accomplish that using a custom extension and standard reactions. Our extension would have a should_it() method that would check whether the reaction target was one of the trainer's trainees. The problem with that, though, is that all of the reactions created by all trainers would be displayed by the how-to-get-points shortcode. (This is actually a broader issue.)

What I've been thinking is that we should build into the API a means of determining whether a particular entity would be a valid target for a particular reaction. That way we could just get the reactions that would apply to a specific user, like we need to do in the how-to-get-points shortcode.

We'd probably introduce a can_target() method or something like that to the extension class.

Just to be clear, this is different than just checking that the entity is of a type supported by the reactor (although of course that is necessary), it involves, for example, checking that any conditions that apply to the target would match that particular user (e.g., they'd have to have a specific role, etc.).

JDGrimes commented 8 years ago

I really like this idea, but I don't think that it is something that we should try to pursue in the initial version at this point. It is a nice feature, but it isn't absolutely necessary for the operation of the how-to-get-points shortcode.

JDGrimes commented 8 years ago

Oh, and yes, it would kind of be nice to have this API in the initial version, just because it looses some of its potency if it isn't complete. But we might be migrating away from the hooks API and toward the possessions API in the future anyway, so perhaps we'll wait until then for this (though it would still be a useful feature in the hooks API as well as long as it stays around in some form).

JDGrimes commented 8 years ago

Closing in favor of https://github.com/WordPoints/wordpoints/issues/465.