diff --git a/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts b/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts index 8384385572..b5e03b7983 100644 --- a/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts +++ b/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.spec.ts @@ -30,24 +30,27 @@ describe('CollectionRolesComponent', () => { undefined, Object.assign(new Collection(), { _links: { - 'irrelevant': { + irrelevant: { href: 'irrelevant link', }, - 'adminGroup': { + adminGroup: { href: 'adminGroup link', }, - 'submittersGroup': { + submittersGroup: { href: 'submittersGroup link', }, - 'itemReadGroup': { + itemReadGroup: { href: 'itemReadGroup link', }, - 'bitstreamReadGroup': { + bitstreamReadGroup: { href: 'bitstreamReadGroup link', }, - 'workflowGroups/test': { - href: 'test workflow group link', - }, + workflowGroups: [ + { + name: 'test', + href: 'test workflow group link', + }, + ], }, }), ), diff --git a/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.ts b/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.ts index 45f2f37b9b..996933e43d 100644 --- a/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.ts +++ b/src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.ts @@ -5,7 +5,7 @@ import { first, map } from 'rxjs/operators'; import { RemoteData } from '../../../core/data/remote-data'; import { Collection } from '../../../core/shared/collection.model'; import { getRemoteDataPayload, getSucceededRemoteData } from '../../../core/shared/operators'; -import { ComcolRole } from '../../../shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role'; +import { HALLink } from '../../../core/shared/hal-link.model'; /** * Component for managing a collection's roles @@ -31,19 +31,27 @@ export class CollectionRolesComponent implements OnInit { /** * The different roles for the collection, as an observable. */ - getComcolRoles(): Observable { + getComcolRoles(): Observable { return this.collection$.pipe( - map((collection) => - [ - ComcolRole.COLLECTION_ADMIN, - ComcolRole.SUBMITTERS, - ComcolRole.ITEM_READ, - ComcolRole.BITSTREAM_READ, - ...Object.keys(collection._links) - .filter((link) => link.startsWith('workflowGroups/')) - .map((link) => new ComcolRole(link.substr('workflowGroups/'.length), link)), - ] - ), + map((collection) => [ + { + name: 'collection-admin', + href: collection._links.adminGroup.href, + }, + { + name: 'submitters', + href: collection._links.submittersGroup.href, + }, + { + name: 'item_read', + href: collection._links.itemReadGroup.href, + }, + { + name: 'bitstream_read', + href: collection._links.bitstreamReadGroup.href, + }, + ...collection._links.workflowGroups, + ]), ); } diff --git a/src/app/+community-page/edit-community-page/community-roles/community-roles.component.html b/src/app/+community-page/edit-community-page/community-roles/community-roles.component.html index 231645a6a5..07d5d96fcd 100644 --- a/src/app/+community-page/edit-community-page/community-roles/community-roles.component.html +++ b/src/app/+community-page/edit-community-page/community-roles/community-roles.component.html @@ -1,5 +1,5 @@ diff --git a/src/app/+community-page/edit-community-page/community-roles/community-roles.component.ts b/src/app/+community-page/edit-community-page/community-roles/community-roles.component.ts index 336a56a584..62e1f73bad 100644 --- a/src/app/+community-page/edit-community-page/community-roles/community-roles.component.ts +++ b/src/app/+community-page/edit-community-page/community-roles/community-roles.component.ts @@ -4,8 +4,8 @@ import { Observable } from 'rxjs'; import { first, map } from 'rxjs/operators'; import { Community } from '../../../core/shared/community.model'; import { getRemoteDataPayload, getSucceededRemoteData } from '../../../core/shared/operators'; -import { ComcolRole } from '../../../shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role'; import { RemoteData } from '../../../core/data/remote-data'; +import { HALLink } from '../../../core/shared/hal-link.model'; /** * Component for managing a community's roles @@ -31,10 +31,15 @@ export class CommunityRolesComponent implements OnInit { /** * The different roles for the community. */ - getComcolRoles(): ComcolRole[] { - return [ - ComcolRole.COMMUNITY_ADMIN, - ]; + getComcolRoles$(): Observable { + return this.community$.pipe( + map((community) => [ + { + name: 'community-admin', + href: community._links.adminGroup.href, + }, + ]), + ); } constructor( diff --git a/src/app/core/eperson/group-data.service.ts b/src/app/core/eperson/group-data.service.ts index a10b46c3d0..c186bc8dcd 100644 --- a/src/app/core/eperson/group-data.service.ts +++ b/src/app/core/eperson/group-data.service.ts @@ -40,7 +40,6 @@ import { GROUP } from './models/group.resource-type'; import { DSONameService } from '../breadcrumbs/dso-name.service'; import { Community } from '../shared/community.model'; import { Collection } from '../shared/collection.model'; -import { ComcolRole } from '../../shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role'; const groupRegistryStateSelector = (state: AppState) => state.groupRegistry; const editGroupSelector = createSelector(groupRegistryStateSelector, (groupRegistryState: GroupRegistryState) => groupRegistryState.editGroup); @@ -324,16 +323,17 @@ export class GroupDataService extends DataService { * Create a group for a given role for a given community or collection. * * @param dso The community or collection for which to create a group + * @param role The name of the role for which to create a group * @param link The REST endpoint to create the group */ - createComcolGroup(dso: Community|Collection, link: string): Observable { + createComcolGroup(dso: Community|Collection, role: string, link: string): Observable { const requestId = this.requestService.generateRequestId(); const group = Object.assign(new Group(), { metadata: { 'dc.description': [ { - value: `${this.nameService.getName(dso)} admin group`, + value: `${this.nameService.getName(dso)} ${role} group`, } ], }, diff --git a/src/app/core/shared/collection.model.ts b/src/app/core/shared/collection.model.ts index b65ac252ef..c1464d7d39 100644 --- a/src/app/core/shared/collection.model.ts +++ b/src/app/core/shared/collection.model.ts @@ -15,8 +15,6 @@ import { RESOURCE_POLICY } from '../resource-policy/models/resource-policy.resou import { COMMUNITY } from './community.resource-type'; import { Community } from './community.model'; import { ChildHALResource } from './child-hal-resource.model'; -import { GROUP } from '../eperson/models/group.resource-type'; -import { Group } from '../eperson/models/group.model'; @typedObject @inheritSerialization(DSpaceObject) @@ -41,6 +39,11 @@ export class Collection extends DSpaceObject implements ChildHALResource { defaultAccessConditions: HALLink; logo: HALLink; parentCommunity: HALLink; + workflowGroups: HALLink[]; + adminGroup: HALLink; + submittersGroup: HALLink; + itemReadGroup: HALLink; + bitstreamReadGroup: HALLink; self: HALLink; }; @@ -72,12 +75,6 @@ export class Collection extends DSpaceObject implements ChildHALResource { @link(COMMUNITY, false) parentCommunity?: Observable>; - /** - * The administrators group of this community. - */ - @link(GROUP) - adminGroup?: Observable>; - /** * The introductory text of this Collection * Corresponds to the metadata field dc.description diff --git a/src/app/core/shared/community.model.ts b/src/app/core/shared/community.model.ts index bdcda70e9b..796aaa8ece 100644 --- a/src/app/core/shared/community.model.ts +++ b/src/app/core/shared/community.model.ts @@ -3,8 +3,6 @@ import { Observable } from 'rxjs'; import { link, typedObject } from '../cache/builders/build-decorators'; import { PaginatedList } from '../data/paginated-list'; import { RemoteData } from '../data/remote-data'; -import { Group } from '../eperson/models/group.model'; -import { GROUP } from '../eperson/models/group.resource-type'; import { Bitstream } from './bitstream.model'; import { BITSTREAM } from './bitstream.resource-type'; import { Collection } from './collection.model'; @@ -66,12 +64,6 @@ export class Community extends DSpaceObject implements ChildHALResource { @link(COMMUNITY, false) parentCommunity?: Observable>; - /** - * The administrators group of this community. - */ - @link(GROUP) - adminGroup?: Observable>; - /** * The introductory text of this Community * Corresponds to the metadata field dc.description diff --git a/src/app/core/shared/hal-resource.model.ts b/src/app/core/shared/hal-resource.model.ts index 334509007b..6e4fe1f502 100644 --- a/src/app/core/shared/hal-resource.model.ts +++ b/src/app/core/shared/hal-resource.model.ts @@ -22,6 +22,6 @@ export class HALResource { /** * {@link HALLink}s to related {@link HALResource}s */ - [k: string]: HALLink; + [k: string]: HALLink | HALLink[]; }; } diff --git a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts b/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts index 4694c13603..6604667a98 100644 --- a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts +++ b/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts @@ -4,13 +4,11 @@ import { GroupDataService } from '../../../../core/eperson/group-data.service'; import { By } from '@angular/platform-browser'; import { SharedModule } from '../../../shared.module'; import { TranslateModule } from '@ngx-translate/core'; -import { ChangeDetectorRef, DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; import { RequestService } from '../../../../core/data/request.service'; -import { ComcolRole } from './comcol-role'; import { of as observableOf } from 'rxjs/internal/observable/of'; import { RemoteData } from '../../../../core/data/remote-data'; import { RouterTestingModule } from '@angular/router/testing'; -import { Collection } from '../../../../core/shared/collection.model'; describe('ComcolRoleComponent', () => { @@ -65,20 +63,10 @@ describe('ComcolRoleComponent', () => { comp = fixture.componentInstance; de = fixture.debugElement; - comp.comcolRole = new ComcolRole( - 'test role name', - 'test role endpoint', - ); - - comp.dso = Object.assign( - new Collection(), { - _links: { - 'test role endpoint': { - href: 'test role link', - } - } - } - ); + comp.comcolRole = { + name: 'test role name', + href: 'test role link', + }; fixture.detectChanges(); }); @@ -138,7 +126,7 @@ describe('ComcolRoleComponent', () => { }); it('should call the groupService create method', () => { - expect(groupService.createComcolGroup).toHaveBeenCalledWith(comp.dso, 'test role link'); + expect(groupService.createComcolGroup).toHaveBeenCalledWith(comp.dso, 'test role name', 'test role link'); }); }); }); diff --git a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts b/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts index 41cb7e7cd2..986d616c7d 100644 --- a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts +++ b/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts @@ -7,9 +7,9 @@ import { GroupDataService } from '../../../../core/eperson/group-data.service'; import { Collection } from '../../../../core/shared/collection.model'; import { filter, map } from 'rxjs/operators'; import { getRemoteDataPayload, getSucceededRemoteData } from '../../../../core/shared/operators'; -import { ComcolRole } from './comcol-role'; import { RequestService } from '../../../../core/data/request.service'; import { RemoteData } from '../../../../core/data/remote-data'; +import { HALLink } from '../../../../core/shared/hal-link.model'; /** * Component for managing a community or collection role. @@ -31,7 +31,7 @@ export class ComcolRoleComponent implements OnInit { * The role to manage */ @Input() - comcolRole: ComcolRole; + comcolRole: HALLink; constructor( protected requestService: RequestService, @@ -43,7 +43,7 @@ export class ComcolRoleComponent implements OnInit { * The link to the related group. */ get groupLink(): string { - return this.dso._links[this.comcolRole.linkName].href; + return this.comcolRole.href; } /** @@ -106,7 +106,7 @@ export class ComcolRoleComponent implements OnInit { * Create a group for this community or collection role. */ create() { - this.groupService.createComcolGroup(this.dso, this.groupLink).subscribe(); + this.groupService.createComcolGroup(this.dso, this.comcolRole.name, this.groupLink).subscribe(); } /** diff --git a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.ts b/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.ts deleted file mode 100644 index 2ac74fe67b..0000000000 --- a/src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { Community } from '../../../../core/shared/community.model'; -import { Collection } from '../../../../core/shared/collection.model'; - -/** - * Class representing a community or collection role. - */ -export class ComcolRole { - - /** - * The community admin role. - */ - public static COMMUNITY_ADMIN = new ComcolRole( - 'community-admin', - 'adminGroup', - ); - - /** - * The collection admin role. - */ - public static COLLECTION_ADMIN = new ComcolRole( - 'collection-admin', - 'adminGroup', - ); - - /** - * The submitters role. - */ - public static SUBMITTERS = new ComcolRole( - 'submitters', - 'submittersGroup', - ); - - /** - * The default item read role. - */ - public static ITEM_READ = new ComcolRole( - 'item_read', - 'itemReadGroup', - ); - - /** - * The default bitstream read role. - */ - public static BITSTREAM_READ = new ComcolRole( - 'bitstream_read', - 'bitstreamReadGroup', - ); - - /** - * @param name The name for this community or collection role. - * @param linkName The path linking to this community or collection role. - */ - constructor( - public name, - public linkName, - ) { - } - - /** - * Get the REST endpoint for managing this role for a given community or collection. - * @param dso - */ - public getEndpoint(dso: Community | Collection) { - - let linkPath; - switch (dso.type + '') { - case 'community': - linkPath = 'communities'; - break; - case 'collection': - linkPath = 'collections'; - break; - } - - return `${linkPath}/${dso.uuid}/${this.linkName}`; - } -}