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: Allow tutors to monitor channels as moderator #9874

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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 @@ -143,7 +143,9 @@ public Optional<Conversation> isMemberOrCreateForCourseWideElseThrow(Long conver

if (conversation instanceof Channel channel && channel.getIsCourseWide()) {
ConversationParticipant conversationParticipant = ConversationParticipant.createWithDefaultValues(user, channel);
conversationParticipant.setIsModerator(authorizationCheckService.isAtLeastInstructorInCourse(channel.getCourse(), user));
boolean canBecomeModerator = (channel.getIsAnnouncementChannel() ? authorizationCheckService.isAtLeastInstructorInCourse(channel.getCourse(), user)
: authorizationCheckService.isAtLeastTeachingAssistantInCourse(channel.getCourse(), user));
conversationParticipant.setIsModerator(canBecomeModerator);
lastReadDate.ifPresent(conversationParticipant::setLastRead);
conversationParticipantRepository.saveAndFlush(conversationParticipant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export class AnswerPostReactionsBarComponent extends PostingsReactionsBarDirecti
this.isAuthorOfOriginalPost = this.metisService.metisUserIsAuthorOfPosting(this.posting.post!);
this.isAnswerOfAnnouncement = getAsChannelDTO(this.posting.post?.conversation)?.isAnnouncementChannel ?? false;
const isCourseWideChannel = getAsChannelDTO(this.posting.post?.conversation)?.isCourseWide ?? false;
const isAtLeastInstructorInCourse = this.metisService.metisUserIsAtLeastInstructorInCourse();
const mayEditOrDeleteOtherUsersAnswer =
(isCourseWideChannel && isAtLeastInstructorInCourse) || (getAsChannelDTO(this.metisService.getCurrentConversation())?.hasChannelModerationRights ?? false);
this.mayDelete = !this.isReadOnlyMode && (this.isAuthorOfPosting || mayEditOrDeleteOtherUsersAnswer);
const canDeletePost = this.isAnswerOfAnnouncement ? this.metisService.metisUserIsAtLeastInstructorInCourse() : this.metisService.metisUserIsAtLeastTutorInCourse();
const mayDeleteOtherUsersAnswer =
(isCourseWideChannel && canDeletePost) || (getAsChannelDTO(this.metisService.getCurrentConversation())?.hasChannelModerationRights ?? false);
this.mayDelete = !this.isReadOnlyMode && (this.isAuthorOfPosting || (mayDeleteOtherUsersAnswer && canDeletePost));
this.mayDeleteOutput.emit(this.mayDelete);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class PostReactionsBarComponent extends PostingsReactionsBarDirective<Pos
*/
private setCanPin(currentConversation: ConversationDTO | undefined) {
if (!currentConversation) {
this.canPin = this.metisService.metisUserIsAtLeastInstructorInCourse();
this.canPin = this.metisService.metisUserIsAtLeastTutorInCourse();
return;
}

Expand Down Expand Up @@ -203,9 +203,12 @@ export class PostReactionsBarComponent extends PostingsReactionsBarDirective<Pos
setMayDelete(): void {
this.isAtLeastInstructorInCourse = this.metisService.metisUserIsAtLeastInstructorInCourse();
const isCourseWideChannel = getAsChannelDTO(this.posting.conversation)?.isCourseWide ?? false;
const isAnswerOfAnnouncement = getAsChannelDTO(this.posting.conversation)?.isAnnouncementChannel ?? false;
const isAtLeastTutorInCourse = this.metisService.metisUserIsAtLeastTutorInCourse();
const canDeleteAnnouncement = isAnswerOfAnnouncement ? this.metisService.metisUserIsAtLeastInstructorInCourse() : true;
const mayDeleteOtherUsersAnswer =
(isCourseWideChannel && this.isAtLeastInstructorInCourse) || (getAsChannelDTO(this.metisService.getCurrentConversation())?.hasChannelModerationRights ?? false);
this.mayDelete = !this.readOnlyMode && !this.previewMode && (this.isAuthorOfPosting || mayDeleteOtherUsersAnswer);
(isCourseWideChannel && isAtLeastTutorInCourse) || (getAsChannelDTO(this.metisService.getCurrentConversation())?.hasChannelModerationRights ?? false);
this.mayDelete = !this.readOnlyMode && !this.previewMode && (this.isAuthorOfPosting || mayDeleteOtherUsersAnswer) && canDeleteAnnouncement;
this.mayDeleteOutput.emit(this.mayDelete);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ describe('AnswerPostReactionsBarComponent', () => {
it('should display the delete option to instructor if posting is in course-wide channel from a student', () => {
metisServiceUserIsAtLeastInstructorMock.mockReturnValue(true);
metisServiceUserPostingAuthorMock.mockReturnValue(false);
metisServiceUserIsAtLeastTutorMock.mockReturnValue(true);
component.posting = { ...metisResolvingAnswerPostUser1, post: { ...metisPostInChannel } };
component.posting.authorRole = UserRole.USER;
component.ngOnInit();
Expand Down Expand Up @@ -158,7 +159,7 @@ describe('AnswerPostReactionsBarComponent', () => {
expect(getEditButton()).not.toBeNull();
});

it('should not display edit and delete options to tutor if posting is in course-wide channel from a student', () => {
it('should display edit and delete options to tutor if posting is in course-wide channel from a student', () => {
metisServiceUserIsAtLeastInstructorMock.mockReturnValue(false);
metisServiceUserIsAtLeastTutorMock.mockReturnValue(true);
metisServiceUserPostingAuthorMock.mockReturnValue(false);
Expand All @@ -167,7 +168,7 @@ describe('AnswerPostReactionsBarComponent', () => {
component.ngOnInit();
fixture.detectChanges();
expect(getEditButton()).toBeNull();
expect(getDeleteButton()).toBeNull();
expect(getDeleteButton()).not.toBeNull();
});

it('should not display edit and delete options to users that are neither author or tutor', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('PostReactionsBarComponent', () => {
expect(debugElement.query(By.directive(ConfirmIconComponent))).toBeNull();
});

it('should not display edit and delete options to tutor if posting is in course-wide channel', () => {
it('should not display edit option but should display delete option to tutor if posting is in course-wide channel', () => {
metisServiceUserIsAtLeastInstructorStub.mockReturnValue(false);
metisServiceUserIsAtLeastTutorStub.mockReturnValue(true);
metisServiceUserIsAuthorOfPostingStub.mockReturnValue(false);
Expand All @@ -232,7 +232,7 @@ describe('PostReactionsBarComponent', () => {
component.ngOnInit();
fixture.detectChanges();
expect(getEditButton()).toBeNull();
expect(getDeleteButton()).toBeNull();
expect(getDeleteButton()).not.toBeNull();
});

it('should not display edit and delete options to tutor if posting is announcement', () => {
Expand All @@ -257,11 +257,14 @@ describe('PostReactionsBarComponent', () => {

it('should display the delete option to instructor if posting is in course-wide channel from a student', () => {
metisServiceUserIsAtLeastInstructorStub.mockReturnValue(true);
metisServiceUserIsAtLeastTutorStub.mockReturnValue(true);
metisServiceUserIsAuthorOfPostingStub.mockReturnValue(false);
component.posting = { ...metisPostInChannel };
component.posting.authorRole = UserRole.USER;

component.ngOnInit();
fixture.detectChanges();
component.setMayDelete();
expect(getDeleteButton()).not.toBeNull();
});

Expand Down
Loading