Skip to content

Commit

Permalink
Merge pull request #608 from LINCnil/feature/update-pia-edit-with-role
Browse files Browse the repository at this point in the history
Feature/update pia edit with role
  • Loading branch information
kevin-atnos authored Nov 8, 2021
2 parents ce3e9ef + daae0a0 commit 97d6030
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/app/models/pia.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class Pia {
public structure_data: { sections: any };
public created_at: Date;
public updated_at: Date;
public user_pias: Array<{ user: User; role: string }>;

constructor() {
this.created_at = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
</ng-container>
</ul>
</div>
<div class="pia-cardsBlock-toolbar">
<div
class="pia-cardsBlock-toolbar"
*ngIf="
!authService.state ||
authService.currentUserValue.access_type.includes('technical') ||
authService.currentUserValue.access_type.includes('functional')
"
>
<div class="pia-cardsBlock-toolbar-export">
<a
*ngIf="!pia.is_example"
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/entries/cards/pia-card/pia-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ export class PiaCardComponent implements OnInit, OnChanges {

checkIfUserExist(field): boolean {
return (
this.users.findIndex(
this.pia.user_pias.findIndex(
u =>
u.firstname + ' ' + u.lastname ===
u.user.firstname + ' ' + u.user.lastname ===
this.piaForm.controls[field].value[0].display
) !== -1
);
Expand Down
66 changes: 37 additions & 29 deletions src/app/modules/entries/list/pia-line/pia-line.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,46 @@
>{{ "homepage.lists.item.tools.consult" | translate }}</span
>
</a>
<a
href="javascript:;"
(click)="onDuplicate(pia.id)"
class="btn pia-tooltip"
<ng-container
*ngIf="
!authService.state ||
authService.currentUserValue.access_type.includes('technical') ||
authService.currentUserValue.access_type.includes('functional')
"
>
<i class="fa fa-files-o" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.duplicate' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.duplicate" | translate }}</span
<a
href="javascript:;"
(click)="onDuplicate(pia.id)"
class="btn pia-tooltip"
>
</a>
<a href="javascript:;" (click)="generateZip()" class="btn pia-tooltip">
<i class="fa fa-download" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.export' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.export" | translate }}</span
>
</a>
<a
href="javascript:;"
(click)="archivePia(pia.id)"
class="btn pia-tooltip"
>
<i class="fa fa-archive" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.archive' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.archive" | translate }}</span
<i class="fa fa-files-o" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.duplicate' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.duplicate" | translate }}</span
>
</a>
<a href="javascript:;" (click)="generateZip()" class="btn pia-tooltip">
<i class="fa fa-download" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.export' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.export" | translate }}</span
>
</a>
<a
href="javascript:;"
(click)="archivePia(pia.id)"
class="btn pia-tooltip"
>
</a>
<i class="fa fa-archive" aria-hidden="true"></i>
<span
title="{{ 'homepage.lists.item.tools.archive' | translate }}"
class="pia-tooltip-text"
>{{ "homepage.lists.item.tools.archive" | translate }}</span
>
</a>
</ng-container>
</div>
</td>
<td class="pia-listsBlock-item pia-listsBlock-item-title">
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/entries/list/pia-line/pia-line.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ export class PiaLineComponent implements OnInit, OnChanges {

private checkUserInField(field) {
return (
this.users.findIndex(u => u.firstname + ' ' + u.lastname === field) !== -1
this.pia.user_pias.findIndex(
u => u.user.firstname + ' ' + u.user.lastname === field
) !== -1
);
}

Expand Down
30 changes: 18 additions & 12 deletions src/app/modules/pia/pia.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,26 @@ export class PiaComponent implements OnInit, DoCheck {
this.authService.currentUser.subscribe({
complete: () => {
if (this.authService.state) {
// TODO: UPDATE editMode var with current user
this.editMode = [];
switch (this.authService.currentUserValue.id) {
case this.pia.author_name:
this.editMode.push('author');
case this.pia.evaluator_name:
this.editMode.push('evaluator');
case this.pia.validator_name:
this.editMode.push('validator');
default:
this.editMode.push('guest');
console.log(this.authService.currentUserValue);

if (
this.authService.currentUserValue.access_type.includes(
'technique'
) ||
this.authService.currentUserValue.access_type.includes('functional')
) {
this.editMode = ['author', 'validator', 'evaluator', 'guest'];
} else {
this.pia.user_pias.forEach(up => {
if (
up.user.id ===
this.authService.currentUserValue.resource_owner_id
) {
this.editMode.push(up.role);
}
});
}
// TODO: Remove it after test
this.editMode.push('validator');
} else {
this.editMode = 'local';
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/shared/guards/auth.guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ export class AuthGuard implements CanActivate {

let bool: boolean;
switch (module) {
case 'users':
case 'users': // ACCESS ONLY FOR TECHNICAL USERS
bool = this.authService.currentUserValue.access_type.includes(
'technical'
);
break;
case 'pia':
case 'pia': // ACCESS FOR ALL USERS WHO INCLUDES FUNCTIONAL AND USER
bool =
this.authService.currentUserValue.access_type.includes(
'functional'
) && this.authService.currentUserValue.access_type.includes('user');
) || this.authService.currentUserValue.access_type.includes('user');
break;
case 'entries':
bool =
this.authService.currentUserValue.access_type.includes(
'functional'
) && this.authService.currentUserValue.access_type.includes('user');
) || this.authService.currentUserValue.access_type.includes('user');
break;
default:
bool = true; // EVERY ELSE
Expand Down

0 comments on commit 97d6030

Please sign in to comment.