Fakultas Ilmu Komputer UI

Commit 8c8a0214 authored by Muhammad Indra Ramadhan's avatar Muhammad Indra Ramadhan
Browse files

[#98] Material: Disable Comment for Unauthenticated

parent 658d59d5
......@@ -260,6 +260,7 @@
</div>
{% if materi_data.status == "APPROVE" %}
<div id="komentar" class="container-fluid comments-wrapper p-0">
{% if is_authenticated %}
<div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
<form method="POST">
{% csrf_token %}
......@@ -272,6 +273,9 @@
</div>
</form>
</div>
{% else %}
<h3>Login terlebih dahulu untuk berkomentar</h3>
{% endif %}
{% for comment in comment_data %}
<div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
<div class="d-flex bd-highlight mb-3 align-items-center user">
......
......@@ -323,10 +323,17 @@ class DetailMateriTest(TestCase):
self.assertContains(response, "Anonymous")
def test_detail_materi_contains_form_comment(self):
self.client.login(**self.contributor_credential)
response = self.client.get(self.url)
self.assertContains(response, "Beri komentar...")
def test_detail_materi_not_contains_form_comment(self):
response = self.client.get(self.url)
self.assertNotContains(response, "Beri komentar...")
self.assertContains(response, "Login terlebih dahulu untuk berkomentar")
def test_delete_comments_by_admin(self):
self.client.login(**self.contributor_credential)
url = self.url
self.client.post(url, {"comment": "This is new comment by Anonymous"})
deleteURL = (
......
......@@ -157,7 +157,9 @@ class DetailMateri(TemplateView):
if self.request.user.is_authenticated:
materi_rating = Rating.objects.filter(materi=materi, user=self.request.user).first()
if materi_rating is not None:
context["materi_rating_score"] = materi_rating.score
context['materi_rating_score'] = materi_rating.score
context['is_authenticated'] = self.request.user.is_authenticated
return context
......@@ -189,6 +191,7 @@ class DetailMateri(TemplateView):
materi = get_object_or_404(Materi, pk=kwargs["pk"])
user_obj = request.user if request.user.is_authenticated else None
if user_obj:
comment = Comment.objects.create(
comment=commentText, username=self.get_user_name(request), materi=materi, user=user_obj
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment