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') @Input('osPermsComplement')
public set osPermsComplement(value: boolean) { 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; 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 * Determine if the state is finished or published
*/ */
public get stateHasVotes(): boolean { public get stateHasVotes(): boolean {
return this.state === PollState.Finished || this.state === PollState.Published; return this.isFinished || this.isPublished;
} }
protected getDecimalFields(): (keyof BasePoll<T, O>)[] { protected getDecimalFields(): (keyof BasePoll<T, O>)[] {

View File

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

View File

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

View File

@ -1,45 +1,49 @@
<div class="assignment-poll-wrapper" *ngIf="poll"> <mat-card class="os-card" *ngIf="poll">
<div class="assignment-poll-wrapper">
<div class=""> <div class="assignment-poll-title-header">
<mat-card-title>
</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>
<a routerLink="/assignments/polls/{{ poll.id }}"> <a routerLink="/assignments/polls/{{ poll.id }}">
{{ poll.title }} {{ poll.title }}
</a> </a>
</h3> </mat-card-title>
<div class="poll-properties"> <div class="poll-properties">
<mat-chip <mat-chip
*osPerms="'assignments.can_manage'"
class="poll-state active" class="poll-state active"
[disableRipple]="true"
[matMenuTriggerFor]="triggerMenu" [matMenuTriggerFor]="triggerMenu"
[ngClass]="poll.stateVerbose.toLowerCase()" [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> </mat-chip>
</div> </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>
<div *ngIf="poll.stateHasVotes">
<div *ngIf="hasVotes">
<os-charts [type]="chartType" [labels]="candidatesLabels" [data]="chartDataSubject"></os-charts> <os-charts [type]="chartType" [labels]="candidatesLabels" [data]="chartDataSubject"></os-charts>
</div> </div>
<os-assignment-poll-vote *ngIf="poll.canBeVotedFor" [poll]="poll"></os-assignment-poll-vote>
</div> </div>
<os-assignment-poll-vote *ngIf="poll.canBeVotedFor" [poll]="poll"></os-assignment-poll-vote> </mat-card>
</div>
<mat-menu #triggerMenu="matMenu"> <mat-menu #triggerMenu="matMenu">
<ng-container *ngIf="poll"> <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 { PromptService } from 'app/core/ui-services/prompt.service';
import { ChartType } from 'app/shared/components/charts/charts.component'; import { ChartType } from 'app/shared/components/charts/charts.component';
import { AssignmentPollMethods } from 'app/shared/models/assignments/assignment-poll'; 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 { BasePollComponent } from 'app/site/polls/components/base-poll.component';
import { PollService } from 'app/site/polls/services/poll.service'; import { PollService } from 'app/site/polls/services/poll.service';
import { AssignmentPollDialogService } from '../../services/assignment-poll-dialog.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'); 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 * @returns true if the description on the form differs from the poll's description
*/ */