Skip to content

Commit 4228362

Browse files
authored
Merge pull request #3695 from DSpace/backport-3308-to-dspace-8_x
2 parents 10a4a2e + 6831097 commit 4228362

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
</button>
66
</div>
77
<div class="modal-body">
8+
<div data-test="admin-div" *ngIf="(isAdmin$ | async)">
89
<button class="btn btn-outline-primary btn-lg btn-block" (click)="selectObject(undefined)">{{'dso-selector.create.community.top-level' | translate}}</button>
910
<div class="h3 position-relative py-1 my-3 font-weight-normal">
1011
<hr>
1112
<div id="create-community-or-separator" class="text-center position-absolute w-100">
1213
<span class="px-4 bg-white">{{'dso-selector.create.community.or-divider' | translate}}</span>
1314
</div>
1415
</div>
15-
16+
</div>
1617
<span class="h5 px-2">{{'dso-selector.create.community.sub-level' | translate}}</span>
1718
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
1819
</div>

src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.spec.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import {
77
TestBed,
88
waitForAsync,
99
} from '@angular/core/testing';
10+
import { By } from '@angular/platform-browser';
1011
import {
1112
ActivatedRoute,
1213
Router,
1314
} from '@angular/router';
1415
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
1516
import { TranslateModule } from '@ngx-translate/core';
17+
import { of as observableOf } from 'rxjs';
1618

19+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
1720
import { Community } from '../../../../core/shared/community.model';
1821
import { MetadataValue } from '../../../../core/shared/metadata.models';
1922
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
@@ -38,7 +41,9 @@ describe('CreateCommunityParentSelectorComponent', () => {
3841
const communityRD = createSuccessfulRemoteDataObject(community);
3942
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
4043
const createPath = '/communities/create';
41-
44+
const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', {
45+
isAuthorized: observableOf(true),
46+
});
4247
beforeEach(waitForAsync(() => {
4348
TestBed.configureTestingModule({
4449
imports: [TranslateModule.forRoot(), CreateCommunityParentSelectorComponent],
@@ -59,6 +64,7 @@ describe('CreateCommunityParentSelectorComponent', () => {
5964
{
6065
provide: Router, useValue: router,
6166
},
67+
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
6268
],
6369
schemas: [NO_ERRORS_SCHEMA],
6470
})
@@ -85,4 +91,20 @@ describe('CreateCommunityParentSelectorComponent', () => {
8591
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
8692
});
8793

94+
it('should show the div when user is an admin', (waitForAsync(() => {
95+
component.isAdmin$ = observableOf(true);
96+
fixture.detectChanges();
97+
98+
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
99+
expect(divElement).toBeTruthy();
100+
})));
101+
102+
it('should hide the div when user is not an admin', (waitForAsync(() => {
103+
component.isAdmin$ = observableOf(false);
104+
fixture.detectChanges();
105+
106+
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
107+
expect(divElement).toBeFalsy();
108+
})));
109+
88110
});

src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
AsyncPipe,
3+
NgIf,
4+
} from '@angular/common';
15
import {
26
Component,
37
OnInit,
@@ -9,6 +13,7 @@ import {
913
} from '@angular/router';
1014
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
1115
import { TranslateModule } from '@ngx-translate/core';
16+
import { Observable } from 'rxjs';
1217

1318
import { environment } from '../../../../../environments/environment';
1419
import {
@@ -19,6 +24,8 @@ import {
1924
SortDirection,
2025
SortOptions,
2126
} from '../../../../core/cache/models/sort-options.model';
27+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
28+
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
2229
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
2330
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
2431
import { hasValue } from '../../../empty.util';
@@ -40,18 +47,23 @@ import {
4047
styleUrls: ['./create-community-parent-selector.component.scss'],
4148
templateUrl: './create-community-parent-selector.component.html',
4249
standalone: true,
43-
imports: [DSOSelectorComponent, TranslateModule],
50+
imports: [DSOSelectorComponent, TranslateModule, NgIf, AsyncPipe],
4451
})
4552
export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrapperComponent implements OnInit {
4653
objectType = DSpaceObjectType.COMMUNITY;
4754
selectorTypes = [DSpaceObjectType.COMMUNITY];
4855
action = SelectorActionType.CREATE;
4956
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
57+
isAdmin$: Observable<boolean>;
5058

51-
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
59+
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router, protected authorizationService: AuthorizationDataService) {
5260
super(activeModal, route);
5361
}
5462

63+
ngOnInit() {
64+
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
65+
}
66+
5567
/**
5668
* Navigate to the community create page
5769
*/

0 commit comments

Comments
 (0)