Merge pull request #5761 from jwinzer/poll-progress-users

Fix user filter of poll progress
This commit is contained in:
Emanuel Schütze 2020-12-13 20:52:50 +01:00 committed by GitHub
commit 0a80a73f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 11 deletions

View File

@ -1,4 +1,4 @@
<div class="poll-progress-wrapper">
<div class="poll-progress-wrapper" *ngIf="canSeeProgressBar">
<div class="vote-number">
<span>{{ votescast }} / {{ max }}</span>
</div>

View File

@ -5,9 +5,10 @@ import { Title } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core';
import { map } from 'rxjs/operators';
import { OperatorService } from 'app/core/core-services/operator.service';
import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service';
import { BaseViewComponentDirective } from 'app/site/base/base-view';
import { ViewBasePoll } from 'app/site/polls/models/view-base-poll';
import { PollClassType, ViewBasePoll } from 'app/site/polls/models/view-base-poll';
@Component({
selector: 'os-poll-progress',
@ -23,11 +24,22 @@ export class PollProgressComponent extends BaseViewComponentDirective implements
return this.poll?.votescast || 0;
}
public get canSeeProgressBar(): boolean {
let canManage = false;
if (this.poll?.pollClassType === PollClassType.Motion) {
canManage = this.operator.hasPerms(this.permission.motionsCanManagePolls);
} else if (this.poll?.pollClassType === PollClassType.Assignment) {
canManage = this.operator.hasPerms(this.permission.assignmentsCanManage);
}
return canManage && this.operator.hasPerms(this.permission.usersCanSeeName);
}
public constructor(
title: Title,
protected translate: TranslateService,
snackbar: MatSnackBar,
private userRepo: UserRepositoryService
private userRepo: UserRepositoryService,
private operator: OperatorService
) {
super(title, translate, snackbar);
}
@ -41,12 +53,14 @@ export class PollProgressComponent extends BaseViewComponentDirective implements
map(users =>
/**
* Filter the users who would be able to vote:
* They are present or have their right to vote delegated
* They are present and don't have their vote right delegated
* or the have their vote delegated to a user who is present.
* They are in one of the voting groups
*/
users.filter(
user =>
(user.is_present || user.isVoteRightDelegated) &&
((user.is_present && !user.isVoteRightDelegated) ||
user.voteDelegatedTo?.is_present) &&
this.poll.groups_id.intersect(user.groups_id).length
)
)

View File

@ -63,16 +63,27 @@ class UserAccessPermissions(BaseAccessPermissions):
# Check user permissions.
if await async_has_perm(user_id, "users.can_see_name"):
whitelist_operator = None
if await async_has_perm(user_id, "users.can_see_extra_data"):
if await async_has_perm(user_id, "users.can_manage"):
data = [filtered_data(full, all_data_fields) for full in full_data]
whitelist = all_data_fields
else:
data = [filtered_data(full, many_data_fields) for full in full_data]
whitelist = many_data_fields
else:
data = [
filtered_data(full, little_data_fields, own_data_fields)
for full in full_data
]
whitelist = little_data_fields
whitelist_operator = own_data_fields
# for managing {motion, assignment} polls the users needs to know
# the vote delegation structure.
if await async_has_perm(
user_id, "motion.can_manage_polls"
) or await async_has_perm(user_id, "assignments.can_manage"):
whitelist.add("vote_delegated_to_id")
whitelist.add("vote_delegated_from_users_id")
data = [
filtered_data(full, whitelist, whitelist_operator) for full in full_data
]
else:
# Build a list of users, that can be seen without any permissions (with little fields).