Remove voted_id for ongoing polls

This commit is contained in:
Finn Stutzenstein 2021-02-26 12:48:55 +01:00
parent 45948c47fb
commit 93da435e7c
No known key found for this signature in database
GPG Key ID: 9042F605C6324654
5 changed files with 14 additions and 18 deletions

@ -1 +1 @@
Subproject commit fcbcfb8d68c083a7c9204548b0f0c1bb61ef49c0 Subproject commit b778a165491d503aa7e286c3859a4d601c827ddc

View File

@ -6,7 +6,7 @@ export abstract class BaseOption<T> extends BaseDecimalModel<T> {
public no: number; public no: number;
public abstain: number; public abstain: number;
public poll_id: number; public poll_id: number;
public voted_id: number[]; public votes_id: number[];
protected getDecimalFields(): string[] { protected getDecimalFields(): string[] {
return ['yes', 'no', 'abstain']; return ['yes', 'no', 'abstain'];

View File

@ -77,7 +77,7 @@ class BasePollAccessPermissions(BaseAccessPermissions):
Non-published polls will be restricted: Non-published polls will be restricted:
- Remove votes* values from the poll - Remove votes* values from the poll
- Remove yes/no/abstain fields from options - Remove yes/no/abstain fields from options
- Remove fields given in self.assitional_fields from the poll - Remove fields given in self.additional_fields from the poll
""" """
# add has_voted for all users to check whether op has voted # add has_voted for all users to check whether op has voted
@ -100,22 +100,23 @@ class BasePollAccessPermissions(BaseAccessPermissions):
) )
poll["user_has_voted_for_delegations"] = voted_for_delegations poll["user_has_voted_for_delegations"] = voted_for_delegations
data_copy = json.loads(json.dumps(full_data))
for poll in data_copy:
if poll["state"] not in (BasePoll.STATE_FINISHED, BasePoll.STATE_PUBLISHED):
del poll["voted_id"]
if await async_has_perm(user_id, self.manage_permission): if await async_has_perm(user_id, self.manage_permission):
data = full_data pass
elif await async_has_perm(user_id, self.base_permission): elif await async_has_perm(user_id, self.base_permission):
data = [] for poll in data_copy:
for poll in full_data:
if poll["state"] != BasePoll.STATE_PUBLISHED: if poll["state"] != BasePoll.STATE_PUBLISHED:
poll = json.loads(
json.dumps(poll)
) # copy, so we can remove some fields.
del poll["votesvalid"] del poll["votesvalid"]
del poll["votesinvalid"] del poll["votesinvalid"]
del poll["votescast"] del poll["votescast"]
del poll["voted_id"] if "voted_id" in poll: # could be removed earlier
del poll["voted_id"]
for field in self.additional_fields: for field in self.additional_fields:
del poll[field] del poll[field]
data.append(poll)
else: else:
data = [] data_copy = []
return data return data_copy

View File

@ -2733,7 +2733,6 @@ class VoteAssignmentPollNamedAutoupdates(VoteAssignmentPollAutoupdatesBaseClass)
"votesvalid": "1.000000", "votesvalid": "1.000000",
"user_has_voted": False, "user_has_voted": False,
"user_has_voted_for_delegations": [], "user_has_voted_for_delegations": [],
"voted_id": [self.user.id],
}, },
"assignments/assignment-option:1": { "assignments/assignment-option:1": {
"abstain": "1.000000", "abstain": "1.000000",
@ -2926,7 +2925,6 @@ class VoteAssignmentPollPseudoanonymousAutoupdates(
"type": AssignmentPoll.TYPE_PSEUDOANONYMOUS, "type": AssignmentPoll.TYPE_PSEUDOANONYMOUS,
"user_has_voted": False, "user_has_voted": False,
"user_has_voted_for_delegations": [], "user_has_voted_for_delegations": [],
"voted_id": [self.user.id],
"onehundred_percent_base": AssignmentPoll.PERCENT_BASE_CAST, "onehundred_percent_base": AssignmentPoll.PERCENT_BASE_CAST,
"majority_method": AssignmentPoll.MAJORITY_TWO_THIRDS, "majority_method": AssignmentPoll.MAJORITY_TWO_THIRDS,
"min_votes_amount": 1, "min_votes_amount": 1,

View File

@ -165,7 +165,6 @@ class CreateMotionPoll(TestCase):
"votescast": "0.000000", "votescast": "0.000000",
"options_id": [1], "options_id": [1],
"id": 1, "id": 1,
"voted_id": [],
"user_has_voted": False, "user_has_voted": False,
"user_has_voted_for_delegations": [], "user_has_voted_for_delegations": [],
}, },
@ -1081,7 +1080,6 @@ class VoteMotionPollNamedAutoupdates(TestCase):
"id": 1, "id": 1,
"user_has_voted": False, "user_has_voted": False,
"user_has_voted_for_delegations": [], "user_has_voted_for_delegations": [],
"voted_id": [self.user.id],
}, },
"motions/motion-vote:1": { "motions/motion-vote:1": {
"pollstate": 2, "pollstate": 2,
@ -1224,7 +1222,6 @@ class VoteMotionPollPseudoanonymousAutoupdates(TestCase):
"id": 1, "id": 1,
"user_has_voted": False, "user_has_voted": False,
"user_has_voted_for_delegations": [], "user_has_voted_for_delegations": [],
"voted_id": [self.user.id],
}, },
"motions/motion-vote:1": { "motions/motion-vote:1": {
"pollstate": 2, "pollstate": 2,