Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1893-update-dataset-bug #1912

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -553,19 +553,15 @@ public boolean hasUpdateRightOnDataset(Dataset dataset, String rightStr) throws
if (dataset.getId() == null) {
throw new IllegalArgumentException("Dataset id cannot be null here.");
}
if (dataset.getStudyId() == null) {
return false;
}
if (dataset.getDatasetProcessing() != null) {
//Forbid processed dataset update for the moment
return false;
}
Dataset dbDataset = datasetRepository.findById(dataset.getId()).orElse(null);
if (dbDataset == null) {
throw new EntityNotFoundException("Cannot find dataset with id " + dataset.getId());
}
if (dataset.getStudyId() == dbDataset.getStudyId()) { // study hasn't changed
return this.hasRightOnStudyCenter(dataset.getDatasetAcquisition().getExamination().getCenterId(), dataset.getDatasetAcquisition().getExamination().getStudyId(), rightStr);
} else { // study has changed : check user has right on both studies
return this.hasRightOnStudyCenter(dataset.getDatasetAcquisition().getExamination().getCenterId(), dataset.getDatasetAcquisition().getExamination().getStudyId(), rightStr)
&& this.hasRightOnStudyCenter(dbDataset.getDatasetAcquisition().getExamination().getCenterId(), dbDataset.getDatasetAcquisition().getExamination().getStudyId(), rightStr);
}
return this.hasRightOnStudyCenter(dbDataset.getDatasetAcquisition().getExamination().getCenterId(), dbDataset.getDatasetAcquisition().getExamination().getStudyId(), rightStr);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ private void testAll(String role) throws ShanoirException, RestServiceException
assertAccessDenied(api::updateDataset, 1L, mockDataset(1L, 1L, 1L, 1L, 1L), mockBindingResult);
} else if ("ROLE_EXPERT".equals(role)) {
assertAccessAuthorized(api::updateDataset, 1L, mockDataset(1L, 1L, 1L, 1L, 1L), mockBindingResult);
assertAccessDenied(api::updateDataset, 1L, mockDataset(1L, 1L, 1L, 2L, 1L), mockBindingResult);

Dataset ds = mockDataset(100L, 1L, 1L, 2L, 1L);
given(datasetRepository.findById(ds.getId())).willReturn(Optional.of(ds));

assertAccessDenied(api::updateDataset, 1L, ds, mockBindingResult);
}
assertAccessDenied(api::updateDataset, 1L, mockDataset(2L, 2L, 2L, 2L, 2L), mockBindingResult);
assertAccessDenied(api::updateDataset, 1L, mockDataset(3L, 3L, 3L, 3L, 1L), mockBindingResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ private void testUpdate(String role) throws ShanoirException {
assertAccessDenied(service::update, mockDataset(1L, 1L, 1L, 1L, 1L));
} else if ("ROLE_EXPERT".equals(role)) {
assertAccessAuthorized(service::update, mockDataset(1L, 1L, 1L, 1L, 1L));
assertAccessDenied(service::update, mockDataset(1L, 1L, 1L, 2L, 1L));
Dataset ds = mockDataset(100L, 1L, 1L, 2L, 1L);
given(datasetRepository.findById(ds.getId())).willReturn(Optional.of(ds));

assertAccessDenied(service::update, ds);
}
assertAccessDenied(service::update, mockDataset(2L, 2L, 2L, 2L, 2L));
assertAccessDenied(service::update, mockDataset(3L, 3L, 3L, 3L, 1L));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,9 @@
<li>
<label i18n="Dataset detail|Dataset study@@datasetDetailStudy">Study</label>
<span class="right-col" [ngSwitch]="mode">
<ng-template [ngSwitchCase]="'view'">
<a [routerLink]="['/study/details/', dataset.study?.id]">
{{dataset.study?.name}}
</a>
</ng-template>
<ng-template ngSwitchDefault>
<select-box [(ngModel)]="dataset.study" formControlName="study" [optionArr]="studies">
</select-box>
</ng-template>
</span>
</li>
<li>
Expand All @@ -99,41 +93,6 @@
</ng-template>
</span>
</li>
<!-- <li>
<label i18n="Dataset detail|Dataset acquisition@@datasetDetailAcquisition">Acquisition</label>
<span class="right-col" [ngSwitch]="mode">
<ng-template [ngSwitchCase]="'view'">{{dataset.acquisitionId}}</ng-template>
<ng-template ngSwitchDefault>
<select [(ngModel)]="dataset.acquisitionId" [ngModelOptions]="{standalone: true}" >
<option *ngFor="" [value]="">{{}}</option>
</select>
</ng-template>
</span>
</li> -->
<!-- <li>
<label i18n="Dataset detail|Dataset processing@@datasetDetailProcessing">Processing</label>
<span class="right-col">
<ng-template *ngIf="mode == 'view'">{{dataset.processing}}</ng-template>
</span>
</li> -->
<!-- <li>
<label i18n="Dataset detail|Dataset referenced for superimposition@@datasetDetailReferencedForSuperimposition">Can be superimposed with</label>
<span class="right-col">
<ng-template *ngIf="mode=='view'">{{dataset.referencedDatasetForSuperimposition}}</ng-template>
</span>
</li> -->

<!-- <li>
<label i18n="Dataset detail|Dataset group fo subject@@datasetDetailGroupOfSubject">Group of subjects</label>
<span class="right-col" [ngSwitch]="mode">
<ng-template [ngSwitchCase]="'view'">{{dataset.groupOfSubjectId}}</ng-template>
<ng-template ngSwitchDefault>
<select [(ngModel)]="dataset.groupOfSubjectId" [ngModelOptions]="{standalone: true}" >
<option *ngFor="" [value]="">{{}}</option>
</select>
</ng-template>
</span>
</li> -->
</ol>
</fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export class CommonDatasetComponent implements OnChanges {
if (this.mode != 'view') {
this.fetchAllSubjects();
this.fetchAllStudies();
if (this.dataset && this.dataset.creationDate) {
this.dataset.creationDate = new Date(this.dataset.creationDate);
}
} else if (this.dataset) {
this.fetchOneSubject();
this.fetchOneStudy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class DatasetComponent extends EntityComponent<Dataset> {
initEdit(): Promise<void> {
return this.fetchDataset().then(dataset => {
this.dataset = dataset;
this.dataset.creationDate = new Date(this.dataset.creationDate);
});
}

Expand Down
11 changes: 9 additions & 2 deletions shanoir-ng-front/src/app/datasets/shared/dataset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import { Page, Pageable } from '../../shared/components/table/pageable.model';
import * as AppUtils from '../../utils/app.utils';
import { ServiceLocator } from '../../utils/locator.service';
import { Dataset } from './dataset.model';
import { MrDataset } from '../dataset/mr/dataset.mr.model';
import { DatasetUtils } from './dataset.utils';
import {DatasetDTO, DatasetDTOService} from "./dataset.dto";
import {DatasetDTO, MrDatasetDTO, DatasetDTOService} from "./dataset.dto";

@Injectable()
export class DatasetService extends EntityService<Dataset> implements OnDestroy {
Expand Down Expand Up @@ -286,7 +287,13 @@ export class DatasetService extends EntityService<Dataset> implements OnDestroy
}

public stringify(entity: Dataset) {
let dto = new DatasetDTO(entity);
let dto;
if (entity instanceof MrDataset) {
dto = new MrDatasetDTO(entity);
dto.updatedMrMetadata = entity.updatedMrMetadata;
} else {
dto = new DatasetDTO(entity);
}
return JSON.stringify(dto, (key, value) => {
return this.customReplacer(key, value, dto);
});
Expand Down