Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
DIGIPUS
Commits
8c8a0214
Commit
8c8a0214
authored
Oct 10, 2020
by
Muhammad Indra Ramadhan
Browse files
[
#98
] Material: Disable Comment for Unauthenticated
parent
658d59d5
Changes
3
Show whitespace changes
Inline
Side-by-side
app/templates/app/detail_materi.html
View file @
8c8a0214
...
...
@@ -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"
>
...
...
app/tests.py
View file @
8c8a0214
...
...
@@ -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
=
(
...
...
app/views.py
View file @
8c8a0214
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment