Skip to content

Commit

Permalink
Merge branch 'main' into issue-OWASP-BLT#1315
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT authored Nov 20, 2023
2 parents d94966e + aac5251 commit 3e1f4d8
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 43 deletions.
4 changes: 3 additions & 1 deletion blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@
re_path(
r"^like_issue/(?P<issue_pk>\d+)/$", website.views.like_issue, name="like_issue"
),
re_path(
r"^dislike_issue/(?P<issue_pk>\d+)/$", website.views.dislike_issue, name="dislike_issue"
),
re_path(
r"^flag_issue/(?P<issue_pk>\d+)/$", website.views.flag_issue, name="flag_issue"
),

re_path(
r"^like_issue2/(?P<issue_pk>\d+)/$", like_issue2, name="like_issue2"
),
Expand Down
20 changes: 20 additions & 0 deletions website/migrations/0081_userprofile_issue_downvoted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.7 on 2023-11-17 09:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("website", "0080_alter_issue_team_members"),
]

operations = [
migrations.AddField(
model_name="userprofile",
name="issue_downvoted",
field=models.ManyToManyField(
blank=True, related_name="downvoted", to="website.issue"
),
),
]
1 change: 1 addition & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class UserProfile(models.Model):
max_digits=10, decimal_places=2, null=True, blank=True
)
issue_upvoted = models.ManyToManyField(Issue, blank=True, related_name="upvoted")
issue_downvoted = models.ManyToManyField(Issue, blank=True, related_name="downvoted")
issue_saved = models.ManyToManyField(Issue, blank=True, related_name="saved")
issue_flaged = models.ManyToManyField(Issue,blank=True,related_name="flaged")
issues_hidden = models.BooleanField(default=False)
Expand Down
4 changes: 2 additions & 2 deletions website/templates/_flags.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

{% if request.user.is_authenticated %}
<a class="btn btn-info btn-xs flag_unflag" name="{{ object.pk }}">
<i class="fa fa-thumbs-down"></i> Flag {{ flags }}
<i class="fa fa-flag"></i> Flag {{ flags }}
</a>
{% else %}
<button class="btn btn-info btn-xs flag_unflag" disabled>
<i class="fa fa-thumbs-down"></i> Flag {{ flags }}
<i class="fa fa-flag"></i> Flag {{ flags }}
</button>
{% endif %}

Expand Down
35 changes: 0 additions & 35 deletions website/templates/_likes.html

This file was deleted.

70 changes: 70 additions & 0 deletions website/templates/_likes_and_dislikes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% load gravatar %}

{% if request.user.is_authenticated %}
<a class="btn btn-info btn-xs like_unlike" name="{{ object.pk }}">
<i class="fa fa-thumbs-up"></i> {{ likes }}
</a>
{% else %}
<button class="btn btn-info btn-xs" disabled>
<i class="fa fa-thumbs-up"></i> {{ likes }}
</button>
{% endif %}

{% if likers %}
<a href="#likedBy" class="btn btn-xs btn-default liked-by" data-toggle="modal">Liked By</a>
{% endif %}

<div id="likedBy" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h3>Liked by:</h3>
{% for usr in likers %}
<div class="list-group-item">
{% if usr.user.socialaccount_set.all.0.get_avatar_url %}
<img src="{{ usr.user.socialaccount_set.all.0.get_avatar_url }}" height="50px">
{% else %}
<img src="{% gravatar_url usr.user.email 50 %}">
{% endif %}
<a href="/profile/{{ usr.user.username }}">{{ usr.user.username }}</a>
</div>
{% endfor %}
</div>
</div>
</div>
</div>


{% if request.user.is_authenticated %}
<a class="btn btn-info btn-xs dislike_undislike" name="{{ object.pk }}">
<i class="fa fa-thumbs-down"></i> {{ dislikes }}
</a>
{% else %}
<button class="btn btn-info btn-xs" disabled>
<i class="fa fa-thumbs-down"></i> {{ dislikes }}
</button>
{% endif %}

{% if dislikers %}
<a href="#dislikedBy" class="btn btn-xs btn-default disliked-by" data-toggle="modal">Disliked By</a>
{% endif %}

