Skip to content

Commit

Permalink
Communication: Fix visibility of create channel option for students (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk authored Dec 10, 2024
1 parent f01b5eb commit 037d35d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { CourseSidebarService } from 'app/overview/course-sidebar.service';
import { LayoutService } from 'app/shared/breakpoints/layout.service';
import { CustomBreakpointNames } from 'app/shared/breakpoints/breakpoints.service';
import { Posting, PostingType, SavedPostStatus, SavedPostStatusMap } from 'app/entities/metis/posting.model';
import { canCreateChannel } from 'app/shared/metis/conversations/conversation-permissions.utils';

const DEFAULT_CHANNEL_GROUPS: AccordionGroups = {
favoriteChannels: { entityData: [] },
Expand Down Expand Up @@ -424,6 +425,7 @@ export class CourseConversationsComponent implements OnInit, OnDestroy {
ungroupedData: this.sidebarConversations,
showAccordionLeadingIcon: true,
messagingEnabled: isMessagingEnabled(this.course),
canCreateChannel: canCreateChannel(this.course!),
};
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/webapp/app/shared/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
<span jhiTranslate="artemisApp.courseOverview.sidebar.createGroupChat"></span>
</button>
}
<button (click)="createNewChannel()" class="p-2" ngbDropdownItem>
<fa-icon [icon]="faHashtag" class="item-icon"></fa-icon>
<span jhiTranslate="artemisApp.courseOverview.sidebar.createChannel"></span>
</button>
@if (sidebarData?.canCreateChannel) {
<button (click)="createNewChannel()" class="p-2 createChannel" ngbDropdownItem>
<fa-icon [icon]="faHashtag" class="item-icon"></fa-icon>
<span jhiTranslate="artemisApp.courseOverview.sidebar.createChannel"></span>
</button>
}
<button (click)="browseChannels()" class="p-2" ngbDropdownItem>
<fa-icon [icon]="faSearch" class="item-icon"></fa-icon>
<span jhiTranslate="artemisApp.courseOverview.sidebar.browseChannels"></span>
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/types/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface SidebarData {
storageId?: string;
showAccordionLeadingIcon?: boolean;
messagingEnabled?: boolean;
canCreateChannel?: boolean;
}

export interface SidebarCardElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SidebarCardElement, SidebarData } from 'app/types/sidebar';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { ExerciseFilterModalComponent } from 'app/shared/exercise-filter/exercise-filter-modal.component';
import { ExerciseFilterResults } from 'app/types/exercise-filter';
import { EventEmitter } from '@angular/core';
import { EventEmitter, input, runInInjectionContext } from '@angular/core';
import { ExerciseCategory } from 'app/entities/exercise-category.model';
import { ExerciseType } from 'app/entities/exercise.model';
import { IconProp } from '@fortawesome/fontawesome-svg-core';
Expand Down Expand Up @@ -49,9 +49,7 @@ describe('SidebarComponent', () => {
],
providers: [MockProvider(NgbModal)],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SidebarComponent);
component = fixture.componentInstance;
modalService = TestBed.inject(NgbModal);
Expand Down Expand Up @@ -288,5 +286,27 @@ describe('SidebarComponent', () => {
expect(component.exerciseFilters).toEqual(mockFilterResults.appliedExerciseFilters);
expect(component.isFilterActive).toBeTrue();
});

it('should show "Create Channel" button when canCreateChannel is true', () => {
runInInjectionContext(fixture.debugElement.injector, () => {
component.inCommunication = input<boolean>(true);
component.ngOnInit();
component.sidebarData.canCreateChannel = true;
fixture.detectChanges();
const createChannelButton = fixture.debugElement.query(By.css('.createChannel'));
expect(createChannelButton).toBeTruthy();
});
});

it('should not show "Create Channel" button when canCreateChannel is false', () => {
runInInjectionContext(fixture.debugElement.injector, () => {
component.inCommunication = input<boolean>(true);
component.ngOnInit();
component.sidebarData.canCreateChannel = false;
fixture.detectChanges();
const createChannelButton = fixture.debugElement.query(By.css('.createChannel'));
expect(createChannelButton).toBeFalsy();
});
});
});
});

0 comments on commit 037d35d

Please sign in to comment.