I’m using Class Based Views.
This is a class based view for comment delete where I use UserPassesTextMixing to prevent other uses to delete a comment. Only the author of the comment can delete the comment.
class CommentDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
# Requires model_confirm_delete.html template name
model = Comment
success_url = reverse_lazy('dicoms:patients_list')
def test_func(self):
obj = self.get_object()
return obj.author == self.request.user
def get_success_url(self):
return reverse_lazy('dicoms:dicom_detail', kwargs={'pk': self.object.dicom_file.id})
Is this a secure enough? Or is it ridiculously insecure?
I mean is using UserPassesTextMixing like this in class based views a secure way to control who can do what? Or is it ridiculously insecure?