Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Fix visibility of create channel option for students #9989

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
asliayk marked this conversation as resolved.
Show resolved Hide resolved
});
});
Loading