Fixes permissions for assignments

- There were some fields that user could see/click/handle, although the user has not the correct permission for the action
This commit is contained in:
GabrielMeyer 2020-01-31 12:08:29 +01:00 committed by FinnStutzenstein
parent df1047fc76
commit 09b0d19de0
6 changed files with 57 additions and 40 deletions

View File

@ -108,7 +108,7 @@ export class PermsDirective implements OnInit, OnDestroy {
}
/**
* COmes from the view.
* Comes from the view.
*/
@Input('osPermsComplement')
public set osPermsComplement(value: boolean) {

View File

@ -68,11 +68,25 @@ export abstract class BasePoll<T = any, O extends BaseOption<any> = any> extends
return this.state === PollState.Published;
}
/**
* If the state is finished.
*/
public get isFinished(): boolean {
return this.state === PollState.Finished;
}
/**
* If the state is published.
*/
public get isPublished(): boolean {
return this.state === PollState.Published;
}
/**
* Determine if the state is finished or published
*/
public get stateHasVotes(): boolean {
return this.state === PollState.Finished || this.state === PollState.Published;
return this.isFinished || this.isPublished;
}
protected getDecimalFields(): (keyof BasePoll<T, O>)[] {

View File

@ -70,9 +70,7 @@
<!-- closed polls -->
<ng-container *ngIf="assignment">
<ng-container *ngFor="let poll of assignment.polls | reverse; trackBy: trackByIndex">
<mat-card class="os-card">
<os-assignment-poll [poll]="poll"> </os-assignment-poll>
</mat-card>
<os-assignment-poll [poll]="poll"> </os-assignment-poll>
</ng-container>
</ng-container>
</div>
@ -143,12 +141,12 @@
[input]="assignment.assignment_related_users"
[live]="true"
[count]="assignment.number_poll_candidates"
[enable]="hasPerms('addOthers')"
[enable]="hasPerms('manage')"
(sortEvent)="onSortingChange($event)"
>
<!-- implicit item references into the component using ng-template slot -->
<ng-template let-item>
<span *ngIf="hasPerms('addOthers')">
<span *ngIf="hasPerms('manage')">
<button
mat-icon-button
matTooltip="{{ 'Remove candidate' | translate }}"
@ -170,7 +168,6 @@
>
<mat-form-field>
<os-search-value-selector
class="search-bar"
formControlName="userId"
[multiple]="false"
placeholder="{{ 'Select a new candidate' | translate }}"

View File

@ -39,11 +39,8 @@
padding: 15px 25px 0 25px;
width: auto;
.search-bar {
display: grid;
.mat-form-field {
width: 100%;
}
.mat-form-field {
width: 100%;
}
}
}

View File

@ -1,45 +1,49 @@
<div class="assignment-poll-wrapper" *ngIf="poll">
<div class="">
</div>
<div class="poll-menu">
<!-- Buttons -->
<button
mat-icon-button
*osPerms="'assignments.can_manage'; &quot;core.can_manage_projector&quot;"
[matMenuTriggerFor]="pollItemMenu"
(click)="$event.stopPropagation()"
>
<mat-icon>more_horiz</mat-icon>
</button>
</div>
<div>
<div>
<h3>
<mat-card class="os-card" *ngIf="poll">
<div class="assignment-poll-wrapper">
<div class="assignment-poll-title-header">
<mat-card-title>
<a routerLink="/assignments/polls/{{ poll.id }}">
{{ poll.title }}
</a>
</h3>
</mat-card-title>
<div class="poll-properties">
<mat-chip
*osPerms="'assignments.can_manage'"
class="poll-state active"
[disableRipple]="true"
[matMenuTriggerFor]="triggerMenu"
[ngClass]="poll.stateVerbose.toLowerCase()"
>
{{ poll.stateVerbose }}
{{ poll.stateVerbose | translate }}
</mat-chip>
<mat-chip
*ngIf="!canManage && poll.isPublished"
[disableRipple]="true"
class="poll-state active"
[ngClass]="poll.stateVerbose.toLowerCase()"
>
{{ poll.stateVerbose | translate }}
</mat-chip>
</div>
<div class="poll-menu">
<!-- Buttons -->
<button
mat-icon-button
*osPerms="'assignments.can_manage'; &quot;core.can_manage_projector&quot;"
[matMenuTriggerFor]="pollItemMenu"
(click)="$event.stopPropagation()"
>
<mat-icon>more_horiz</mat-icon>
</button>
</div>
</div>
<div *ngIf="poll.stateHasVotes">
<div *ngIf="hasVotes">
<os-charts [type]="chartType" [labels]="candidatesLabels" [data]="chartDataSubject"></os-charts>
</div>
<os-assignment-poll-vote *ngIf="poll.canBeVotedFor" [poll]="poll"></os-assignment-poll-vote>
</div>
<os-assignment-poll-vote *ngIf="poll.canBeVotedFor" [poll]="poll"></os-assignment-poll-vote>
</div>
</mat-card>
<mat-menu #triggerMenu="matMenu">
<ng-container *ngIf="poll">

View File

@ -11,6 +11,7 @@ import { AssignmentPollRepositoryService } from 'app/core/repositories/assignmen
import { PromptService } from 'app/core/ui-services/prompt.service';
import { ChartType } from 'app/shared/components/charts/charts.component';
import { AssignmentPollMethods } from 'app/shared/models/assignments/assignment-poll';
import { PollState } from 'app/shared/models/poll/base-poll';
import { BasePollComponent } from 'app/site/polls/components/base-poll.component';
import { PollService } from 'app/site/polls/services/poll.service';
import { AssignmentPollDialogService } from '../../services/assignment-poll-dialog.service';
@ -67,6 +68,10 @@ export class AssignmentPollComponent extends BasePollComponent<ViewAssignmentPol
return this.operator.hasPerms('assignments.can_see');
}
public get hasVotes(): boolean {
return (this.canManage && this.poll.state === PollState.Finished) || this.poll.state === PollState.Published;
}
/**
* @returns true if the description on the form differs from the poll's description
*/