<div id="dislikedBy" class="modal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h3>Disliked by:</h3>
{% for usr in dislikers %}
<div class="list-group-item">
{% if usr.user.socialaccount_set.all.0.get_avatar_url %}
<img src="{{ usr.user.socialaccount_set.all.0.get_avatar_url }}" height="50px">
{% else %}
<img src="{% gravatar_url usr.user.email 50 %}">
{% endif %}
<a href="/profile/{{ usr.user.username }}">{{ usr.user.username }}</a>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
22 changes: 18 additions & 4 deletions website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
.bookmark,
.copy-btn,
.flag_btn a.flaged-by,
.like_btn a.liked-by {
.like_btn a.liked-by,
.dislike_btn a.disliked-by {
vertical-align: top;
}

Expand Down Expand Up @@ -183,8 +184,8 @@ <h3 class="page-header">
<i class="glyphicon glyphicon-copy"></i> Copy Title
</button>

<span class="like_btn">
{% include '_likes.html' %}
<span class="like_dislike_buttons">
{% include '_likes_and_dislikes.html' %}
</span>
<span class="flag_btn">
{% include '_flags.html' %}
Expand Down Expand Up @@ -544,7 +545,20 @@ <h3>Comments:</h3>
url: '/like_issue/' + issue_pk + '/',
data: {},
success: function (data) {
$('.like_btn').html(data);
$('.like_dislike_buttons').html(data);
},
});
});

$('body').on('click', '.dislike_undislike', function (e) {
e.preventDefault();
var issue_pk = $(this).attr('name');
$.ajax({
type: 'GET',
url: '/dislike_issue/' + issue_pk + '/',
data: {},
success: function (data) {
$('.like_dislike_buttons').html(data);
},
});
});
Expand Down
38 changes: 37 additions & 1 deletion website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ def get_context_data(self, **kwargs):
context["all_users"] = User.objects.all()
context["likes"] = UserProfile.objects.filter(issue_upvoted=self.object).count()
context["likers"] = UserProfile.objects.filter(issue_upvoted=self.object)
context["dislikes"] = UserProfile.objects.filter(issue_downvoted=self.object).count()
context["dislikers"] = UserProfile.objects.filter(issue_downvoted=self.object)

context["flags"] = UserProfile.objects.filter(issue_flaged=self.object).count()
context["flagers"] = UserProfile.objects.filter(issue_flaged=self.object)
Expand Down Expand Up @@ -1906,6 +1908,10 @@ def like_issue(request, issue_pk):
issue_pk = int(issue_pk)
issue = Issue.objects.get(pk=issue_pk)
userprof = UserProfile.objects.get(user=request.user)

if userprof in UserProfile.objects.filter(issue_downvoted=issue):
userprof.issue_downvoted.remove(issue)

if userprof in UserProfile.objects.filter(issue_upvoted=issue):
userprof.issue_upvoted.remove(issue)
else:
Expand Down Expand Up @@ -1942,7 +1948,37 @@ def like_issue(request, issue_pk):
total_votes = UserProfile.objects.filter(issue_upvoted=issue).count()
context["object"] = issue
context["likes"] = total_votes
return render(request, "_likes.html", context)
context["likers"] = UserProfile.objects.filter(issue_upvoted=issue)
context["dislikes"] = UserProfile.objects.filter(issue_downvoted=issue).count()
context["dislikers"] = UserProfile.objects.filter(issue_downvoted=issue)

return render(request, "_likes_and_dislikes.html", context)


@login_required(login_url="/accounts/login")
def dislike_issue(request, issue_pk):
context = {}
issue_pk = int(issue_pk)
issue = Issue.objects.get(pk=issue_pk)
userprof = UserProfile.objects.get(user=request.user)

if userprof in UserProfile.objects.filter(issue_upvoted=issue):
userprof.issue_upvoted.remove(issue)

if userprof in UserProfile.objects.filter(issue_downvoted=issue):
userprof.issue_downvoted.remove(issue)
else:
userprof.issue_downvoted.add(issue)

userprof.save()
total_downvotes = UserProfile.objects.filter(issue_downvoted=issue).count()
context["object"] = issue
context["likes"] = UserProfile.objects.filter(issue_upvoted=issue).count()
context["likers"] = UserProfile.objects.filter(issue_upvoted=issue)
context["dislikes"] = total_downvotes
context["dislikers"] = UserProfile.objects.filter(issue_downvoted=issue)

return render(request, "_likes_and_dislikes.html", context)


@login_required(login_url="/accounts/login")
Expand Down

0 comments on commit 3e1f4d8

Please sign in to comment.