Skip to content

Commit

Permalink
feat(context): read only context can revoke permission if the context…
Browse files Browse the repository at this point in the history
… is shared directly
  • Loading branch information
mbarbeau committed Jul 3, 2020
1 parent e5600d6 commit 95e7c5b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ export class ContextItemComponent {
}

get canShare(): boolean {
return (
this.storageService.get('canShare') === true &&
this.context.permission === this.typePermission[this.typePermission.write]
);
return this.storageService.get('canShare') === true;
}

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class ContextPermissionsBindingDirective implements OnInit, OnDestroy {

ngOnDestroy() {
this.editedContext$$.unsubscribe();
this.contextService.editedContext$.next(undefined);
}

private handleEditedContextChange(context: DetailedContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<div *ngIf="context">

<div class="scopeForm">
<div *ngIf="!canWrite" class="scopeForm">
<h4>{{ 'igo.context.permission.readOnlyTitle' | translate }}</h4>
<p>{{ 'igo.context.permission.readOnlyMsg' | translate }}</p>
</div>

<div *ngIf="canWrite" class="scopeForm">
<mat-radio-group [(ngModel)]="context.scope"
(change)="scopeChanged.emit(context)">
<mat-radio-button value="private">
Expand All @@ -15,7 +20,7 @@
</mat-radio-group>
</div>

<form *ngIf="context.scope !== 'private'" [formGroup]="form"
<form *ngIf="context.scope !== 'private' && canWrite" [formGroup]="form"
(ngSubmit)="handleFormSubmit(form.value)">

<mat-form-field class="full-width">
Expand Down Expand Up @@ -66,12 +71,12 @@
<ng-template ngFor let-permission [ngForOf]="groupPermissions.value">
<mat-list-item>
<mat-icon mat-list-avatar svgIcon="account-outline"></mat-icon>
<h4 mat-line>{{permission.profil}}</h4>
<h4 mat-line>{{permission.profilTitle}} <small class="mat-typography">{{permission.profil}}</small></h4>

<div igoStopPropagation
class="igo-actions-container">

<button
<button *ngIf="canWrite || permission.profil === authService.decodeToken().user.sourceId"
mat-icon-button
[matTooltip]="'igo.context.permission.delete' | translate"
matTooltipShowDelay="500"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
ContextPermissionsList,
ContextProfils
} from '../shared/context.interface';
import { TypePermission } from '../shared/context.enum';

import { HttpClient } from '@angular/common/http';
import { Subscription } from 'rxjs';

Expand Down Expand Up @@ -49,6 +51,10 @@ export class ContextPermissionsComponent implements OnInit {
}
private _profils: ContextProfils[] = [];

get canWrite(): boolean {
return this.context.permission === TypePermission[TypePermission.write];
}

private baseUrlProfils = '/apis/igo2/profils-users?';

public formControl = new FormControl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ContextPermission {
id?: string;
contextId?: string;
profil: string;
profilTitle?: string;
typePermission: TypePermission;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/context/src/locale/en.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"user": "User or group",
"profilRequired": "Profil required",
"read": "Read only",
"readOnlyTitle": "Read-only context",
"readOnlyMsg": "You can only revoke permission if the context is shared directly to your username.",
"scope": {
"private": "Private",
"protected": "Protected",
Expand Down
2 changes: 2 additions & 0 deletions packages/context/src/locale/fr.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"user": "Utilisateur ou groupe",
"profilRequired": "Le profil est obligatoire",
"read": "Lecture seule",
"readOnlyTitle": "Contexte en lecture seule",
"readOnlyMsg": "Vous pouvez seulement retirer la permission si le contexte est directement partagé à votre nom d'utilisateur.",
"scope": {
"private": "Privé",
"protected": "Protégé",
Expand Down

0 comments on commit 95e7c5b

Please sign in to comment.