Skip to content

Commit a53df4f

Browse files
authored
Merge pull request #3696 from 4Science/backport-3308-to-dspace-7_x
2 parents 35a25b3 + c743387 commit a53df4f

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Community } from '../../../../core/shared/community.model';
88
import { CreateCommunityParentSelectorComponent } from './create-community-parent-selector.component';
99
import { MetadataValue } from '../../../../core/shared/metadata.models';
1010
import { createSuccessfulRemoteDataObject } from '../../../remote-data.utils';
11+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
12+
import { By } from '@angular/platform-browser';
13+
import { of as observableOf } from 'rxjs';
1114

1215
describe('CreateCommunityParentSelectorComponent', () => {
1316
let component: CreateCommunityParentSelectorComponent;
@@ -26,7 +29,9 @@ describe('CreateCommunityParentSelectorComponent', () => {
2629
const communityRD = createSuccessfulRemoteDataObject(community);
2730
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
2831
const createPath = '/communities/create';
29-
32+
const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', {
33+
isAuthorized: observableOf(true),
34+
});
3035
beforeEach(waitForAsync(() => {
3136
TestBed.configureTestingModule({
3237
imports: [TranslateModule.forRoot()],
@@ -47,7 +52,8 @@ describe('CreateCommunityParentSelectorComponent', () => {
4752
},
4853
{
4954
provide: Router, useValue: router
50-
}
55+
},
56+
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
5157
],
5258
schemas: [NO_ERRORS_SCHEMA]
5359
}).compileComponents();
@@ -70,4 +76,20 @@ describe('CreateCommunityParentSelectorComponent', () => {
7076
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
7177
});
7278

79+
it('should show the div when user is an admin', (waitForAsync(() => {
80+
component.isAdmin$ = observableOf(true);
81+
fixture.detectChanges();
82+
83+
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
84+
expect(divElement).toBeTruthy();
85+
})));
86+
87+
it('should hide the div when user is not an admin', (waitForAsync(() => {
88+
component.isAdmin$ = observableOf(false);
89+
fixture.detectChanges();
90+
91+
const divElement = fixture.debugElement.query(By.css('div[data-test="admin-div"]'));
92+
expect(divElement).toBeFalsy();
93+
})));
94+
7395
});

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
} from '../../../../community-page/community-page-routing-paths';
1515
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
1616
import { environment } from '../../../../../environments/environment';
17+
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
18+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
19+
import { Observable } from 'rxjs';
1720

1821
/**
1922
* Component to wrap a button - for top communities -
@@ -32,11 +35,16 @@ export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrap
3235
selectorTypes = [DSpaceObjectType.COMMUNITY];
3336
action = SelectorActionType.CREATE;
3437
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
38+
isAdmin$: Observable<boolean>;
3539

36-
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
40+
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router, protected authorizationService: AuthorizationDataService) {
3741
super(activeModal, route);
3842
}
3943

44+
ngOnInit() {
45+
this.isAdmin$ = this.authorizationService.isAuthorized(FeatureID.AdministratorOf);
46+
}
47+
4048
/**
4149
* Navigate to the community create page
4250
*/

0 commit comments

Comments
 (0)