def test_cache(self): key = ('can_delete_comment', self.project.get_full_slug()) self.assertTrue(not hasattr(self.user, 'alc_permissions_cache')) self.assertFalse(can_delete_comment(self.user, self.project)) self.assertFalse(self.user.acl_permissions_cache[key]) self.user.acl_permissions_cache[key] = True self.assertTrue(can_delete_comment(self.user, self.project))
def test_cache(self): key = ('can_delete_comment', self.user.id) self.assertNotIn(key, self.project.permissions_cache) self.assertFalse(can_delete_comment(self.user, self.project)) self.assertFalse(self.project.permissions_cache[key]) self.project.permissions_cache[key] = True self.assertTrue(can_delete_comment(self.user, self.project))
def delete_comment(request, pk): """ Deletes comment. """ comment_obj = get_object_or_404(Comment, pk=pk) comment_obj.project.check_acl(request) if not can_delete_comment(request.user, comment_obj.project): raise PermissionDenied() units = get_related_units(comment_obj) if units.exists(): fallback_url = units[0].get_absolute_url() else: fallback_url = comment_obj.project.get_absolute_url() comment_obj.delete() messages.info(request, _('Translation comment has been deleted.')) return redirect(request.POST.get('next', fallback_url))
def test_delete_comment_user(self): self.assertFalse(can_delete_comment(self.user, self.project))
def test_delete_comment_owner(self): self.assertTrue(can_delete_comment(self.owner, self.project))