+
-
-
{{'community.edit.tabs.roles.' + comcolRole.name + '.name' | translate}}
+
+ {{'comcol-role.edit.' + comcolRole.name + '.name' | translate}}
+
+
+
+
+
+ {{'comcol-role.edit.no-group' | translate}}
+
+
+ {{'comcol-role.edit.' + comcolRole.name + '.anonymous-group' | translate}}
+
+
+ {{group.name}}
+
-
-
-
- {{'community.edit.tabs.roles.none' | translate}}
-
-
-
- {{group.name}}
-
-
- create
-
-
- delete
-
-
-
+
+
+ {{'comcol-role.edit.create' | translate}}
+
+
+ {{'comcol-role.edit.restrict' | translate}}
+
+
+ {{'comcol-role.edit.delete' | translate}}
+
+
- {{'community.edit.tabs.roles.' + comcolRole.name + '.description' | translate}}
+ {{'comcol-role.edit.' + comcolRole.name + '.description' | translate}}
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 4750da34bb..4a36509410 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
@@ -6,33 +6,47 @@ import { SharedModule } from '../../../shared.module';
import { TranslateModule } from '@ngx-translate/core';
import { ChangeDetectorRef, DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
import { RequestService } from '../../../../core/data/request.service';
-import { LinkService } from '../../../../core/cache/builders/link.service';
-import { Community } from '../../../../core/shared/community.model';
import { ComcolRole } from './comcol-role';
import { of as observableOf } from 'rxjs/internal/observable/of';
import { RemoteData } from '../../../../core/data/remote-data';
-import { Group } from '../../../../core/eperson/models/group.model';
import { RouterTestingModule } from '@angular/router/testing';
+import { Collection } from '../../../../core/shared/collection.model';
describe('ComcolRoleComponent', () => {
let fixture: ComponentFixture
;
let comp: ComcolRoleComponent;
let de: DebugElement;
+
+ let requestService;
let groupService;
- let linkService;
+
+ let group;
+ let statusCode;
beforeEach(() => {
- groupService = jasmine.createSpyObj('groupService', {
- createComcolGroup: undefined,
- deleteComcolGroup: undefined,
- });
+ requestService = {hasByHrefObservable: () => observableOf(true)};
- linkService = {
- resolveLink: () => undefined,
+ groupService = {
+ findByHref: () => undefined,
+ createComcolGroup: jasmine.createSpy('createComcolGroup'),
+ deleteComcolGroup: jasmine.createSpy('deleteComcolGroup'),
};
+ spyOn(groupService, 'findByHref').and.callFake((link) => {
+ if (link === 'test role link') {
+ return observableOf(new RemoteData(
+ false,
+ false,
+ true,
+ undefined,
+ group,
+ statusCode,
+ ));
+ }
+ });
+
TestBed.configureTestingModule({
imports: [
SharedModule,
@@ -41,9 +55,8 @@ describe('ComcolRoleComponent', () => {
],
providers: [
{ provide: GroupDataService, useValue: groupService },
- { provide: LinkService, useValue: linkService },
{ provide: ChangeDetectorRef, useValue: {} },
- { provide: RequestService, useValue: {} },
+ { provide: RequestService, useValue: requestService },
], schemas: [
NO_ERRORS_SCHEMA
]
@@ -54,20 +67,38 @@ describe('ComcolRoleComponent', () => {
de = fixture.debugElement;
comp.comcolRole = new ComcolRole(
- 'test name',
- 'test link name',
+ 'test role name',
+ 'test role endpoint',
);
- comp.dso = new Community();
+ comp.dso = Object.assign(
+ new Collection(), {
+ _links: {
+ 'test role endpoint': {
+ href: 'test role link',
+ }
+ }
+ }
+ );
fixture.detectChanges();
});
describe('when there is no group yet', () => {
- it('should have a create button but no delete button', () => {
- expect(de.query(By.css('.btn.create'))).toBeDefined();
- expect(de.query(By.css('.btn.delete'))).toBeNull();
+ beforeEach(() => {
+ group = null;
+ statusCode = 204;
+ fixture.detectChanges();
+ });
+
+ it('should have a create button but no restrict or delete button', () => {
+ expect(de.query(By.css('.btn.create')))
+ .toBeTruthy();
+ expect(de.query(By.css('.btn.restrict')))
+ .toBeNull();
+ expect(de.query(By.css('.btn.delete')))
+ .toBeNull();
});
describe('when the create button is pressed', () => {
@@ -82,25 +113,54 @@ describe('ComcolRoleComponent', () => {
});
});
- describe('when there is a group yet', () => {
+ describe('when the related group is the Anonymous group', () => {
beforeEach(() => {
- Object.assign(comp.dso, {
- 'test link name': observableOf(new RemoteData(
- false,
- false,
- true,
- undefined,
- new Group(),
- )),
- });
-
+ group = {
+ name: 'Anonymous'
+ };
+ statusCode = 200;
fixture.detectChanges();
});
- it('should have a delete button but no create button', () => {
- expect(de.query(By.css('.btn.delete'))).toBeDefined();
- expect(de.query(By.css('.btn.create'))).toBeNull();
+ it('should have a restrict button but no create or delete button', () => {
+ expect(de.query(By.css('.btn.create')))
+ .toBeNull();
+ expect(de.query(By.css('.btn.restrict')))
+ .toBeTruthy();
+ expect(de.query(By.css('.btn.delete')))
+ .toBeNull();
+ });
+
+ describe('when the restrict button is pressed', () => {
+
+ beforeEach(() => {
+ de.query(By.css('.btn.restrict')).nativeElement.click();
+ });
+
+ it('should call the groupService create method', () => {
+ expect(groupService.createComcolGroup).toHaveBeenCalledWith(comp.dso, 'test role link');
+ });
+ });
+ });
+
+ describe('when the related group is a custom group', () => {
+
+ beforeEach(() => {
+ group = {
+ name: 'custom group name'
+ };
+ statusCode = 200;
+ fixture.detectChanges();
+ });
+
+ it('should have a delete button but no create or restrict button', () => {
+ expect(de.query(By.css('.btn.create')))
+ .toBeNull();
+ expect(de.query(By.css('.btn.restrict')))
+ .toBeNull();
+ expect(de.query(By.css('.btn.delete')))
+ .toBeTruthy();
});
describe('when the delete button is pressed', () => {
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 044e2568e1..41cb7e7cd2 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
@@ -1,16 +1,15 @@
-import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
+import { Component, Input, OnInit } from '@angular/core';
import { Group } from '../../../../core/eperson/models/group.model';
import { Community } from '../../../../core/shared/community.model';
-import { EMPTY, Observable } from 'rxjs';
+import { Observable } from 'rxjs';
import { getGroupEditPath } from '../../../../+admin/admin-access-control/admin-access-control-routing.module';
import { GroupDataService } from '../../../../core/eperson/group-data.service';
import { Collection } from '../../../../core/shared/collection.model';
-import { map } from 'rxjs/operators';
-import { followLink } from '../../../utils/follow-link-config.model';
-import { LinkService } from '../../../../core/cache/builders/link.service';
+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';
/**
* Component for managing a community or collection role.
@@ -35,24 +34,34 @@ export class ComcolRoleComponent implements OnInit {
comcolRole: ComcolRole;
constructor(
- protected groupService: GroupDataService,
- protected linkService: LinkService,
- protected cdr: ChangeDetectorRef,
protected requestService: RequestService,
+ protected groupService: GroupDataService,
) {
}
/**
- * The group for this role as an observable.
+ * The link to the related group.
+ */
+ get groupLink(): string {
+ return this.dso._links[this.comcolRole.linkName].href;
+ }
+
+ /**
+ * The group for this role, as an observable remote data.
+ */
+ get groupRD$(): Observable> {
+ return this.groupService.findByHref(this.groupLink).pipe(
+ filter((groupRD) => !!groupRD.statusCode),
+ );
+ }
+
+ /**
+ * The group for this role, as an observable.
*/
get group$(): Observable {
-
- if (!this.dso[this.comcolRole.linkName]) {
- return EMPTY;
- }
-
- return this.dso[this.comcolRole.linkName].pipe(
+ return this.groupRD$.pipe(
getSucceededRemoteData(),
+ filter((groupRD) => groupRD != null),
getRemoteDataPayload(),
);
}
@@ -66,29 +75,52 @@ export class ComcolRoleComponent implements OnInit {
);
}
+ /**
+ * Return true if there is no group for this ComcolRole, as an observable.
+ */
+ hasNoGroup$(): Observable {
+ return this.groupRD$.pipe(
+ map((groupRD) => groupRD.statusCode === 204),
+ )
+ }
+
+ /**
+ * Return true if the group for this ComcolRole is the Anonymous group, as an observable.
+ */
+ hasAnonymousGroup$(): Observable {
+ return this.group$.pipe(
+ map((group) => group.name === 'Anonymous'),
+ )
+ }
+
+ /**
+ * Return true if there is a group for this ComcolRole other than the Anonymous group, as an observable.
+ */
+ hasCustomGroup$(): Observable {
+ return this.hasAnonymousGroup$().pipe(
+ map((anonymous) => !anonymous),
+ )
+ }
+
/**
* Create a group for this community or collection role.
*/
create() {
-
- this.groupService.createComcolGroup(this.dso, this.comcolRole)
- .subscribe(() => {
- this.linkService.resolveLink(this.dso, followLink(this.comcolRole.linkName));
- this.cdr.detectChanges();
- });
+ this.groupService.createComcolGroup(this.dso, this.groupLink).subscribe();
}
/**
* Delete the group for this community or collection role.
*/
delete() {
- this.groupService.deleteComcolGroup(this.dso, this.comcolRole)
- .subscribe(() => {
- this.cdr.detectChanges();
- })
+ this.groupService.deleteComcolGroup(this.groupLink).subscribe();
}
ngOnInit(): void {
- this.linkService.resolveLink(this.dso, followLink(this.comcolRole.linkName));
+ this.requestService.hasByHrefObservable(this.groupLink)
+ .pipe(
+ filter((hasByHrefObservable) => !hasByHrefObservable),
+ )
+ .subscribe(() => this.groupRD$.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
index 1c4412eaac..2ac74fe67b 100644
--- 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
@@ -7,13 +7,45 @@ import { Collection } from '../../../../core/shared/collection.model';
export class ComcolRole {
/**
- * The admin role.
+ * The community admin role.
*/
- public static ADMIN = new ComcolRole(
- 'admin',
+ 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.