Show only authorized collections list during submission

This commit is contained in:
Giuseppe Digilio
2019-07-04 11:17:56 +02:00
parent 395509a19a
commit ed959e492a
3 changed files with 41 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ import { Observable } from 'rxjs/internal/Observable';
import { FindAllOptions } from './request.models';
import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list';
import { SearchParam } from '../cache/models/search-param.model';
@Injectable()
export class CollectionDataService extends ComColDataService<Collection> {
@@ -40,6 +41,22 @@ export class CollectionDataService extends ComColDataService<Collection> {
super();
}
/**
* Get all collections whom user has authorization to submit to by community
*
* @return boolean
* true if the user has at least one collection to submit to
*/
getAuthorizedCollectionByCommunity(communityId): Observable<RemoteData<PaginatedList<Collection>>> {
const searchHref = 'findAuthorizedByCommunity';
const options = new FindAllOptions();
options.elementsPerPage = 1000;
options.searchParams = [new SearchParam('uuid', communityId)];
return this.searchBy(searchHref, options).pipe(
filter((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending));
}
/**
* Find whether there is a collection whom user has authorization to submit to
*

View File

@@ -8,6 +8,7 @@ import { filter } from 'rxjs/operators';
import { TranslateModule } from '@ngx-translate/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { Store } from '@ngrx/store';
import { cold } from 'jasmine-marbles';
import { SubmissionServiceStub } from '../../../shared/testing/submission-service-stub';
import { mockSubmissionId, mockSubmissionRestResponse } from '../../../shared/mocks/mock-submission';
@@ -24,7 +25,7 @@ import { PaginatedList } from '../../../core/data/paginated-list';
import { PageInfo } from '../../../core/shared/page-info.model';
import { Collection } from '../../../core/shared/collection.model';
import { createTestComponent } from '../../../shared/testing/utils';
import { cold } from 'jasmine-marbles';
import { CollectionDataService } from '../../../core/data/collection-data.service';
const subcommunities = [Object.assign(new Community(), {
name: 'SubCommunity 1',
@@ -125,6 +126,12 @@ const mockCommunity2 = Object.assign(new Community(), {
const mockCommunityList = observableOf(new RemoteData(true, true, true,
undefined, new PaginatedList(new PageInfo(), [mockCommunity, mockCommunity2])));
const mockCommunityCollectionList = observableOf(new RemoteData(true, true, true,
undefined, new PaginatedList(new PageInfo(), [mockCommunity1Collection1, mockCommunity1Collection2])));
const mockCommunity2CollectionList = observableOf(new RemoteData(true, true, true,
undefined, new PaginatedList(new PageInfo(), [mockCommunity2Collection1, mockCommunity2Collection2])));
const mockCollectionList = [
{
communities: [
@@ -193,6 +200,11 @@ describe('SubmissionFormCollectionComponent Component', () => {
const communityDataService: any = jasmine.createSpyObj('communityDataService', {
findAll: jasmine.createSpy('findAll')
});
const collectionDataService: any = jasmine.createSpyObj('collectionDataService', {
getAuthorizedCollectionByCommunity: jasmine.createSpy('getAuthorizedCollectionByCommunity')
});
const store: any = jasmine.createSpyObj('store', {
dispatch: jasmine.createSpy('dispatch'),
select: jasmine.createSpy('select')
@@ -214,6 +226,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
TestComponent
],
providers: [
{ provide: CollectionDataService, useValue: collectionDataService },
{ provide: SubmissionJsonPatchOperationsService, useClass: SubmissionJsonPatchOperationsServiceStub },
{ provide: SubmissionService, useClass: SubmissionServiceStub },
{ provide: CommunityDataService, useValue: communityDataService },
@@ -284,6 +297,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
it('should init collection list properly', () => {
communityDataService.findAll.and.returnValue(mockCommunityList);
collectionDataService.getAuthorizedCollectionByCommunity.and.returnValues(mockCommunityCollectionList, mockCommunity2CollectionList);
comp.ngOnChanges({
currentCollectionId: new SimpleChange(null, collectionId, true)

View File

@@ -35,6 +35,8 @@ import { PaginatedList } from '../../../core/data/paginated-list';
import { SubmissionService } from '../../submission.service';
import { SubmissionObject } from '../../../core/submission/models/submission-object.model';
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
import { CollectionDataService } from '../../../core/data/collection-data.service';
import { FindAllOptions } from '../../../core/data/request.models';
/**
* An interface to represent a collection entry
@@ -145,12 +147,14 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
*
* @param {ChangeDetectorRef} cdr
* @param {CommunityDataService} communityDataService
* @param {CollectionDataService} collectionDataService
* @param {JsonPatchOperationsBuilder} operationsBuilder
* @param {SubmissionJsonPatchOperationsService} operationsService
* @param {SubmissionService} submissionService
*/
constructor(protected cdr: ChangeDetectorRef,
private communityDataService: CommunityDataService,
private collectionDataService: CollectionDataService,
private operationsBuilder: JsonPatchOperationsBuilder,
private operationsService: SubmissionJsonPatchOperationsService,
private submissionService: SubmissionService) {
@@ -189,16 +193,19 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
if (hasValue(changes.currentCollectionId)
&& hasValue(changes.currentCollectionId.currentValue)) {
this.selectedCollectionId = this.currentCollectionId;
const findOptions: FindAllOptions = {
elementsPerPage: 100
};
// @TODO replace with search/top browse endpoint
// @TODO implement community/subcommunity hierarchy
const communities$ = this.communityDataService.findAll().pipe(
const communities$ = this.communityDataService.findAll(findOptions).pipe(
find((communities: RemoteData<PaginatedList<Community>>) => isNotEmpty(communities.payload)),
mergeMap((communities: RemoteData<PaginatedList<Community>>) => communities.payload.page));
const listCollection$ = communities$.pipe(
flatMap((communityData: Community) => {
return communityData.collections.pipe(
return this.collectionDataService.getAuthorizedCollectionByCommunity(communityData.uuid).pipe(
find((collections: RemoteData<PaginatedList<Collection>>) => !collections.isResponsePending && collections.hasSucceeded),
mergeMap((collections: RemoteData<PaginatedList<Collection>>) => collections.payload.page),
filter((collectionData: Collection) => isNotEmpty(collectionData)),