feat: add Decision column to TUVote

In preparation for allowing TUs to change their votes on proposals,
we need a way to track what users vote for.

Without this, the vote decisions are stored within the related
TU_VoteInfo record, decoupled from the user who made the vote.

That being the case meant we cannot actually change a vote, because
we can't figure out what TU_VoteInfo decision columns to decrement
when the vote has changed.

You may be wondering why we aren't removing the decision columns out
of TU_VoteInfo with the advent of this new column. The reason being:
previous votes are all calculated off of the TU_VoteInfo columns, so
without a manual DB rework, relocating them to the user-related vote
records would break outcomes of old proposals. So, the plan is:
we'll solely use this column for votes from this point on to track
what decision a user made internally, which will open up TUs changing
their decision.

In addition, this migration resets all running proposals:
- all votes are deleted
- time is reset to Start when migration is run

This was necessary to put running proposals into a state that can
take advantage of the new revote system.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-03-07 18:16:41 -08:00
parent c7c79a152b
commit a29701459c
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
4 changed files with 95 additions and 4 deletions

View file

@ -4,7 +4,7 @@ from sqlalchemy.exc import IntegrityError
from aurweb import db, time
from aurweb.models.account_type import TRUSTED_USER_ID
from aurweb.models.tu_vote import TUVote
from aurweb.models.tu_vote import YES_ID, TUVote
from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
@ -36,10 +36,12 @@ def tu_voteinfo(user: User) -> TUVoteInfo:
def test_tu_vote_creation(user: User, tu_voteinfo: TUVoteInfo):
with db.begin():
tu_vote = db.create(TUVote, User=user, VoteInfo=tu_voteinfo)
tu_vote = db.create(TUVote, User=user, VoteInfo=tu_voteinfo,
Decision=YES_ID)
assert tu_vote.VoteInfo == tu_voteinfo
assert tu_vote.User == user
assert tu_vote.Decision == YES_ID
assert tu_vote in user.tu_votes
assert tu_vote in tu_voteinfo.tu_votes
@ -52,3 +54,12 @@ def test_tu_vote_null_user_raises_exception(tu_voteinfo: TUVoteInfo):
def test_tu_vote_null_voteinfo_raises_exception(user: User):
with pytest.raises(IntegrityError):
TUVote(User=user)
def test_tu_vote_bad_decision_raises_exception(user: User,
tu_voteinfo: TUVoteInfo):
with pytest.raises(IntegrityError):
TUVote(User=user, VoteInfo=tu_voteinfo, Decision=None)
with pytest.raises(IntegrityError):
TUVote(User=user, VoteInfo=tu_voteinfo, Decision=0)