Skip to content
Snippets Groups Projects
Unverified Commit 060d187f authored by Gaëlle Fournier's avatar Gaëlle Fournier Committed by GitHub
Browse files

[CEA] Fix : Référentiel contexte (#332)


* TULEAP 24198: Synchronize permission tab

* remove unused import

* TULEAP-24200: Fix context creation steps, date and style

* Fix TULEAP 20316: context activation and deactivation date update

* [CEA] 24199, 24200, 20311 : Many fixes on vitam contexts

Co-authored-by: default avatarbenemart <benedicte.martinez@cea.fr>

* Fix import front contextPermission

Co-authored-by: default avatarMaël QUAISSARD <mael.quaissard@smile.fr>
Co-authored-by: default avatarEL HAJJIOUI Nabil <nabil.elhajjioui@smile.fr>
Co-authored-by: default avatarbenemart <benedicte.martinez@cea.fr>
parent 1586aa83
No related branches found
No related tags found
2 merge requests!51Merge mis a jour vitam-ui,!25Nouveau mis a jour Vitamui
Showing
with 2049 additions and 1950 deletions
......@@ -38,6 +38,7 @@ package fr.gouv.vitamui.iam.internal.server.customer.service;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.ExternalParametersDto;
import fr.gouv.vitamui.commons.api.domain.GroupDto;
import fr.gouv.vitamui.commons.api.domain.LanguageDto;
import fr.gouv.vitamui.commons.api.domain.OwnerDto;
import fr.gouv.vitamui.commons.api.domain.ServicesData;
......@@ -190,6 +191,34 @@ public class InitCustomerService {
createCustomGroups(customerDto, proofTenantDto, customProfiles);
createCustomUsers(customerDto, customGroups);
Optional<Profile> accessProfile =
createdAdminProfiles.stream().filter(ac -> ac.getApplicationName().equals(CommonConstants.ACCESS_CONTRATCS_APPLICATIONS_NAME)).findFirst();
Optional<Profile> ingestProfile =
createdAdminProfiles.stream().filter(ac -> ac.getApplicationName().equals(CommonConstants.INGEST_CONTRATCS_APPLICATIONS_NAME)).findFirst();
if(accessProfile.isPresent() && ingestProfile.isPresent()) {
addAccessAndIngestContractsToAdmin(accessProfile.get(), ingestProfile.get());
}
}
private void addAccessAndIngestContractsToAdmin(Profile accessProfile, Profile ingestProfile) {
UserDto adminUser = internalUserService.getOne(CommonConstants.ADMIN_USER);
final GroupDto adminGroupDto = internalGroupService.getOne(adminUser.getGroupId());
if(adminGroupDto != null) {
adminGroupDto.getProfileIds().add(accessProfile.getId());
adminGroupDto.getProfileIds().add(ingestProfile.getId());
internalGroupService.updateProfilesById(adminGroupDto.getId(), adminGroupDto.getProfileIds());
} else {
LOGGER.warn("Le groupe d'administrateur n'existe pas, " +
"pour la gestion des permissions des contrats d'accès et d'entrées des contextes applicatifs vitam pour le tenant {}" +
"faudra associer les profils (les profils devront etre actifs) de ces applications [ contrat d'accès: {} et contrat d'entrée: {}].",
accessProfile.getTenantIdentifier(), accessProfile.getName(), ingestProfile.getName());
}
}
private ExternalParametersDto initFullAccessContractExternalParameter(String customerIdentifier) {
......
......@@ -95,6 +95,9 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* The service to read, create, update and delete the tenants.
......
......@@ -165,6 +165,7 @@ public class TenantInternalServiceTest {
prepareServices();
internalTenantService.create(tenantDto);
assertThat(profileRepository.findAll()).isNotNull();
}
@Test
......
......@@ -321,4 +321,8 @@ public class CommonConstants {
public static final String X_SIZE_TOTAL = "X-Size-Total";
public static final String X_CHUNK_OFFSET = "X-Chunk-Offset";
public static final String LOGO = "LOGO";
public static final String ACCESS_CONTRATCS_APPLICATIONS_NAME = "ACCESS_APP";
public static final String INGEST_CONTRATCS_APPLICATIONS_NAME = "INGEST_APP";
public static final String ADMIN_USER = "admin_user";
}
source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
......@@ -69,8 +69,14 @@
</div>
<div class="actions">
<button type="button" class="btn primary" cdkStepperNext [disabled]="firstStepInvalid()"
<button *ngIf="form?.controls.enableControl?.value === true"
type="button" class="btn primary" cdkStepperNext
[disabled]="firstStepInvalid()"
i18n="Next step button label@@contextCreateNextButton">Suivant</button>
<button *ngIf="form?.controls.enableControl?.value === false"
type="submit" class="btn primary"
[disabled]="firstStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button>
<button type="button" class="btn cancel" (click)="onCancel()"
i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button>
</div>
......@@ -97,13 +103,17 @@
</ng-container>
</div>
<button type="submit" class="btn primary" [disabled]="lastStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button>
<button type="button" class="btn cancel" (click)="onCancel()"
i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button>
<div class="actions">
<button type="submit" class="btn primary" [disabled]="lastStepInvalid()"
i18n="Finish context creation button@@contextCreateFinishButton">Terminer</button>
<button type="button" class="btn cancel" (click)="onCancel()"
i18n="Cancel context creation@@contextCreateCancelButton">Annuler</button>
</div>
<button type="button" class="back" cdkStepperPrevious>
<i class="material-icons">arrow_back</i>
<ng-container i18n="Previous step button label@@contextCreateBackButton">Retour</ng-container>
<ng-container i18n="Previous step button label@@contextCreateBackButton">
<span class="underline">Retour</span>
</ng-container>
</button>
</div>
</cdk-step>
......
......@@ -34,16 +34,18 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import {Component,Inject,Input,OnDestroy,OnInit,ViewChild} from '@angular/core';
import {FormBuilder,FormControl,FormGroup,Validators} from '@angular/forms';
import {MatDialogRef,MAT_DIALOG_DATA} from '@angular/material/dialog';
import {ContextPermission} from 'projects/vitamui-library/src/public-api';
import {Subscription} from 'rxjs';
import {ConfirmDialogService, Option} from 'ui-frontend-common';
import {Component, Inject, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {AuthService,ConfirmDialogService,Option} from 'ui-frontend-common';
import {Context} from '../../../../../vitamui-library/src/lib/models/context';
import {SecurityProfileService} from '../../security-profile/security-profile.service';
import {ContextService} from '../context.service';
import {ContextCreateValidators} from './context-create.validators';
const PROGRESS_BAR_MULTIPLICATOR = 100;
@Component({
......@@ -74,7 +76,6 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
@ViewChild('fileSearch', {static: false}) fileSearch: any;
securityProfiles: Option[] = [];
constructor(
public dialogRef: MatDialogRef<ContextCreateComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
......@@ -82,7 +83,8 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
private confirmDialogService: ConfirmDialogService,
private contextService: ContextService,
private contextCreateValidators: ContextCreateValidators,
private securityProfileService: SecurityProfileService
private securityProfileService: SecurityProfileService,
private authService: AuthService
) {
}
......@@ -93,7 +95,7 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
identifier: [null, Validators.required, this.contextCreateValidators.uniqueIdentifier()],
securityProfile: [null, Validators.required],
enableControl: [false],
permissions: [[{tenant: null, accessContracts: [], ingestContracts: []}], null, this.contextCreateValidators.permissionInvalid()]
permissions: [[{tenant: null, accessContracts: [], ingestContracts: []}], null, null]
});
this.form.controls.name.valueChanges.subscribe((value) => {
......@@ -106,10 +108,20 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
this.form.controls.status.setValue(value = (value === false) ? 'INACTIVE' : 'ACTIVE');
});
// Add or remove controls on the permissions
this.form.controls.enableControl.valueChanges.subscribe((value) => {
if (value) {
this.form.controls.permissions.setAsyncValidators([this.contextCreateValidators.permissionInvalid()]);
} else {
this.form.controls.permissions.clearAsyncValidators();
}
this.form.controls.permissions.updateValueAndValidity(this.form.controls.permissions.value);
});
this.securityProfileService.getAll().subscribe(
securityProfiles => {
this.securityProfiles = securityProfiles.map(x => ({label: x.name, key: x.identifier}));
});
});
this.keyPressSubscription = this.confirmDialogService.listenToEscapeKeyPress(this.dialogRef).subscribe(() => this.onCancel());
}
......@@ -131,7 +143,15 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
return;
}
this.contextService.create(this.form.value).subscribe(
let context = this.form.value as Context;
if(context.permissions.length == 1) {
if(context.permissions[0].tenant == null) {
this.fillContextPermissions(context);
}
}
context.status === 'ACTIVE' ? context.activationDate = new Date().toISOString() : context.deactivationDate = new Date().toISOString();
this.contextService.create(context).subscribe(
() => {
this.dialogRef.close({success: true, action: 'none'});
},
......@@ -141,6 +161,18 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
});
}
fillContextPermissions(context: Context): Context {
const permission : ContextPermission = {
tenant: this.authService.user.proofTenantIdentifier,
accessContracts: [],
ingestContracts: []
}
context.permissions.pop();
context.permissions.push(permission);
return context;
}
firstStepInvalid() {
return this.form.get('name').invalid || this.form.get('name').pending ||
this.form.get('status').invalid || this.form.get('status').pending ||
......@@ -169,7 +201,14 @@ export class ContextCreateComponent implements OnInit, OnDestroy {
}
get stepProgress() {
return ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR;
let stepProgress: number;
// For the first step, check if the controls are enabled and if the second step is available or not
if (this.stepIndex === 0 && this.form.controls.enableControl.value === true) {
stepProgress = ((this.stepIndex + 1) / this.stepCount) * PROGRESS_BAR_MULTIPLICATOR;
} else {
stepProgress = PROGRESS_BAR_MULTIPLICATOR;
}
return stepProgress;
}
}
......@@ -36,15 +36,15 @@
*/
/* tslint:disable:no-use-before-declare */
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ContextPermission } from 'projects/vitamui-library/src/public-api';
import { AuthService, Option } from 'ui-frontend-common';
import { Customer, Tenant } from 'ui-frontend-common/app/modules/models/customer';
import { AccessContractService } from '../../../access-contract/access-contract.service';
import { CustomerApiService } from '../../../core/api/customer-api.service';
import { TenantApiService } from '../../../core/api/tenant-api.service';
import { IngestContractService } from '../../../ingest-contract/ingest-contract.service';
import {Component,EventEmitter,forwardRef,Input,OnInit,Output} from '@angular/core';
import {ControlValueAccessor,NG_VALUE_ACCESSOR} from '@angular/forms';
import {ContextPermission} from 'projects/vitamui-library/src/public-api';
import {AuthService,Option} from 'ui-frontend-common';
import {Customer,Tenant} from 'ui-frontend-common/app/modules/models/customer';
import {AccessContractService} from '../../../access-contract/access-contract.service';
import {CustomerApiService} from '../../../core/api/customer-api.service';
import {TenantApiService} from '../../../core/api/tenant-api.service';
import {IngestContractService} from '../../../ingest-contract/ingest-contract.service';
export const CONTEXT_PERMISSION_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR,
......@@ -122,7 +122,7 @@ export class ContextEditPermissionComponent implements ControlValueAccessor, OnI
accessTenants.forEach((tenant) => {
this.accessService.getAllForTenant('' + tenant.identifier).subscribe(
accessContracts => {
this.accessContracts.set('' + tenant.identifier, accessContracts.map(x => ({
this.accessContracts.set('' + tenant.identifier, accessContracts.filter(ac => ac.status === 'ACTIVE').map(x => ({
label: x.name,
key: x.identifier
})));
......@@ -136,7 +136,7 @@ export class ContextEditPermissionComponent implements ControlValueAccessor, OnI
ingestTenants.forEach((tenant) => {
this.ingestService.getAllForTenant('' + tenant.identifier).subscribe(
ingestContracts => {
this.ingestContracts.set('' + tenant.identifier, ingestContracts.map(x => ({
this.ingestContracts.set('' + tenant.identifier, ingestContracts.filter(ic => ic.status === 'ACTIVE').map(x => ({
label: x.name,
key: x.identifier
})));
......
......@@ -172,8 +172,11 @@ export class ContextInformationTabComponent {
this.prepareSubmit().subscribe(() => {
this.contextService.get(this._context.identifier).subscribe(
response => {
this.submited = false;
this.context = response;
this.submited = false;
this.context = extend(this.context, response);
// Update the activation and deactivation dates
this.context.activationDate = response.activationDate ? response.activationDate : null;
this.context.deactivationDate = response.deactivationDate ? response.deactivationDate : null;
}
);
}, () => {
......
......@@ -86,7 +86,6 @@ export class ContextPreviewComponent implements AfterViewInit {
async checkBeforeExit() {
if (await this.confirmAction()) {
const submitAccessContractUpdate: Observable<Context> = this.tabLinks[this.tabs.selectedIndex].prepareSubmit();
submitAccessContractUpdate.subscribe(() => {
this.contextService.get(this.context.identifier).subscribe(
response => {
......@@ -94,14 +93,17 @@ export class ContextPreviewComponent implements AfterViewInit {
}
);
});
} else {
this.tabLinks[this.tabs.selectedIndex].resetForm(this.context);
}
}
async interceptTabChange(tab: MatTab, tabHeader: MatTabHeader, idx: number) {
if (this.tabUpdated[this.tabs.selectedIndex]) {
await this.checkBeforeExit();
} else {
if (idx === 1) {
// Reset the permissions for if the context has changed
this.tabLinks[idx].resetForm(this.context);
}
}
const args = [tab, tabHeader, idx];
......
......@@ -34,15 +34,15 @@
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
import {Component, OnInit, ViewChild} from '@angular/core';
import {Component,OnInit,ViewChild} from '@angular/core';
import {MatDialog} from '@angular/material/dialog';
import {ActivatedRoute} from '@angular/router';
import {ApplicationService, GlobalEventService, SidenavPage} from 'ui-frontend-common';
import {ApplicationService,GlobalEventService,SidenavPage} from 'ui-frontend-common';
import {Context} from '../../../../vitamui-library/src/lib/models/context';
import {ContextCreateComponent} from './context-create/context-create.component';
import {ContextListComponent} from './context-list/context-list.component';
@Component({
selector: 'app-context',
templateUrl: './context.component.html',
......
......@@ -136,5 +136,3 @@ list-enable-external-identifiers:
- ACCESS_CONTRACT
- MANAGEMENT_CONTRACT
- PROFILE
- SECURITY_PROFILE
- CONTEXT
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