Commit 35751083 authored by ndurand's avatar ndurand
Browse files

vérification des droits utilisateurs

parent 7e84af4b
<div *ngIf="userRight &&( userRight.EDITION || userRight.EDITION_MODIFICATION)">
<em>* : champ obligatoire</em>
<h4 class="modal-title" id="modal-basic-title">Gid: {{feature && feature.properties.gid}}</h4>
<form *ngIf="feature">
<form (ngSubmit)="saveData(featureForm)" #featureForm="ngForm" >
<div *ngIf="feature" >
<div class="form-group" *ngFor="let structure of structures$ | async" >
<div *ngIf="structure.column_name !== 'gid'">
<ng-container [ngSwitch]="structure.data_type">
<ng-container *ngSwitchCase="'character varying'">
<div class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<input type="text" class="form-control" [(ngModel)]="feature.properties[structure.column_name]" [name]="structure.column_name"
[maxlength]="structure.character_maximum_length" [required]="!structure.is_nullable"/>
[maxlength]="structure.character_maximum_length" [required]="!structure.is_nullable" #domainName="ngModel"/>
</div>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
</ng-container>
<ng-container *ngSwitchCase="'text'">
<div *ngIf="!structure.domain_name" class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<textarea class="form-control" class="col-9 px-0 form-control" cols="20" rows="3"
<textarea class="form-control" class="col-9 px-0 form-control" cols="20" rows="3" #domainName="ngModel"
[(ngModel)]="feature.properties[structure.column_name]" [required]="!structure.is_nullable"
[name]="structure.column_name">
</textarea>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
</div>
<div class="form-group row" *ngIf="structure.domain_name && !domainNameFile[structure.domain_name]">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<input type="text" class="form-control" [(ngModel)]="feature.properties[structure.column_name]" [name]="structure.column_name"/>
<input type="text" class="form-control" #domainName="ngModel" [(ngModel)]="feature.properties[structure.column_name]" [name]="structure.column_name"
pattern="{{regex[structure.domain_name]}}"
[required]="!structure.is_nullable"
/>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
<div *ngIf="domainName.errors.pattern">
champ incorect
</div>
</div>
</div>
</div>
<div *ngIf="structure.domain_name && domainNameFile[structure.domain_name]" class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<label class="custom-file-upload btn btn-modal px-3 py-2 mb-0 mr-2">
<input (change)="setImage($event, feature, structure.column_name)" [name]="structure.column_name" type="file" accept=".jpeg, .jpg, .png"
[required]="!structure.is_nullable"/>
......@@ -40,43 +65,64 @@
</ng-container>
<ng-container *ngSwitchCase="'integer'">
<div class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<input type="number" class="form-control" [(ngModel)]="feature.properties[ structure.column_name ]"
<input type="number" class="form-control" [(ngModel)]="feature.properties[ structure.column_name ]" #domainName="ngModel"
[maxlength]="structure.character_maximum_length"
[required]="!structure.is_nullable"
[name]="structure.column_name"/>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
</div>
</ng-container>
<ng-container *ngSwitchCase="'boolean'">
<td class="fiche-modify">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" [name]="structure.column_name"
<input class="form-check-input" type="radio" [name]="structure.column_name" #domainName="ngModel"
[id]="structure.column_name + '_true'" [ngModelOptions]="{standalone: true}"
[(ngModel)]="feature.properties[ structure.column_name ]" value="true"
[required]="!structure.is_nullable">
<label class="form-check-label" [for]="structure.column_name + '_true'">Oui</label>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" [name]="structure.column_name"
<input class="form-check-input" type="radio" [name]="structure.column_name" #domainName="ngModel"
[id]="structure.column_name + '_false'" [ngModelOptions]="{standalone: true}"
[(ngModel)]="feature.properties[ structure.column_name ]" value="false">
<label class="form-check-label" [for]="structure.column_name + '_false'">Non</label>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
<div *ngIf="structure.is_nullable" class="form-check form-check-inline">
<input class="form-check-input" type="radio" [name]="structure.column_name"
<input class="form-check-input" type="radio" [name]="structure.column_name" #domainName="ngModel"
[id]="structure.column_name + '_null'" [ngModelOptions]="{standalone: true}"
[(ngModel)]="feature.properties[ structure.column_name ]" value="null">
<label class="form-check-label" [for]="structure.column_name + '_null'">Non défini</label>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
</td>
</ng-container>
<ng-container *ngSwitchCase="'date'">
<div class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<input type="date" class="form-control" [(ngModel)]="feature.properties[ structure.column_name ]"
<input type="date" class="form-control" [(ngModel)]="feature.properties[ structure.column_name ]"
[maxlength]="structure.character_maximum_length"
[required]="!structure.is_nullable"
[name]="structure.column_name"/>
......@@ -85,9 +131,9 @@
</ng-container>
<ng-container *ngSwitchCase="'USER-DEFINED'">
<div *ngIf="structure.udt_name && enumerations[structure.udt_name ]" class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<select class="form-control " [(ngModel)]="feature.properties[ structure.column_name ]"
<select class="form-control " [(ngModel)]="feature.properties[ structure.column_name ]" #domainName="ngModel"
[required]="!structure.is_nullable" [name]="structure.column_name">
<option hidden selected disabled>Sélectionnez un ou plusieurs paramètres</option>
<option
......@@ -95,12 +141,17 @@
<span>{{ item }}</span>
</option>
</select>
<div *ngIf="domainName && domainName.invalid && (domainName.dirty || domainName.touched)" class="alert alert-danger">
<div *ngIf="domainName.errors.required">
champ obligatoire
</div>
</div>
</div>
</div>
</ng-container>
<ng-container *ngSwitchCase="'ARRAY'">
<div *ngIf="structure.udt_name && enumerations[structure.udt_name ]" class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-8">
<ng-multiselect-dropdown
[placeholder]="'Sélectionnez un ou plusieurs paramètres'"
......@@ -116,18 +167,25 @@
</ng-container>
<ng-container *ngSwitchDefault> <!-- 'double precision', 'numeric', 'smallint', 'real', 'bigint' -->
<div class="form-group row">
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}}</label>
<label [for]="structure.column_name" class="col-sm-3 col-form-label">{{structure.column_name}} {{ structure.is_nullable ? '' : "*" }}</label>
<div class="col-sm-5">
<input type="number" class="form-control" [(ngModel)]="feature.properties[ structure.column_name ]"
[maxlength]="structure.character_maximum_length"
[required]="!structure.is_nullable"
[name]="structure.column_name"/>
</div>
<div *ngIf="typeArray && typeArray.invalid && (typeArray.dirty || typeArray.touched)" class="alert alert-danger">
<div *ngIf="typeArray.errors.required">
champ obligatoire
</div>
</div>
</div>
</ng-container>
</ng-container>
</div>
</div>
</form>
<a routerLink="/tableView/{{uuid}}" class="btn btn-primary" routerLinkActive="active"> Retour </a>
<button type="button" class="btn btn-outline-dark" (click)="saveData()">Save</button>
<a routerLink="/tableView/{{uuid}}" class="btn btn-primary" routerLinkActive="active"> Retour </a>
<button [disabled]="!featureForm.form.valid" type="submit" class="btn btn-outline-dark" > <i class="fa fars-sauvegarder"></i> Sauvegarder</button>
</div>
</form >
</div>
......@@ -6,6 +6,8 @@ import { Feature } from 'src/app/models/layer-type';
import { Structure } from 'src/app/models/structure';
import { DataService } from 'src/app/services/data.service';
import { TableViewDataService } from 'src/app/services/table-view-data.service';
import { NgForm } from '@angular/forms';
import { UserRight } from 'src/app/models/user-right';
@Component({
selector: 'app-modal-edit',
......@@ -31,6 +33,15 @@ export class EditDataComponent implements OnInit {
/** */
public enumerations: {};
/** */
public regex = {
email: '^[a-zA-Z]+[^@]*@[a-zA-Z]+[^@]*\\.[a-zA-Z]{2,}[^@]*$',
phone_number: '^(\\+33|0)[1-9](\\d\\d){4}$'
};
/** */
public userRight: UserRight;
constructor(
private tableViewData: TableViewDataService,
private dataService: DataService,
......@@ -43,6 +54,16 @@ export class EditDataComponent implements OnInit {
this.tableViewData.getEnumerations$().subscribe( enumerations => {
this.enumerations = enumerations;
});
this.tableViewData.getUserRight$().subscribe(userRight => {
console.log('59', userRight);
this.userRight = userRight;
// si l'utilisateur n'a pas les droits d'édtion on renvoie sur la vue tableView
if (userRight && !this.userRight.EDITION && !this.userRight.EDITION_MODIFICATION) {
this.router.navigate(['/tableView/' + this.uuid, {}]);
}
});
}
/** */
......@@ -69,7 +90,7 @@ export class EditDataComponent implements OnInit {
structures = this.dataService.apllyStructureFilter(structures);
this.tableViewData.setStructures( structures );
structures.forEach(structure => {
properties[structure.column_name] = '';
properties[structure.column_name] = null;
});
this.feature = {properties} as Feature;
......@@ -84,7 +105,6 @@ export class EditDataComponent implements OnInit {
if (this.feature.properties.gid || this.feature.properties.gid === '0') {
this.dataService.updateData([this.feature]);
} else {
console.log('posData');
this.dataService.postData([this.feature]).subscribe(
reponse => {
console.log(reponse);
......
......@@ -23,6 +23,11 @@ export class MainComponent implements OnInit {
this.dataService.uuid = this.activatedRoute.snapshot.paramMap.get('uuid');
}
/** Right */
this.dataService.getDataRight().subscribe( userRight => {
this.tableViewData.setUserRight(userRight);
});
/** config */
this.dataService.getContifData().subscribe( response => {
if (response && response.metadata && response.metadata.title) {
......
......@@ -13,11 +13,11 @@
</ng-template>
<!-- Recherche-->
<div class="form-group form-inline">
<div class="form-group form-inline" >
Recherche : <input class="form-control ml-2" type="text" name="searchTerm" [(ngModel)]="tableViewData.searchTerm"/>
<span class="ml-3" *ngIf="tableViewData.getLoading$() | async">Loading...</span>
</div>
<a routerLink="edit" class="btn btn-primary" routerLinkActive="active"><i class="fas fa-edit"></i> Editer</a>
<a routerLink="edit" *ngIf="userRight && (userRight.EDITION || userRight.EDITION_AJOUT )" class="btn btn-primary" routerLinkActive="active"><i class="fas fa-edit"></i> Ajouter</a>
<!-- Pagination -->
<ng-container *ngTemplateOutlet="paginationTpl"></ng-container>
......@@ -27,7 +27,7 @@
<thead>
<tr>
<th scope="col" *ngFor="let structure of structures$ | async; index as k" [appSortable]="structure.column_name" (sort)="onSort($event)">{{structure.column_name}}</th>
<th>Actions</th>
<th *ngIf="userRight && (userRight.EDITION || userRight.MODIFICATION)">Actions</th>
</tr>
</thead>
<tbody>
......@@ -35,9 +35,9 @@
<td *ngFor="let structure of structures$ | async; index as j">
{{feature.properties[structure.column_name]}}
</td>
<td class="table-button-action">
<td class="table-button-action" *ngIf="userRight && (userRight.EDITION || userRight.MODIFICATION)">
<a routerLink="edit/{{feature.properties.gid}}" class="btn btn-primary" routerLinkActive="active"><i class="fas fa-edit"></i> Editer</a>
<button type="button" class="btn btn-danger" (click)="deleteData(feature)"><i class="fas fa-times"></i> Suprimmer</button>
<button type="button" class="btn btn-danger" ng-if="userRight && userRight.EDITION" (click)="deleteData(feature)"><i class="fas fa-times"></i> Suprimmer</button>
</td>
</tr>
</tbody>
......
......@@ -6,6 +6,8 @@ import { TableViewDataService } from 'src/app/services/table-view-data.service';
import { Structure } from 'src/app/models/structure';
import { DataService } from 'src/app/services/data.service';
import { switchMap } from 'rxjs/operators';
import { ActivatedRoute } from '@angular/router';
import { UserRight } from 'src/app/models/user-right';
@Component({
selector: 'app-table-view',
......@@ -20,7 +22,8 @@ export class TableViewComponent implements OnInit {
public features$: Observable<Feature[]>;
public total$: Observable<number>;
public pageSizeChoice: Array<number>;
public userRight$: Observable<UserRight>;
public userRight: UserRight;
/** Pour le tri */
@ViewChildren(SortableHeaderDirective) headers: QueryList<SortableHeaderDirective>;
......@@ -28,15 +31,21 @@ export class TableViewComponent implements OnInit {
/** */
constructor(
public tableViewData: TableViewDataService,
private dataService: DataService
private dataService: DataService,
private activatedRoute: ActivatedRoute
) {
this.features$ = this.tableViewData.getFeatures$();
this.structures$ = this.tableViewData.getStructures$();
this.total$ = this.tableViewData.getTotal$();
this.userRight$ = this.tableViewData.getUserRight$();
}
/** */
ngOnInit(): void {
this.userRight$.subscribe(userRight => {
this.userRight = userRight;
});
forkJoin(
this.dataService.getData(),
this.dataService.getStructure()
......@@ -50,6 +59,18 @@ export class TableViewComponent implements OnInit {
this.tableViewData.searchFromUrlParam();
this.pageSizeChoice = this.tableViewData.pageSizeChoice;
const searchTerm: string = this.activatedRoute.snapshot.paramMap.get('q');
const valueTerm: string = this.activatedRoute.snapshot.paramMap.get('value');
const fieldFilter: string = this.activatedRoute.snapshot.paramMap.get('field');
if (searchTerm) {
this.tableViewData.searchTerm = searchTerm;
} else if (valueTerm && fieldFilter) {
this.tableViewData.searchTerm = searchTerm;
this.tableViewData.sortColumn = fieldFilter;
}
}
onSort({column, direction}: SortEvent): void {
......
export interface UserRight {
NAVIGATION: boolean;
SYNCHRONIZE: boolean;
EDITION_ATTRIBUTE_FILTER: boolean;
EDITION: boolean;
EDITION_AJOUT: boolean;
EDITION_MODIFICATION: boolean;
isAdmProdige: boolean;
isConnected: boolean;
userNom: string;
userPrenom: string;
userLogin: string;
userId: number;
userSignature: number;
userEmail: string;
success: boolean;
}
......@@ -7,6 +7,7 @@ import { Observable, Observer } from 'rxjs';
import { ConfigData } from '../models/config-data';
import { Structure } from '../models/structure';
import { ProdigeReponse } from '../models/prodige-reponse';
import { UserRight } from '../models/user-right';
@Injectable({
providedIn: 'root'
......@@ -23,6 +24,15 @@ export class DataService {
/** */
private columnNameHide = {_userid_creation: true , _userid_modification: true , _edit_datemaj: true};
/** */
getDataRight(): Observable<UserRight> {
return this.http.get<UserRight>(
this.envService.catalogueUrl +
'/prodige/verify_rights?OBJET_TYPE=dataset&OBJET_STYPE&TRAITEMENTS=EDITION%7CNAVIGATION&uuid=' + this.uuid,
this.httpOption
);
}
/** Donnée tabulaire */
getData(): Observable<FeatureCollection> {
return this.http.get<FeatureCollection>( this.envService.catalogueUrl + '/api/data/' + this.uuid , this.httpOption);
......@@ -37,14 +47,12 @@ export class DataService {
/** Ajout de données tabulaire */
postData(features: Array<Feature>): Observable<ProdigeReponse> {
const data = {type: 'FeatureCollection', features } as FeatureCollection;
return this.http.post<ProdigeReponse>(this.envService.catalogueUrl + '/api/data_tabulaire/' + this.uuid, data, this.httpOption);
}
/** Mise à jour de données tabulaire */
updateData(features: Array<Feature>) {
const data = {type: 'FeatureCollection', features } as FeatureCollection;
console.log(data);
this.http.patch(this.envService.catalogueUrl + '/api/data_tabulaire/' + this.uuid, data, this.httpOption).subscribe(response => {
console.log(response);
});
......
......@@ -8,6 +8,7 @@ import { Feature } from '../models/layer-type';
import { SortDirection } from 'src/app/directives/sortable-header.directive';
import { EnvService } from './env.service';
import { Structure } from '../models/structure';
import { UserRight } from '../models/user-right';
interface SearchResult {
features: Feature[];
......@@ -41,6 +42,9 @@ export class TableViewDataService {
private enumerations$ = new BehaviorSubject<{}>({});
private enumerations: {};
/** */
private userRight$ = new BehaviorSubject<UserRight>(null);
private state: State = {
page: 1,
pageSize: 10,
......@@ -48,7 +52,7 @@ export class TableViewDataService {
sortColumn: 'gid',
sortDirection: 'asc',
searchField: '',
pageSizeChoice: [10, 25, 50, 100, 500]
pageSizeChoice: [10, 25, 50, 100, 500],
};
constructor(private pipe: DecimalPipe, private envService: EnvService, ) {
......@@ -76,6 +80,8 @@ export class TableViewDataService {
getStructures(): Structure[] { return this.structures; }
getStructures$(): Observable<Structure[]> {return this.structures$.asObservable(); }
getUserRight$(): Observable<UserRight> {return this.userRight$.asObservable(); }
getFeatures$(): Observable<Feature[]> { return this.features$.asObservable(); }
get page(): number { return this.state.page; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment