mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-05 14:18:51 -05:00
commment permission
This commit is contained in:
@@ -164,11 +164,12 @@ class CommentUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
|
|
||||||
# TODO add msg box
|
# TODO add msg box
|
||||||
|
|
||||||
def get_object(self, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
obj = super(CommentUpdate, self).get_object(*args, **kwargs)
|
obj = self.get_object()
|
||||||
if not obj.created_by == self.request.user:
|
if not obj.created_by == request.user:
|
||||||
return obj # TODO move to dispatch or build custom exception
|
messages.add_message(request, messages.ERROR, _('You cannot edit this comment!'))
|
||||||
return obj
|
return HttpResponseRedirect(reverse('view_recipe', args=[obj.recipe.pk]))
|
||||||
|
return super(CommentUpdate, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse('edit_comment', kwargs={'pk': self.object.pk})
|
return reverse('edit_comment', kwargs={'pk': self.object.pk})
|
||||||
|
|||||||
Reference in New Issue
Block a user