mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #3308 from 4Science/task/main/DURACOM-296
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div data-test="admin-div" *ngIf="(isAdmin$ | async)">
|
||||
<button class="btn btn-outline-primary btn-lg btn-block" (click)="selectObject(undefined)">{{'dso-selector.create.community.top-level' | translate}}</button>
|
||||
<div class="h3 position-relative py-1 my-3 font-weight-normal">
|
||||
<hr>
|
||||
@@ -12,7 +13,7 @@
|
||||
<span class="px-4 bg-white">{{'dso-selector.create.community.or-divider' | translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<span class="h5 px-2">{{'dso-selector.create.community.sub-level' | translate}}</span>
|
||||
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
|
||||
</div>
|
||||
|
@@ -7,13 +7,16 @@ import {
|
||||
TestBed,
|
||||
waitForAsync,
|
||||
} from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { Community } from '../../../../core/shared/community.model';
|
||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
|
||||
@@ -38,7 +41,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(), CreateCommunityParentSelectorComponent],
|
||||
@@ -59,6 +64,7 @@ describe('CreateCommunityParentSelectorComponent', () => {
|
||||
{
|
||||
provide: Router, useValue: router,
|
||||
},
|
||||
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
})
|
||||
@@ -85,4 +91,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();
|
||||
})));
|
||||
|
||||
});
|
||||
|
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
AsyncPipe,
|
||||
NgIf,
|
||||
} from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
OnInit,
|
||||
@@ -9,6 +13,7 @@ import {
|
||||
} from '@angular/router';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../../../../environments/environment';
|
||||
import {
|
||||
@@ -19,6 +24,8 @@ import {
|
||||
SortDirection,
|
||||
SortOptions,
|
||||
} from '../../../../core/cache/models/sort-options.model';
|
||||
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
|
||||
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
|
||||
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
|
||||
import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.model';
|
||||
import { hasValue } from '../../../empty.util';
|
||||
@@ -40,18 +47,23 @@ import {
|
||||
styleUrls: ['./create-community-parent-selector.component.scss'],
|
||||
templateUrl: './create-community-parent-selector.component.html',
|
||||
standalone: true,
|
||||
imports: [DSOSelectorComponent, TranslateModule],
|
||||
imports: [DSOSelectorComponent, TranslateModule, NgIf, AsyncPipe],
|
||||
})
|
||||
export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrapperComponent implements OnInit {
|
||||
objectType = DSpaceObjectType.COMMUNITY;
|
||||
selectorTypes = [DSpaceObjectType.COMMUNITY];
|
||||
action = SelectorActionType.CREATE;
|
||||
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
|
||||
isAdmin$: Observable<boolean>;
|
||||
|
||||
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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user