From b2a41d3bf67ce46f712ed0b57007de50be2cf49c Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:02:29 +0530 Subject: [PATCH] fix: issue votes (#2006) * fix: issue votes * fix: added default as 1 in vote * fix: issue vote migration file --- apiserver/plane/api/views/issue.py | 3 ++- ..._together_alter_issuevote_vote_and_more.py | 26 +++++++++++++++++++ apiserver/plane/db/models/issue.py | 6 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 apiserver/plane/db/migrations/0042_alter_issuevote_unique_together_alter_issuevote_vote_and_more.py diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 616cef0d6..05434aec5 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -1822,8 +1822,9 @@ class IssueVotePublicViewSet(BaseViewSet): actor_id=request.user.id, project_id=project_id, issue_id=issue_id, - vote=request.data.get("vote", 1), ) + issue_vote.vote = request.data.get("vote", 1) + issue_vote.save() serializer = IssueVoteSerializer(issue_vote) return Response(serializer.data, status=status.HTTP_201_CREATED) except Exception as e: diff --git a/apiserver/plane/db/migrations/0042_alter_issuevote_unique_together_alter_issuevote_vote_and_more.py b/apiserver/plane/db/migrations/0042_alter_issuevote_unique_together_alter_issuevote_vote_and_more.py new file mode 100644 index 000000000..d8063acc0 --- /dev/null +++ b/apiserver/plane/db/migrations/0042_alter_issuevote_unique_together_alter_issuevote_vote_and_more.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.3 on 2023-08-29 07:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0041_cycle_sort_order_issuecomment_access_and_more'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='issuevote', + unique_together=set(), + ), + migrations.AlterField( + model_name='issuevote', + name='vote', + field=models.IntegerField(choices=[(-1, 'DOWNVOTE'), (1, 'UPVOTE')], default=1), + ), + migrations.AlterUniqueTogether( + name='issuevote', + unique_together={('issue', 'actor', 'vote')}, + ), + ] diff --git a/apiserver/plane/db/models/issue.py b/apiserver/plane/db/models/issue.py index 7af9e6e14..1633cbaf9 100644 --- a/apiserver/plane/db/models/issue.py +++ b/apiserver/plane/db/models/issue.py @@ -476,10 +476,12 @@ class IssueVote(ProjectBaseModel): choices=( (-1, "DOWNVOTE"), (1, "UPVOTE"), - ) + ), + default=1, ) + class Meta: - unique_together = ["issue", "actor"] + unique_together = ["issue", "actor", "vote"] verbose_name = "Issue Vote" verbose_name_plural = "Issue Votes" db_table = "issue_votes"