Merge pull request #6031 from jsangmeister/fix-entitled-users

Fix entitled user calculation and display of voting banner in case of vote delegations
This commit is contained in:
Emanuel Schütze 2021-04-29 15:38:49 +02:00 committed by GitHub
commit d86fcd80b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 5 deletions

View File

@ -7,8 +7,10 @@ import { ViewAssignmentPoll } from 'app/site/assignments/models/view-assignment-
import { ViewMotionPoll } from 'app/site/motions/models/view-motion-poll'; import { ViewMotionPoll } from 'app/site/motions/models/view-motion-poll';
import { ViewBasePoll } from 'app/site/polls/models/view-base-poll'; import { ViewBasePoll } from 'app/site/polls/models/view-base-poll';
import { PollListObservableService } from 'app/site/polls/services/poll-list-observable.service'; import { PollListObservableService } from 'app/site/polls/services/poll-list-observable.service';
import { ViewUser } from 'app/site/users/models/view-user';
import { BannerDefinition, BannerService } from './banner.service'; import { BannerDefinition, BannerService } from './banner.service';
import { OpenSlidesStatusService } from '../core-services/openslides-status.service'; import { OpenSlidesStatusService } from '../core-services/openslides-status.service';
import { OperatorService } from '../core-services/operator.service';
import { VotingService } from './voting.service'; import { VotingService } from './voting.service';
@Injectable({ @Injectable({
@ -19,23 +21,46 @@ export class VotingBannerService {
private subText = _('Click here to vote!'); private subText = _('Click here to vote!');
private polls: ViewBasePoll[];
private delegations: ViewUser[];
public constructor( public constructor(
pollListObservableService: PollListObservableService, pollListObservableService: PollListObservableService,
private banner: BannerService, private banner: BannerService,
private translate: TranslateService, private translate: TranslateService,
private OSStatus: OpenSlidesStatusService, private OSStatus: OpenSlidesStatusService,
private votingService: VotingService private votingService: VotingService,
private operator: OperatorService
) { ) {
pollListObservableService.getViewModelListObservable().subscribe(polls => this.checkForVotablePolls(polls)); pollListObservableService.getViewModelListObservable().subscribe(polls => {
this.polls = polls;
this.checkForVotablePolls();
});
operator.getViewUserObservable().subscribe(user => {
if (user) {
this.delegations = user.voteDelegationsFrom;
this.checkForVotablePolls();
}
});
} }
/** /**
* checks all polls for votable ones and displays a banner for them * checks all polls for votable ones and displays a banner for them
* @param polls the updated poll list * @param polls the updated poll list
*/ */
private checkForVotablePolls(polls: ViewBasePoll[]): void { private checkForVotablePolls(): void {
// display no banner if in history mode or there are no polls to vote // display no banner if in history mode or there are no polls to vote
const pollsToVote = polls.filter(poll => this.votingService.canVote(poll) && !poll.user_has_voted); const pollsToVote = this.polls.filter(poll => {
if (this.votingService.canVote(poll) && !poll.user_has_voted) {
return true;
}
for (const delegation of this.delegations) {
if (this.votingService.canVote(poll, delegation) && !poll.hasVotedId(delegation.id)) {
return true;
}
}
});
if ((this.OSStatus.isInHistoryMode && this.currentBanner) || !pollsToVote.length) { if ((this.OSStatus.isInHistoryMode && this.currentBanner) || !pollsToVote.length) {
this.sliceBanner(); this.sliceBanner();
return; return;

View File

@ -278,7 +278,10 @@ class BasePoll(models.Model):
entitled_users_ids = set() entitled_users_ids = set()
for group in self.groups.all(): for group in self.groups.all():
for user in group.user_set.all(): for user in group.user_set.all():
if user.is_present and user.id not in entitled_users_ids: if (
user.is_present
or (user.vote_delegated_to and user.vote_delegated_to.is_present)
) and user.id not in entitled_users_ids:
entitled_users_ids.add(user.id) entitled_users_ids.add(user.id)
entitled_users.append( entitled_users.append(
{ {

View File

@ -1193,6 +1193,9 @@ class StopMotionPoll(TestCase):
def test_stop_poll_with_entitled_users_and_vote_delegation(self): def test_stop_poll_with_entitled_users_and_vote_delegation(self):
self.setup_entitled_users() self.setup_entitled_users()
user, _ = self.create_user() user, _ = self.create_user()
user.is_present = True
user.save()
self.admin.is_present = False
self.admin.vote_delegated_to = user self.admin.vote_delegated_to = user
self.admin.save() self.admin.save()
response = self.client.post(reverse("motionpoll-stop", args=[self.poll.pk])) response = self.client.post(reverse("motionpoll-stop", args=[self.poll.pk]))