django-star-ratings
django-star-ratings copied to clipboard
Discriminate which user can vote
Hi all. I think there is a very important use case that is not addressed by this lbry, how can one discriminate which user can vote? In my case, I need to make sure only users with a "certificate" can vote on the course rating (other users haven't taken the course, they shouldn't be able to vote). How can I achieve that, the template tag doesn't receive any useful argument for this. There is an editable
template variable but no docs on how/where to set it to false.
Hi @Alejoss
Thanks for the report, that does sound like a useful feature to add.
I think it could be answered a couple of ways, either via overriding editable in the template to check for a permission, or perhaps a more generic solution would be to amend how editable is used within ratings.py
https://github.com/wildfish/django-star-ratings/blob/3495eaab0847bd5cae5a237213ed11b321a563ca/star_ratings/templatetags/ratings.py#L57
Adding a variable along the lines of STAR_RATINGS_PERMISSIONS_CHECK
to allow users to specify a path to a function that takes a user and checks permissions (falling back to is_authenticated).
If this is something you are looking into we'd be happy to accept a PR.
Thanks