Skip to content

Commit 027ba44

Browse files
[DSC-1916] Porting of 'DURACOM-296'
1 parent b95a7e9 commit 027ba44

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

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
<h3 class="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
</h3>
15-
16+
</div>
1617
<h5 class="px-2">{{'dso-selector.create.community.sub-level' | translate}}</h5>
1718
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [configuration]="configuration" [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 & 1 deletion
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 { of as observableOf } from 'rxjs';
12+
import { By } from '@angular/platform-browser';
13+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
1114

1215
describe('CreateCommunityParentSelectorComponent', () => {
1316
let component: CreateCommunityParentSelectorComponent;
@@ -26,6 +29,9 @@ describe('CreateCommunityParentSelectorComponent', () => {
2629
const communityRD = createSuccessfulRemoteDataObject(community);
2730
const modalStub = jasmine.createSpyObj('modalStub', ['close']);
2831
const createPath = '/communities/create';
32+
const mockAuthorizationDataService = jasmine.createSpyObj('authorizationService', {
33+
isAuthorized: observableOf(true),
34+
});
2935

3036
beforeEach(waitForAsync(() => {
3137
TestBed.configureTestingModule({
@@ -47,7 +53,8 @@ describe('CreateCommunityParentSelectorComponent', () => {
4753
},
4854
{
4955
provide: Router, useValue: router
50-
}
56+
},
57+
{ provide: AuthorizationDataService, useValue: mockAuthorizationDataService },
5158
],
5259
schemas: [NO_ERRORS_SCHEMA]
5360
}).compileComponents();
@@ -70,4 +77,20 @@ describe('CreateCommunityParentSelectorComponent', () => {
7077
expect(router.navigate).toHaveBeenCalledWith([createPath], { queryParams: { parent: community.uuid } });
7178
});
7279

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

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 { Observable } from 'rxjs/internal/Observable';
18+
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
19+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
1720

1821
/**
1922
* Component to wrap a button - for top communities -
@@ -33,11 +36,16 @@ export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrap
3336
action = SelectorActionType.CREATE;
3437
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
3538
configuration = 'editCommunity';
39+
isAdmin$: Observable<boolean>;
3640

37-
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
41+
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router, protected authorizationService: AuthorizationDataService) {
3842
super(activeModal, route);
3943
}
4044

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

0 commit comments

Comments
 (0)