mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
fix #869 Submission embargo bug
This commit is contained in:
@@ -8,16 +8,6 @@ export class AccessConditionOption {
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The uuid of the Group this Access Condition applies to
|
||||
*/
|
||||
groupUUID: string;
|
||||
|
||||
/**
|
||||
* The uuid of the Group that contains set of groups this Resource Policy applies to
|
||||
*/
|
||||
selectGroupUUID: string;
|
||||
|
||||
/**
|
||||
* A boolean representing if this Access Condition has a start date
|
||||
*/
|
||||
|
@@ -13,11 +13,6 @@ export class SubmissionUploadFileAccessConditionObject {
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The access group UUID defined in this access condition
|
||||
*/
|
||||
groupUUID: string;
|
||||
|
||||
/**
|
||||
* Possible start date of the access condition
|
||||
*/
|
||||
|
@@ -1284,27 +1284,23 @@ export const mockUploadConfigResponse = {
|
||||
accessConditionOptions: [
|
||||
{
|
||||
name: 'openaccess',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: false,
|
||||
hasEndDate: false
|
||||
},
|
||||
{
|
||||
name: 'lease',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: false,
|
||||
hasEndDate: true,
|
||||
maxEndDate: '2019-07-12T14:40:06.308+0000'
|
||||
},
|
||||
{
|
||||
name: 'embargo',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: true,
|
||||
hasEndDate: false,
|
||||
maxStartDate: '2022-01-12T14:40:06.308+0000'
|
||||
},
|
||||
{
|
||||
name: 'administrator',
|
||||
groupUUID: '0f2773dd-1741-475f-80e7-ccdef153d655',
|
||||
hasStartDate: false,
|
||||
hasEndDate: false
|
||||
}
|
||||
@@ -1323,35 +1319,6 @@ export const mockUploadConfigResponse = {
|
||||
// Clone the object and change one property
|
||||
export const mockUploadConfigResponseNotRequired = Object.assign({}, mockUploadConfigResponse, { required: false });
|
||||
|
||||
export const mockAccessConditionOptions = [
|
||||
{
|
||||
name: 'openaccess',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: false,
|
||||
hasEndDate: false
|
||||
},
|
||||
{
|
||||
name: 'lease',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: false,
|
||||
hasEndDate: true,
|
||||
maxEndDate: '2019-07-12T14:40:06.308+0000'
|
||||
},
|
||||
{
|
||||
name: 'embargo',
|
||||
groupUUID: '123456-g',
|
||||
hasStartDate: true,
|
||||
hasEndDate: false,
|
||||
maxStartDate: '2022-01-12T14:40:06.308+0000'
|
||||
},
|
||||
{
|
||||
name: 'administrator',
|
||||
groupUUID: '0f2773dd-1741-475f-80e7-ccdef153d655',
|
||||
hasStartDate: false,
|
||||
hasEndDate: false
|
||||
}
|
||||
];
|
||||
|
||||
export const mockGroup = Object.assign(new Group(), {
|
||||
handle: null,
|
||||
permanent: true,
|
||||
@@ -1478,17 +1445,6 @@ export const mockFileFormData = {
|
||||
otherInformation: null
|
||||
}
|
||||
],
|
||||
groupUUID: [
|
||||
{
|
||||
value: '123456-g',
|
||||
language: null,
|
||||
authority: null,
|
||||
display: '123456-g',
|
||||
confidence: -1,
|
||||
place: 0,
|
||||
otherInformation: null
|
||||
}
|
||||
]
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -1522,17 +1478,6 @@ export const mockFileFormData = {
|
||||
otherInformation: null
|
||||
}
|
||||
],
|
||||
groupUUID: [
|
||||
{
|
||||
value: '123456-g',
|
||||
language: null,
|
||||
authority: null,
|
||||
display: '123456-g',
|
||||
confidence: -1,
|
||||
place: 0,
|
||||
otherInformation: null
|
||||
}
|
||||
]
|
||||
}
|
||||
,
|
||||
{
|
||||
@@ -1566,17 +1511,6 @@ export const mockFileFormData = {
|
||||
otherInformation: null
|
||||
}
|
||||
],
|
||||
groupUUID: [
|
||||
{
|
||||
value: '123456-g',
|
||||
language: null,
|
||||
authority: null,
|
||||
display: '123456-g',
|
||||
confidence: -1,
|
||||
place: 0,
|
||||
otherInformation: null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@@ -2,7 +2,6 @@
|
||||
<span *ngIf="accessCondition.action == 'DEFAULT_BITSTREAM_READ'" class="badge badge-primary mt-3 mr-2">
|
||||
{{accessCondition.name}} {{accessCondition.startDate}} {{accessCondition.endDate}}
|
||||
</span>
|
||||
<span *ngIf="accessCondition.name == 'openaccess'" class="badge badge-success mt-3 mr-2">{{accessCondition.name}}</span>
|
||||
<span *ngIf="accessCondition.name == 'lease'" class="badge badge-primary mt-3 mr-2">{{accessCondition.name}} from {{accessCondition.endDate}}</span>
|
||||
<span *ngIf="accessCondition.name == 'embargo'" class="badge badge-dark mt-3 mr-2">{{accessCondition.name}} until {{accessCondition.startDate}}</span>
|
||||
<br>
|
||||
|
@@ -43,10 +43,6 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
const sectionId = 'upload';
|
||||
const collectionId = mockSubmissionCollectionId;
|
||||
const availableAccessConditionOptions = mockUploadConfigResponse.accessConditionOptions;
|
||||
const availableGroupsMap: Map<string, Group[]> = new Map([
|
||||
[mockUploadConfigResponse.accessConditionOptions[1].name, [mockGroup as any]],
|
||||
[mockUploadConfigResponse.accessConditionOptions[2].name, [mockGroup as any]],
|
||||
]);
|
||||
const collectionPolicyType = POLICY_DEFAULT_WITH_LIST;
|
||||
const configMetadataForm: any = mockUploadConfigResponseMetadata;
|
||||
const fileIndex = '0';
|
||||
@@ -123,7 +119,6 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
comp.collectionId = collectionId;
|
||||
comp.sectionId = sectionId;
|
||||
comp.availableAccessConditionOptions = availableAccessConditionOptions;
|
||||
comp.availableAccessConditionGroups = availableGroupsMap;
|
||||
comp.collectionPolicyType = collectionPolicyType;
|
||||
comp.fileIndex = fileIndex;
|
||||
comp.fileId = fileId;
|
||||
@@ -180,18 +175,15 @@ describe('SubmissionSectionUploadFileEditComponent test suite', () => {
|
||||
|
||||
control.value = 'openaccess';
|
||||
comp.setOptions(model, control);
|
||||
expect(formbuilderService.findById).not.toHaveBeenCalledWith('groupUUID', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
expect(formbuilderService.findById).not.toHaveBeenCalledWith('endDate', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
expect(formbuilderService.findById).not.toHaveBeenCalledWith('startDate', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
|
||||
control.value = 'lease';
|
||||
comp.setOptions(model, control);
|
||||
expect(formbuilderService.findById).toHaveBeenCalledWith('groupUUID', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
expect(formbuilderService.findById).toHaveBeenCalledWith('endDate', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
|
||||
control.value = 'embargo';
|
||||
comp.setOptions(model, control);
|
||||
expect(formbuilderService.findById).toHaveBeenCalledWith('groupUUID', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
expect(formbuilderService.findById).toHaveBeenCalledWith('startDate', (model.parent as DynamicFormArrayGroupModel).group);
|
||||
});
|
||||
});
|
||||
@@ -208,7 +200,6 @@ class TestComponent {
|
||||
availableAccessConditionOptions;
|
||||
collectionId = mockSubmissionCollectionId;
|
||||
collectionPolicyType;
|
||||
configMetadataForm$;
|
||||
fileIndexes = [];
|
||||
fileList = [];
|
||||
fileNames = [];
|
||||
|
@@ -22,8 +22,6 @@ import {
|
||||
BITSTREAM_ACCESS_CONDITIONS_FORM_ARRAY_LAYOUT,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_CONFIG,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_LAYOUT,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_CONFIG,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_CONFIG,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_LAYOUT,
|
||||
BITSTREAM_FORM_ACCESS_CONDITION_TYPE_CONFIG,
|
||||
@@ -32,14 +30,13 @@ import {
|
||||
BITSTREAM_METADATA_FORM_GROUP_LAYOUT
|
||||
} from './section-upload-file-edit.model';
|
||||
import { POLICY_DEFAULT_WITH_LIST } from '../../section-upload.component';
|
||||
import { isNotEmpty, isNotUndefined } from '../../../../../shared/empty.util';
|
||||
import { isNotEmpty } from '../../../../../shared/empty.util';
|
||||
import { SubmissionFormsModel } from '../../../../../core/config/models/config-submission-forms.model';
|
||||
import { FormFieldModel } from '../../../../../shared/form/builder/models/form-field.model';
|
||||
import { AccessConditionOption } from '../../../../../core/config/models/config-access-condition-option.model';
|
||||
import { SubmissionService } from '../../../../submission.service';
|
||||
import { FormService } from '../../../../../shared/form/form.service';
|
||||
import { FormComponent } from '../../../../../shared/form/form.component';
|
||||
import { Group } from '../../../../../core/eperson/models/group.model';
|
||||
|
||||
/**
|
||||
* This component represents the edit form for bitstream
|
||||
@@ -56,12 +53,6 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
|
||||
*/
|
||||
@Input() availableAccessConditionOptions: any[];
|
||||
|
||||
/**
|
||||
* The list of available groups for an access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
@@ -210,19 +201,16 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
|
||||
});
|
||||
const confStart = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: hasStart }] };
|
||||
const confEnd = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: hasEnd }] };
|
||||
const confGroup = { relations: [{ match: MATCH_ENABLED, operator: OR_OPERATOR, when: hasGroups }] };
|
||||
|
||||
accessConditionsArrayConfig.groupFactory = () => {
|
||||
const type = new DynamicSelectModel(accessConditionTypeModelConfig, BITSTREAM_FORM_ACCESS_CONDITION_TYPE_LAYOUT);
|
||||
const startDateConfig = Object.assign({}, BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_CONFIG, confStart);
|
||||
const endDateConfig = Object.assign({}, BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_CONFIG, confEnd);
|
||||
const groupsConfig = Object.assign({}, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_CONFIG, confGroup);
|
||||
|
||||
const startDate = new DynamicDatePickerModel(startDateConfig, BITSTREAM_FORM_ACCESS_CONDITION_START_DATE_LAYOUT);
|
||||
const endDate = new DynamicDatePickerModel(endDateConfig, BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_LAYOUT);
|
||||
const groups = new DynamicSelectModel(groupsConfig, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT);
|
||||
|
||||
return [type, startDate, endDate, groups];
|
||||
return [type, startDate, endDate];
|
||||
};
|
||||
|
||||
// Number of access conditions blocks in form
|
||||
@@ -244,19 +232,11 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
|
||||
*/
|
||||
public initModelData(formModel: DynamicFormControlModel[]) {
|
||||
this.fileData.accessConditions.forEach((accessCondition, index) => {
|
||||
Array.of('name', 'groupUUID', 'startDate', 'endDate')
|
||||
Array.of('name', 'startDate', 'endDate')
|
||||
.filter((key) => accessCondition.hasOwnProperty(key))
|
||||
.forEach((key) => {
|
||||
const metadataModel: any = this.formBuilderService.findById(key, formModel, index);
|
||||
if (metadataModel) {
|
||||
if (key === 'groupUUID' && this.availableAccessConditionGroups.get(accessCondition.name)) {
|
||||
this.availableAccessConditionGroups.get(accessCondition.name).forEach((group) => {
|
||||
metadataModel.options.push({
|
||||
label: group.name,
|
||||
value: group.uuid
|
||||
});
|
||||
});
|
||||
}
|
||||
if (metadataModel.type === DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER) {
|
||||
const date = new Date(accessCondition[key]);
|
||||
metadataModel.value = {
|
||||
@@ -299,51 +279,18 @@ export class SubmissionSectionUploadFileEditComponent implements OnChanges {
|
||||
if (isNotEmpty(accessCondition)) {
|
||||
const showGroups: boolean = accessCondition.hasStartDate === true || accessCondition.hasEndDate === true;
|
||||
|
||||
const groupControl: FormControl = control.parent.get('groupUUID') as FormControl;
|
||||
const startDateControl: FormControl = control.parent.get('startDate') as FormControl;
|
||||
const endDateControl: FormControl = control.parent.get('endDate') as FormControl;
|
||||
|
||||
// Clear previous state
|
||||
groupControl.markAsUntouched();
|
||||
startDateControl.markAsUntouched();
|
||||
endDateControl.markAsUntouched();
|
||||
|
||||
// Clear previous values
|
||||
if (showGroups) {
|
||||
groupControl.setValue(null);
|
||||
} else {
|
||||
groupControl.clearValidators();
|
||||
groupControl.setValue(accessCondition.groupUUID);
|
||||
}
|
||||
startDateControl.setValue(null);
|
||||
control.parent.markAsDirty();
|
||||
endDateControl.setValue(null);
|
||||
|
||||
if (showGroups) {
|
||||
if (isNotUndefined(accessCondition.groupUUID) || isNotUndefined(accessCondition.selectGroupUUID)) {
|
||||
|
||||
const groupOptions = [];
|
||||
if (isNotUndefined(this.availableAccessConditionGroups.get(accessCondition.name))) {
|
||||
const groupModel = this.formBuilderService.findById(
|
||||
'groupUUID',
|
||||
(model.parent as DynamicFormArrayGroupModel).group) as DynamicSelectModel<any>;
|
||||
|
||||
this.availableAccessConditionGroups.get(accessCondition.name).forEach((group) => {
|
||||
groupOptions.push({
|
||||
label: group.name,
|
||||
value: group.uuid
|
||||
});
|
||||
});
|
||||
|
||||
// Due to a bug can't dynamically change the select options, so replace the model with a new one
|
||||
const confGroup = { relation: groupModel.relations };
|
||||
const groupsConfig = Object.assign({}, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_CONFIG, confGroup);
|
||||
groupsConfig.options = groupOptions;
|
||||
(model.parent as DynamicFormGroupModel).group.pop();
|
||||
(model.parent as DynamicFormGroupModel).group.push(new DynamicSelectModel(groupsConfig, BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT));
|
||||
}
|
||||
|
||||
}
|
||||
if (accessCondition.hasStartDate) {
|
||||
const startDateModel = this.formBuilderService.findById(
|
||||
'startDate',
|
||||
|
@@ -108,32 +108,3 @@ export const BITSTREAM_FORM_ACCESS_CONDITION_END_DATE_LAYOUT: DynamicFormControl
|
||||
host: 'col-md-4'
|
||||
}
|
||||
};
|
||||
|
||||
export const BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_CONFIG: DynamicSelectModelConfig<any> = {
|
||||
id: 'groupUUID',
|
||||
label: 'submission.sections.upload.form.group-label',
|
||||
options: [],
|
||||
relations: [
|
||||
{
|
||||
match: MATCH_ENABLED,
|
||||
operator: OR_OPERATOR,
|
||||
when: []
|
||||
}
|
||||
],
|
||||
required: true,
|
||||
validators: {
|
||||
required: null
|
||||
},
|
||||
errorMessages: {
|
||||
required: 'submission.sections.upload.form.group-required'
|
||||
}
|
||||
};
|
||||
export const BITSTREAM_FORM_ACCESS_CONDITION_GROUPS_LAYOUT: DynamicFormControlLayout = {
|
||||
element: {
|
||||
container: 'p-0',
|
||||
label: 'col-form-label'
|
||||
},
|
||||
grid: {
|
||||
host: 'col-sm-10'
|
||||
}
|
||||
};
|
||||
|
@@ -37,7 +37,6 @@
|
||||
<ds-submission-section-upload-file-view *ngIf="readMode"
|
||||
[fileData]="fileData"></ds-submission-section-upload-file-view>
|
||||
<ds-submission-section-upload-file-edit *ngIf="!readMode"
|
||||
[availableAccessConditionGroups]="availableAccessConditionGroups"
|
||||
[availableAccessConditionOptions]="availableAccessConditionOptions"
|
||||
[collectionId]="collectionId"
|
||||
[collectionPolicyType]="collectionPolicyType"
|
||||
|
@@ -162,7 +162,6 @@ describe('SubmissionSectionUploadFileComponent test suite', () => {
|
||||
comp.collectionId = collectionId;
|
||||
comp.sectionId = sectionId;
|
||||
comp.availableAccessConditionOptions = availableAccessConditionOptions;
|
||||
comp.availableAccessConditionGroups = availableGroupsMap;
|
||||
comp.collectionPolicyType = collectionPolicyType;
|
||||
comp.fileIndex = fileIndex;
|
||||
comp.fileId = fileId;
|
||||
@@ -258,9 +257,9 @@ describe('SubmissionSectionUploadFileComponent test suite', () => {
|
||||
operationsService.jsonPatchByResourceID.and.returnValue(observableOf(response));
|
||||
|
||||
const accessConditionsToSave = [
|
||||
{ name: 'openaccess', groupUUID: '123456-g' },
|
||||
{ name: 'lease', endDate: '2019-01-16T00:00:00Z', groupUUID: '123456-g' },
|
||||
{ name: 'embargo', startDate: '2019-01-16T00:00:00Z', groupUUID: '123456-g' }
|
||||
{ name: 'openaccess' },
|
||||
{ name: 'lease', endDate: '2019-01-16T00:00:00Z' },
|
||||
{ name: 'embargo', startDate: '2019-01-16T00:00:00Z' },
|
||||
];
|
||||
comp.saveBitstreamData(event);
|
||||
tick();
|
||||
|
@@ -12,7 +12,6 @@ import { JsonPatchOperationsBuilder } from '../../../../core/json-patch/builder/
|
||||
import { JsonPatchOperationPathCombiner } from '../../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { WorkspaceitemSectionUploadFileObject } from '../../../../core/submission/models/workspaceitem-section-upload-file.model';
|
||||
import { SubmissionFormsModel } from '../../../../core/config/models/config-submission-forms.model';
|
||||
import { deleteProperty } from '../../../../shared/object.util';
|
||||
import { dateToISOFormat } from '../../../../shared/date.util';
|
||||
import { SubmissionService } from '../../../submission.service';
|
||||
import { FileService } from '../../../../core/shared/file.service';
|
||||
@@ -21,7 +20,6 @@ import { SubmissionJsonPatchOperationsService } from '../../../../core/submissio
|
||||
import { SubmissionObject } from '../../../../core/submission/models/submission-object.model';
|
||||
import { WorkspaceitemSectionUploadObject } from '../../../../core/submission/models/workspaceitem-section-upload.model';
|
||||
import { SubmissionSectionUploadFileEditComponent } from './edit/section-upload-file-edit.component';
|
||||
import { Group } from '../../../../core/eperson/models/group.model';
|
||||
|
||||
/**
|
||||
* This component represents a single bitstream contained in the submission
|
||||
@@ -39,12 +37,6 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit {
|
||||
*/
|
||||
@Input() availableAccessConditionOptions: any[];
|
||||
|
||||
/**
|
||||
* The list of available groups for an access condition
|
||||
* @type {Array}
|
||||
*/
|
||||
@Input() availableAccessConditionGroups: Map<string, Group[]>;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
@@ -172,7 +164,7 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit {
|
||||
* Retrieve bitstream's metadata
|
||||
*/
|
||||
ngOnChanges() {
|
||||
if (this.availableAccessConditionOptions && this.availableAccessConditionGroups) {
|
||||
if (this.availableAccessConditionOptions) {
|
||||
// Retrieve file state
|
||||
this.subscriptions.push(
|
||||
this.uploadService
|
||||
@@ -272,28 +264,17 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit {
|
||||
.forEach((element) => accessConditionOpt = element);
|
||||
|
||||
if (accessConditionOpt) {
|
||||
|
||||
if (accessConditionOpt.hasStartDate !== true && accessConditionOpt.hasEndDate !== true) {
|
||||
accessConditionOpt = deleteProperty(accessConditionOpt, 'hasStartDate');
|
||||
|
||||
accessConditionOpt = deleteProperty(accessConditionOpt, 'hasEndDate');
|
||||
accessConditionsToSave.push(accessConditionOpt);
|
||||
} else {
|
||||
accessConditionOpt = Object.assign({}, accessCondition);
|
||||
accessConditionOpt.name = this.retrieveValueFromField(accessCondition.name);
|
||||
accessConditionOpt.groupUUID = this.retrieveValueFromField(accessCondition.groupUUID);
|
||||
if (accessCondition.startDate) {
|
||||
const startDate = this.retrieveValueFromField(accessCondition.startDate);
|
||||
accessConditionOpt.startDate = dateToISOFormat(startDate);
|
||||
accessConditionOpt = deleteProperty(accessConditionOpt, 'endDate');
|
||||
}
|
||||
if (accessCondition.endDate) {
|
||||
const endDate = this.retrieveValueFromField(accessCondition.endDate);
|
||||
accessConditionOpt.endDate = dateToISOFormat(endDate);
|
||||
accessConditionOpt = deleteProperty(accessConditionOpt, 'startDate');
|
||||
}
|
||||
accessConditionsToSave.push(accessConditionOpt);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
|
||||
<ng-container *ngFor="let fileEntry of fileList">
|
||||
<ds-submission-upload-section-file [availableAccessConditionGroups]="availableGroups"
|
||||
<ds-submission-upload-section-file
|
||||
[availableAccessConditionOptions]="availableAccessConditionOptions"
|
||||
[collectionId]="collectionId"
|
||||
[collectionPolicyType]="collectionPolicyType"
|
||||
|
@@ -260,8 +260,6 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any);
|
||||
expect(comp.required$.getValue()).toBe(true);
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(compAsAny.availableGroups.size).toBe(2);
|
||||
expect(compAsAny.availableGroups).toEqual(expectedGroupsMap);
|
||||
expect(compAsAny.fileList).toEqual([]);
|
||||
expect(compAsAny.fileIndexes).toEqual([]);
|
||||
expect(compAsAny.fileNames).toEqual([]);
|
||||
@@ -298,8 +296,6 @@ describe('SubmissionSectionUploadComponent test suite', () => {
|
||||
expect(comp.availableAccessConditionOptions).toEqual(mockUploadConfigResponse.accessConditionOptions as any);
|
||||
expect(comp.required$.getValue()).toBe(true);
|
||||
expect(compAsAny.subs.length).toBe(2);
|
||||
expect(compAsAny.availableGroups.size).toBe(2);
|
||||
expect(compAsAny.availableGroups).toEqual(expectedGroupsMap);
|
||||
expect(compAsAny.fileList).toEqual(mockUploadFiles);
|
||||
expect(compAsAny.fileIndexes).toEqual(['123456-test-upload']);
|
||||
expect(compAsAny.fileNames).toEqual(['123456-test-upload.jpg']);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ChangeDetectorRef, Component, Inject } from '@angular/core';
|
||||
|
||||
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged, filter, find, map, mergeMap, reduce, switchMap, tap } from 'rxjs/operators';
|
||||
import { distinctUntilChanged, filter, map, mergeMap, switchMap, tap } from 'rxjs/operators';
|
||||
|
||||
import { SectionModelComponent } from '../models/section.model';
|
||||
import { hasValue, isNotEmpty, isNotUndefined, isUndefined } from '../../../shared/empty.util';
|
||||
@@ -23,7 +23,6 @@ import { SectionsService } from '../sections.service';
|
||||
import { SubmissionService } from '../../submission.service';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { AccessConditionOption } from '../../../core/config/models/config-access-condition-option.model';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||
import { followLink } from '../../../shared/utils/follow-link-config.model';
|
||||
import { getFirstSucceededRemoteData } from '../../../core/shared/operators';
|
||||
|
||||
@@ -100,11 +99,6 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
*/
|
||||
public availableAccessConditionOptions: AccessConditionOption[]; // List of accessConditions that an user can select
|
||||
|
||||
/**
|
||||
* List of Groups available for every access condition
|
||||
*/
|
||||
public availableGroups: Map<string, Group[]>; // Groups for any policy
|
||||
|
||||
/**
|
||||
* Is the upload required
|
||||
* @type {boolean}
|
||||
@@ -184,53 +178,12 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
|
||||
}
|
||||
}),*/
|
||||
mergeMap(() => config$),
|
||||
mergeMap((config: SubmissionUploadsModel) => {
|
||||
this.required$.next(config.required);
|
||||
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];
|
||||
|
||||
this.collectionPolicyType = this.availableAccessConditionOptions.length > 0
|
||||
? POLICY_DEFAULT_WITH_LIST
|
||||
: POLICY_DEFAULT_NO_LIST;
|
||||
|
||||
this.availableGroups = new Map();
|
||||
const mapGroups$: Observable<AccessConditionGroupsMapEntry>[] = [];
|
||||
// Retrieve Groups for accessCondition Policies
|
||||
this.availableAccessConditionOptions.forEach((accessCondition: AccessConditionOption) => {
|
||||
if (accessCondition.hasEndDate === true || accessCondition.hasStartDate === true) {
|
||||
if (accessCondition.groupUUID) {
|
||||
mapGroups$.push(
|
||||
this.groupService.findById(accessCondition.groupUUID).pipe(
|
||||
find((rd: RemoteData<Group>) => !rd.isResponsePending && rd.hasSucceeded),
|
||||
map((rd: RemoteData<Group>) => ({
|
||||
accessCondition: accessCondition.name,
|
||||
groups: [rd.payload]
|
||||
} as AccessConditionGroupsMapEntry)))
|
||||
);
|
||||
} else if (accessCondition.selectGroupUUID) {
|
||||
mapGroups$.push(
|
||||
this.groupService.findById(accessCondition.selectGroupUUID).pipe(
|
||||
find((rd: RemoteData<Group>) => !rd.isResponsePending && rd.hasSucceeded),
|
||||
mergeMap((group: RemoteData<Group>) => group.payload.subgroups),
|
||||
find((rd: RemoteData<PaginatedList<Group>>) => !rd.isResponsePending && rd.hasSucceeded),
|
||||
map((rd: RemoteData<PaginatedList<Group>>) => ({
|
||||
accessCondition: accessCondition.name,
|
||||
groups: rd.payload.page
|
||||
} as AccessConditionGroupsMapEntry))
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
return mapGroups$;
|
||||
}),
|
||||
mergeMap((entry) => entry),
|
||||
reduce((acc: any[], entry: AccessConditionGroupsMapEntry) => {
|
||||
acc.push(entry);
|
||||
return acc;
|
||||
}, []),
|
||||
).subscribe((entries: AccessConditionGroupsMapEntry[]) => {
|
||||
entries.forEach((entry: AccessConditionGroupsMapEntry) => {
|
||||
this.availableGroups.set(entry.accessCondition, entry.groups);
|
||||
});
|
||||
).subscribe((config: SubmissionUploadsModel) => {
|
||||
this.required$.next(config.required);
|
||||
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];
|
||||
this.collectionPolicyType = this.availableAccessConditionOptions.length > 0
|
||||
? POLICY_DEFAULT_WITH_LIST
|
||||
: POLICY_DEFAULT_NO_LIST;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}),
|
||||
|
||||
|
Reference in New Issue
Block a user