mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
[DURACOM-296] Enabled 'admin-div' only for Site Administrator
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<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>
|
<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">
|
<div class="h3 position-relative py-1 my-3 font-weight-normal">
|
||||||
<hr>
|
<hr>
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
<span class="px-4 bg-white">{{'dso-selector.create.community.or-divider' | translate}}</span>
|
<span class="px-4 bg-white">{{'dso-selector.create.community.or-divider' | translate}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<span class="h5 px-2">{{'dso-selector.create.community.sub-level' | translate}}</span>
|
<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>
|
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -8,6 +8,9 @@ import { Community } from '../../../../core/shared/community.model';
|
|||||||
import { CreateCommunityParentSelectorComponent } from './create-community-parent-selector.component';
|
import { CreateCommunityParentSelectorComponent } from './create-community-parent-selector.component';
|
||||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||||
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
|
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', () => {
|
describe('CreateCommunityParentSelectorComponent', () => {
|
||||||
let component: CreateCommunityParentSelectorComponent;
|
let component: CreateCommunityParentSelectorComponent;
|
||||||
@@ -26,7 +29,9 @@ describe('CreateCommunityParentSelectorComponent', () => {
|
|||||||
const communityRD = createSuccessfulRemoteDataObject(community);
|
const communityRD = createSuccessfulRemoteDataObject(community);
|
||||||
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||||
const createPath = '/communities/create';
|
const createPath = '/communities/create';
|
||||||
|
const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', {
|
||||||
|
isAuthorized: observableOf(true),
|
||||||
|
});
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot()],
|
imports: [TranslateModule.forRoot()],
|
||||||
@@ -47,7 +52,8 @@ describe('CreateCommunityParentSelectorComponent', () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: Router, useValue: router
|
provide: Router, useValue: router
|
||||||
}
|
},
|
||||||
|
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
@@ -70,4 +76,20 @@ describe('CreateCommunityParentSelectorComponent', () => {
|
|||||||
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
|
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();
|
||||||
|
})));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -14,6 +14,9 @@ import {
|
|||||||
} from '../../../../community-page/community-page-routing-paths';
|
} from '../../../../community-page/community-page-routing-paths';
|
||||||
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
|
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
|
||||||
import { environment } from '../../../../../environments/environment';
|
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 -
|
* Component to wrap a button - for top communities -
|
||||||
@@ -32,11 +35,16 @@ export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrap
|
|||||||
selectorTypes = [DSpaceObjectType.COMMUNITY];
|
selectorTypes = [DSpaceObjectType.COMMUNITY];
|
||||||
action = SelectorActionType.CREATE;
|
action = SelectorActionType.CREATE;
|
||||||
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
|
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);
|
super(activeModal, route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigate to the community create page
|
* Navigate to the community create page
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user