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

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Dec 10, 2024

Checklist

General

Client

Motivation and Context

Students currently see the "Create Channel" button despite lacking the permission to create channel, leading to confusion and errors. (Closes #9969)

Description

The visibility of the "Create Channel" button was fixed using the canCreateChannel variable to ensure it only appears for users with the necessary permissions.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Student
  • 1 Course with Communication enabled
  1. Log in to Artemis (as an Instructor)
  2. Navigate to Communication section of a course
  3. As an Instructor, click on the "+" button in the sidebar and verify that the "Create Channel" option is visible.
  4. Log out and log in as a Student.
  5. Click on the "+" button in the sidebar and verify that the "Create Channel" option is not visible.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
course-conversations.component.ts 90.76% ✅ ❌
sidebar.ts not found (modified)

Summary by CodeRabbit

  • New Features

    • Added functionality to determine if users can create a channel, enhancing sidebar data.
    • Conditional rendering for the "Create Channel" button based on user permissions.
  • Bug Fixes

    • Updated tests to verify the visibility of the "Create Channel" button according to permissions.
  • Documentation

    • Updated the SidebarData interface to include a new optional property for channel creation permissions.

@asliayk asliayk added tests client Pull requests that update TypeScript code. (Added Automatically!) small bugfix component:Communication labels Dec 10, 2024
@asliayk asliayk self-assigned this Dec 10, 2024
@asliayk asliayk requested a review from a team as a code owner December 10, 2024 05:55
Copy link

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request introduce a new utility function, canCreateChannel, to determine user permissions for creating channels in the CourseConversationsComponent. This function's result is incorporated into the sidebar data structure, which now includes a canCreateChannel property. The sidebar's HTML template is updated to conditionally render the "Create Channel" button based on this property. Additionally, the sidebar component's tests are enhanced to verify the visibility of the button according to the user's permissions.

Changes

File Change Summary
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts Added import for canCreateChannel and updated updateSidebarData method to include canCreateChannel in sidebarData.
src/main/webapp/app/shared/sidebar/sidebar.component.html Wrapped "Create Channel" button in a conditional block based on sidebarData?.canCreateChannel. Updated class attribute for the button.
src/main/webapp/app/types/sidebar.ts Added optional property canCreateChannel of type boolean to SidebarData interface.
src/test/javascript/spec/component/shared/sidebar/sidebar.component.spec.ts Added tests for the visibility of the "Create Channel" button based on canCreateChannel. Updated imports and streamlined beforeEach setup.

Assessment against linked issues

Objective Addressed Explanation
Prevent students from seeing the "Create Channel" button (Issue #9969)
Ensure that the button is only visible when the user has permission to create channels (Issue #9969)

Possibly related PRs

Suggested labels

ready to merge

Suggested reviewers

  • JohannesWt
  • edkaya
  • rabeatwork
  • florian-glombik
  • anian03
  • HawKhiem
  • SimonEntholzer
  • az108

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

428-428: Consider adding null check for better safety.

The use of non-null assertion operator (!) could lead to runtime errors if this.course is undefined.

Consider this safer implementation:

-canCreateChannel: canCreateChannel(this.course!),
+canCreateChannel: this.course ? canCreateChannel(this.course) : false,
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4ebb290 and e53f342.

📒 Files selected for processing (4)
  • src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (2 hunks)
  • src/main/webapp/app/shared/sidebar/sidebar.component.html (1 hunks)
  • src/main/webapp/app/types/sidebar.ts (1 hunks)
  • src/test/javascript/spec/component/shared/sidebar/sidebar.component.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/main/webapp/app/types/sidebar.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/shared/sidebar/sidebar.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/shared/sidebar/sidebar.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

🔇 Additional comments (5)
src/main/webapp/app/types/sidebar.ts (1)

44-44: LGTM! Clean and focused type definition.

The new optional boolean property canCreateChannel is well-placed and follows the TypeScript naming conventions.

src/main/webapp/app/shared/sidebar/sidebar.component.html (1)

38-43: LGTM! Clean implementation of conditional rendering.

The implementation correctly uses the new Angular @if directive and follows a logical structure within the dropdown menu. The addition of the 'createChannel' class aids in testing.

src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (3)

43-43: LGTM! Import statement follows Angular guidelines.

The import of the canCreateChannel utility function is well-placed and follows naming conventions.


428-428: LGTM! Implementation aligns with PR objectives.

The addition of canCreateChannel property effectively controls the visibility of the create channel button based on user permissions.


428-428: Verify the complete implementation chain.

Let's verify the integration between the permission check and the sidebar template.

✅ Verification successful

Let me gather more information about the implementation chain.


Implementation chain is properly integrated

The verification shows a complete and correct implementation chain:

  • The canCreateChannel utility is properly defined in conversation-permissions.utils.ts with correct course permission check
  • It's correctly used in course-conversations.component.ts to pass the permission
  • The sidebar template properly controls button visibility based on this permission
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the implementation of canCreateChannel utility
echo "Checking canCreateChannel utility implementation:"
ast-grep --pattern 'export function canCreateChannel($_) {
  $$$
}'

# Check sidebar template for button visibility control
echo "Checking sidebar template implementation:"
rg -A 2 'canCreateChannel' 'src/main/webapp/app/shared/sidebar'

Length of output: 802


Script:

#!/bin/bash
# Check the type definition and usage in sidebar component
echo "Checking sidebar component implementation:"
ast-grep --pattern 'export class SidebarComponent {
  $$$
}'

# Find where canCreateChannel is defined
echo "Finding canCreateChannel definition:"
rg -A 5 'export function canCreateChannel'

# Check course-conversations component implementation
echo "Checking course-conversations component:"
rg -A 5 'canCreateChannel: canCreateChannel' 'src/main/webapp/app/overview/course-conversations'

Length of output: 1968

Copy link

@eylulnc eylulnc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in TS5. Works as expected. Created channel not visible yo user.

Copy link
Member

@anian03 anian03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5, works as expected. Thanks for the quick fix!

Copy link

@julian-wls julian-wls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5, works as expected!

Copy link
Contributor

@FelberMartin FelberMartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5, works as described

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS5. I could indeed create channel as an instructor and/or a tutor and not as a student

image

image

@bassner bassner added this to the 7.7.5 milestone Dec 10, 2024
@bassner bassner merged commit 037d35d into develop Dec 10, 2024
102 of 107 checks passed
@bassner bassner deleted the bugfix/communication/restrict-create-channel-view branch December 10, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) component:Communication ready to merge small tests
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

Communication: Students have access to create channel view, despite not having rights
7 participants