mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Merge remote-tracking branch 'remotes/origin/master' into #601-resource-policies
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -761,11 +761,59 @@
|
||||
|
||||
"community.edit.tabs.roles.title": "Community Edit - Roles",
|
||||
|
||||
"community.edit.tabs.roles.none": "None",
|
||||
|
||||
"community.edit.tabs.roles.admin.name": "Administrators",
|
||||
|
||||
"community.edit.tabs.roles.admin.description": "Community administrators can create sub-communities or collections, and manage or assign management for those sub-communities or collections. In addition, they decide who can submit items to any sub-collections, edit item metadata (after submission), and add (map) existing items from other collections (subject to authorization).",
|
||||
"comcol-role.edit.no-group": "None",
|
||||
|
||||
"comcol-role.edit.create": "Create",
|
||||
|
||||
"comcol-role.edit.restrict": "Restrict",
|
||||
|
||||
"comcol-role.edit.delete": "Delete",
|
||||
|
||||
|
||||
"comcol-role.edit.community-admin.name": "Administrators",
|
||||
|
||||
"comcol-role.edit.collection-admin.name": "Administrators",
|
||||
|
||||
|
||||
"comcol-role.edit.community-admin.description": "Community administrators can create sub-communities or collections, and manage or assign management for those sub-communities or collections. In addition, they decide who can submit items to any sub-collections, edit item metadata (after submission), and add (map) existing items from other collections (subject to authorization).",
|
||||
|
||||
"comcol-role.edit.collection-admin.description": "Collection administrators decide who can submit items to the collection, edit item metadata (after submission), and add (map) existing items from other collections to this collection (subject to authorization for that collection).",
|
||||
|
||||
|
||||
"comcol-role.edit.submitters.name": "Submitters",
|
||||
|
||||
"comcol-role.edit.submitters.description": "The E-People and Groups that have permission to submit new items to this collection.",
|
||||
|
||||
|
||||
"comcol-role.edit.item_read.name": "Default item read access",
|
||||
|
||||
"comcol-role.edit.item_read.description": "E-People and Groups that can read new items submitted to this collection. Changes to this role are not retroactive. Existing items in the system will still be viewable by those who had read access at the time of their addition.",
|
||||
|
||||
"comcol-role.edit.item_read.anonymous-group": "Default read for incoming items is currently set to Anonymous.",
|
||||
|
||||
|
||||
"comcol-role.edit.bitstream_read.name": "Default bitstream read access",
|
||||
|
||||
"comcol-role.edit.bitstream_read.description": "Community administrators can create sub-communities or collections, and manage or assign management for those sub-communities or collections. In addition, they decide who can submit items to any sub-collections, edit item metadata (after submission), and add (map) existing items from other collections (subject to authorization).",
|
||||
|
||||
"comcol-role.edit.bitstream_read.anonymous-group": "Default read for incoming bitstreams is currently set to Anonymous.",
|
||||
|
||||
|
||||
"comcol-role.edit.editor.name": "Editors",
|
||||
|
||||
"comcol-role.edit.editor.description": "Editors are able to edit the metadata of incoming submissions, and then accept or reject them.",
|
||||
|
||||
|
||||
"comcol-role.edit.finaleditor.name": "Final editors",
|
||||
|
||||
"comcol-role.edit.finaleditor.description": "Final editors are able to edit the metadata of incoming submissions, but will not be able to reject them.",
|
||||
|
||||
|
||||
"comcol-role.edit.reviewer.name": "Reviewers",
|
||||
|
||||
"comcol-role.edit.reviewer.description": "Reviewers are able to accept or reject incoming submissions. However, they are not able to edit the submission's metadata.",
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
<ds-comcol-role
|
||||
*ngFor="let comcolRole of getComcolRoles() | async"
|
||||
[dso]="collection$ | async"
|
||||
[comcolRole]="comcolRole"
|
||||
>
|
||||
</ds-comcol-role>
|
||||
|
@@ -0,0 +1,121 @@
|
||||
import { ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { CollectionRolesComponent } from './collection-roles.component';
|
||||
import { Collection } from '../../../core/shared/collection.model';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { GroupDataService } from '../../../core/eperson/group-data.service';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
describe('CollectionRolesComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<CollectionRolesComponent>;
|
||||
let comp: CollectionRolesComponent;
|
||||
let de: DebugElement;
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
const route = {
|
||||
parent: {
|
||||
data: observableOf({
|
||||
dso: new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
Object.assign(new Collection(), {
|
||||
_links: {
|
||||
'irrelevant': {
|
||||
href: 'irrelevant link',
|
||||
},
|
||||
'adminGroup': {
|
||||
href: 'adminGroup link',
|
||||
},
|
||||
'submittersGroup': {
|
||||
href: 'submittersGroup link',
|
||||
},
|
||||
'itemReadGroup': {
|
||||
href: 'itemReadGroup link',
|
||||
},
|
||||
'bitstreamReadGroup': {
|
||||
href: 'bitstreamReadGroup link',
|
||||
},
|
||||
'workflowGroups/test': {
|
||||
href: 'test workflow group link',
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const requestService = {
|
||||
hasByHrefObservable: () => observableOf(true),
|
||||
};
|
||||
|
||||
const groupDataService = {
|
||||
findByHref: () => observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
{},
|
||||
200,
|
||||
)),
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SharedModule,
|
||||
RouterTestingModule.withRoutes([]),
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
CollectionRolesComponent,
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: RequestService, useValue: requestService },
|
||||
{ provide: GroupDataService, useValue: groupDataService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CollectionRolesComponent);
|
||||
comp = fixture.componentInstance;
|
||||
de = fixture.debugElement;
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should display a collection admin role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role .collection-admin')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display a submitters role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role .submitters')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display a default item read role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role .item_read')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display a default bitstream read role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role .bitstream_read')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
it('should display a test workflow role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role .test')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
});
|
@@ -1,4 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
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';
|
||||
|
||||
/**
|
||||
* Component for managing a collection's roles
|
||||
@@ -7,6 +14,48 @@ import { Component } from '@angular/core';
|
||||
selector: 'ds-collection-roles',
|
||||
templateUrl: './collection-roles.component.html',
|
||||
})
|
||||
export class CollectionRolesComponent {
|
||||
/* TODO: Implement Collection Edit - Roles */
|
||||
export class CollectionRolesComponent implements OnInit {
|
||||
|
||||
dsoRD$: Observable<RemoteData<Collection>>;
|
||||
|
||||
/**
|
||||
* The collection to manage, as an observable.
|
||||
*/
|
||||
get collection$(): Observable<Collection> {
|
||||
return this.dsoRD$.pipe(
|
||||
getSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The different roles for the collection, as an observable.
|
||||
*/
|
||||
getComcolRoles(): Observable<ComcolRole[]> {
|
||||
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)),
|
||||
]
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
protected route: ActivatedRoute,
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dsoRD$ = this.route.parent.data.pipe(
|
||||
first(),
|
||||
map((data) => data.dso),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,5 @@
|
||||
*ngFor="let comcolRole of getComcolRoles()"
|
||||
[dso]="community$ | async"
|
||||
[comcolRole]="comcolRole"
|
||||
class="card {{comcolRole.name}}"
|
||||
>
|
||||
</ds-comcol-role>
|
||||
|
@@ -7,6 +7,10 @@ import { CommunityRolesComponent } from './community-roles.component';
|
||||
import { Community } from '../../../core/shared/community.model';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { RequestService } from '../../../core/data/request.service';
|
||||
import { GroupDataService } from '../../../core/eperson/group-data.service';
|
||||
import { SharedModule } from '../../../shared/shared.module';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
describe('CommunityRolesComponent', () => {
|
||||
|
||||
@@ -24,14 +28,40 @@ describe('CommunityRolesComponent', () => {
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
new Community(),
|
||||
)
|
||||
Object.assign(new Community(), {
|
||||
_links: {
|
||||
irrelevant: {
|
||||
href: 'irrelevant link',
|
||||
},
|
||||
adminGroup: {
|
||||
href: 'adminGroup link',
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
const requestService = {
|
||||
hasByHrefObservable: () => observableOf(true),
|
||||
};
|
||||
|
||||
const groupDataService = {
|
||||
findByHref: () => observableOf(new RemoteData(
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
undefined,
|
||||
{},
|
||||
200,
|
||||
)),
|
||||
};
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
SharedModule,
|
||||
RouterTestingModule.withRoutes([]),
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
@@ -39,6 +69,8 @@ describe('CommunityRolesComponent', () => {
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: RequestService, useValue: requestService },
|
||||
{ provide: GroupDataService, useValue: groupDataService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).compileComponents();
|
||||
@@ -51,6 +83,7 @@ describe('CommunityRolesComponent', () => {
|
||||
});
|
||||
|
||||
it('should display a community admin role component', () => {
|
||||
expect(de.query(By.css('ds-comcol-role.admin'))).toBeDefined();
|
||||
expect(de.query(By.css('ds-comcol-role .community-admin')))
|
||||
.toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@@ -33,7 +33,7 @@ export class CommunityRolesComponent implements OnInit {
|
||||
*/
|
||||
getComcolRoles(): ComcolRole[] {
|
||||
return [
|
||||
ComcolRole.ADMIN,
|
||||
ComcolRole.COMMUNITY_ADMIN,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -324,12 +324,11 @@ export class GroupDataService extends DataService<Group> {
|
||||
* 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 comcolRole The role for which to create a group
|
||||
* @param link The REST endpoint to create the group
|
||||
*/
|
||||
createComcolGroup(dso: Community|Collection, comcolRole: ComcolRole): Observable<RestResponse> {
|
||||
createComcolGroup(dso: Community|Collection, link: string): Observable<RestResponse> {
|
||||
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const link = comcolRole.getEndpoint(dso);
|
||||
const group = Object.assign(new Group(), {
|
||||
metadata: {
|
||||
'dc.description': [
|
||||
@@ -340,47 +339,37 @@ export class GroupDataService extends DataService<Group> {
|
||||
},
|
||||
});
|
||||
|
||||
return this.halService.getEndpoint(link).pipe(
|
||||
distinctUntilChanged(),
|
||||
take(1),
|
||||
map((endpoint: string) =>
|
||||
new CreateRequest(
|
||||
requestId,
|
||||
endpoint,
|
||||
JSON.stringify(group),
|
||||
)
|
||||
),
|
||||
configureRequest(this.requestService),
|
||||
tap(() => this.requestService.removeByHrefSubstring(link)),
|
||||
switchMap((restRequest) => this.requestService.getByUUID(restRequest.uuid)),
|
||||
this.requestService.configure(
|
||||
new CreateRequest(
|
||||
requestId,
|
||||
link,
|
||||
JSON.stringify(group),
|
||||
));
|
||||
|
||||
return this.requestService.getByUUID(requestId).pipe(
|
||||
getResponseFromEntry(),
|
||||
tap(() => this.requestService.removeByHrefSubstring(link)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the group for a given role for a given community or collection.
|
||||
*
|
||||
* @param dso The community or collection for which to delete the group
|
||||
* @param comcolRole The role for which to delete the group
|
||||
* @param link The REST endpoint to delete the group
|
||||
*/
|
||||
deleteComcolGroup(dso: Community|Collection, comcolRole: ComcolRole): Observable<RestResponse> {
|
||||
deleteComcolGroup(link: string): Observable<RestResponse> {
|
||||
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const link = comcolRole.getEndpoint(dso);
|
||||
|
||||
return this.halService.getEndpoint(link).pipe(
|
||||
distinctUntilChanged(),
|
||||
take(1),
|
||||
map((endpoint: string) =>
|
||||
new DeleteRequest(
|
||||
requestId,
|
||||
endpoint,
|
||||
)
|
||||
),
|
||||
configureRequest(this.requestService),
|
||||
tap(() => this.requestService.removeByHrefSubstring(link)),
|
||||
switchMap((restRequest) => this.requestService.getByUUID(restRequest.uuid)),
|
||||
this.requestService.configure(
|
||||
new DeleteRequest(
|
||||
requestId,
|
||||
link,
|
||||
));
|
||||
|
||||
return this.requestService.getByUUID(requestId).pipe(
|
||||
getResponseFromEntry(),
|
||||
tap(() => this.requestService.removeByHrefSubstring(link)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,40 +1,50 @@
|
||||
<div class="card p-2">
|
||||
<div class="card p-2 m-3 {{comcolRole.name}}">
|
||||
|
||||
<div class="card-body d-flex flex-column">
|
||||
<div class="card-body d-flex flex-column"
|
||||
*ngVar="group$ | async as group">
|
||||
|
||||
<div class="d-flex flex-row justify-content-between">
|
||||
<div class="d-flex flex-md-row flex-column">
|
||||
|
||||
<div>
|
||||
<p>{{'community.edit.tabs.roles.' + comcolRole.name + '.name' | translate}}</p>
|
||||
<h5 class="w-100 ">
|
||||
{{'comcol-role.edit.' + comcolRole.name + '.name' | translate}}
|
||||
</h5>
|
||||
|
||||
<div class="w-100">
|
||||
<ds-loading *ngIf="!(groupRD$ | async)"></ds-loading>
|
||||
<div *ngIf="hasNoGroup$() | async">
|
||||
{{'comcol-role.edit.no-group' | translate}}
|
||||
</div>
|
||||
<div *ngIf="hasAnonymousGroup$() | async">
|
||||
{{'comcol-role.edit.' + comcolRole.name + '.anonymous-group' | translate}}
|
||||
</div>
|
||||
<a *ngIf="hasCustomGroup$() | async"
|
||||
routerLink="{{editGroupLink$ | async}}">
|
||||
{{group.name}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ng-container *ngVar="group$ | async as group">
|
||||
|
||||
<div *ngIf="!group">
|
||||
{{'community.edit.tabs.roles.none' | translate}}
|
||||
</div>
|
||||
|
||||
<a *ngIf="group"
|
||||
routerLink="{{editGroupLink$ | async}}">
|
||||
{{group.name}}
|
||||
</a>
|
||||
|
||||
<div *ngIf="!group"
|
||||
class="btn btn-outline-dark create"
|
||||
(click)="create()">create
|
||||
</div>
|
||||
|
||||
<div *ngIf="group"
|
||||
class="btn btn-outline-dark delete"
|
||||
(click)="delete()">delete
|
||||
</div>
|
||||
|
||||
</ng-container>
|
||||
<div class="ml-md-auto pl-md-2 ml-0 pl-0 pt-2">
|
||||
<div *ngIf="hasNoGroup$() | async"
|
||||
class="btn btn-outline-dark create"
|
||||
(click)="create()">
|
||||
{{'comcol-role.edit.create' | translate}}
|
||||
</div>
|
||||
<div *ngIf="hasAnonymousGroup$() | async"
|
||||
class="btn btn-outline-dark restrict"
|
||||
(click)="create()">
|
||||
{{'comcol-role.edit.restrict' | translate}}
|
||||
</div>
|
||||
<div *ngIf="hasCustomGroup$() | async"
|
||||
class="btn btn-outline-dark delete"
|
||||
(click)="delete()">
|
||||
{{'comcol-role.edit.delete' | translate}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
{{'community.edit.tabs.roles.' + comcolRole.name + '.description' | translate}}
|
||||
{{'comcol-role.edit.' + comcolRole.name + '.description' | translate}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@@ -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<ComcolRoleComponent>;
|
||||
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,7 @@ 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 +66,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 +112,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', () => {
|
||||
|
@@ -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<RemoteData<Group>> {
|
||||
return this.groupService.findByHref(this.groupLink).pipe(
|
||||
filter((groupRD) => !!groupRD.statusCode),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The group for this role, as an observable.
|
||||
*/
|
||||
get group$(): Observable<Group> {
|
||||
|
||||
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<boolean> {
|
||||
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<boolean> {
|
||||
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<boolean> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user