diff --git a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html index 8ae146b42c4..a8ec02239d3 100644 --- a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html +++ b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html @@ -5,6 +5,7 @@ {{'dso-selector.create.community.sub-level' | translate}} diff --git a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.spec.ts b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.spec.ts index 2d0a2a25de4..d21714a5ef5 100644 --- a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.spec.ts +++ b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.spec.ts @@ -8,6 +8,9 @@ import { Community } from '../../../../core/shared/community.model'; import { CreateCommunityParentSelectorComponent } from './create-community-parent-selector.component'; import { MetadataValue } from '../../../../core/shared/metadata.models'; import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils'; +import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; +import { By } from '@angular/platform-browser'; +import { of as observableOf } from 'rxjs'; describe('CreateCommunityParentSelectorComponent', () => { let component: CreateCommunityParentSelectorComponent; @@ -26,7 +29,9 @@ describe('CreateCommunityParentSelectorComponent', () => { const communityRD = createSuccessfulRemoteDataObject(community); const modalStub = jasmine.createSpyObj('modalStub', ['close']); const createPath = '/communities/create'; - + const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', { + isAuthorized: observableOf(true), + }); beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], @@ -47,7 +52,8 @@ describe('CreateCommunityParentSelectorComponent', () => { }, { provide: Router, useValue: router - } + }, + { provide: AuthorizationDataService, useValue: mockAuthorizationDataService }, ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -70,4 +76,20 @@ describe('CreateCommunityParentSelectorComponent', () => { expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } }); }); + it('should show the div when user is an admin', (waitForAsync(() => { + component.isAdmin$ = observableOf(true); + fixture.detectChanges(); + + const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]')); + expect(divElement).toBeTruthy(); + }))); + + it('should hide the div when user is not an admin', (waitForAsync(() => { + component.isAdmin$ = observableOf(false); + fixture.detectChanges(); + + const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]')); + expect(divElement).toBeFalsy(); + }))); + }); diff --git a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts index 77458d98022..e44a7450e67 100644 --- a/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts +++ b/src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts @@ -14,6 +14,9 @@ import { } from '../../../../community-page/community-page-routing-paths'; import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model'; import { environment } from '../../../../../environments/environment'; +import { FeatureID } from '../../../../core/data/feature-authorization/feature-id'; +import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; +import { Observable } from 'rxjs'; /** * Component to wrap a button - for top communities - @@ -32,11 +35,16 @@ export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrap selectorTypes = [DSpaceObjectType.COMMUNITY]; action = SelectorActionType.CREATE; defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection); + isAdmin$: Observable; - constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) { + constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router, protected authorizationService: AuthorizationDataService) { super(activeModal, route); } + ngOnInit() { + this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf); + } + /** * Navigate to the community create page */