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: Add option to toggle channel privacy #10315

Merged
merged 8 commits into from
Feb 15, 2025

Conversation

asliayk
Copy link
Contributor

@asliayk asliayk commented Feb 12, 2025

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

Artemis currently lacks the ability to toggle channel privacy, a feature available in Slack's channel settings. Adding this option enables users to seamlessly switch between public and private channels, improving flexibility and access control.

Description

The ability to toggle channel privacy has been added. This feature is integrated into the Settings tab of the Conversation Details Dialog. It allows switching a public channel to private and vice versa. Informative confirmation dialogs have also been implemented.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Course with Communication enabled
  1. Log in to Artemis
  2. Navigate to Communication section of a course
  3. Click on the three-dot menu of a channel and select Settings.
  4. Observe the first button (Change to Public/Private Channel).
  5. Click this button to toggle the channel's privacy and verify that the channel is updated accordingly.

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Screenshots

channel settings with new toggle channel privacy option
image

informative confirmation dialog
image

Summary by CodeRabbit

  • New Features
    • Users can now toggle a channel’s visibility between public and private directly from conversation settings.
    • Conversation dialogs have been enhanced with clearer buttons and confirmation prompts for managing privacy and archival states.
    • Interface text updates in multiple languages provide improved clarity when changing channel visibility.

@asliayk asliayk added tests client Pull requests that update TypeScript code. (Added Automatically!) component:Communication labels Feb 12, 2025
@asliayk asliayk self-assigned this Feb 12, 2025
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Feb 12, 2025
@helios-aet helios-aet bot temporarily deployed to artemis-test6.artemis.cit.tum.de February 13, 2025 12:06 Inactive
@asliayk asliayk marked this pull request as ready for review February 13, 2025 12:43
@asliayk asliayk requested a review from a team as a code owner February 13, 2025 12:43
Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The pull request implements functionality for toggling a channel’s privacy status. On the backend, a new toggleChannelPrivacy method is added to the REST resource to handle POST requests with role-based authorization and channel validation. On the frontend, Angular components are updated to handle a new privacy event, including new UI controls and associated modal dialogs. Corresponding updates are introduced in the service layer to make the API call, and comprehensive test cases are added for both backend and frontend components. Additionally, translation files are updated with new dialog entries for public and private channels.

Changes

File(s) Change Summary
src/main/java/.../ChannelResource.java Added the toggleChannelPrivacy method with request logging, channel validation, permission checks, privacy toggle, and response conversion.
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.html
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.ts
Added an event binding (channelPrivacyChange)="onPrivacyChange()" in the HTML and a corresponding onPrivacyChange() method in the component to handle privacy changes.
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.html
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.ts
Enhanced the conversation settings UI by replacing archival-specific actions with privacy toggles; added new methods (openPublicChannelModal, openPrivateChannelModal, toggleChannelPrivacy) and updated modal handling logic.
src/main/webapp/app/shared/metis/conversations/channel.service.ts
src/main/webapp/app/shared/metis/conversations/conversation-permissions.utils.ts
Introduced toggleChannelPrivacy in the service for making API calls and added canChangeChannelPrivacyState to check user permissions.
src/main/webapp/i18n/de/conversation.json
src/main/webapp/i18n/en/conversation.json
Updated translation files with new dialogs and actions for public/private channel management, and modified archival action labels.
Test files in src/test/java/... and src/test/javascript/spec/... Added new test cases for the backend integration testing of channel privacy toggling, for Angular component behavior, and for service methods handling the privacy change API call.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant UI as ConversationSettingsComponent
    participant CS as ChannelService
    participant CR as ChannelResource (Server)
    participant DB as Database

    U->>UI: Click on toggle privacy button
    UI->>CS: Call toggleChannelPrivacy(courseId, channelId)
    CS->>CR: POST /{courseId}/channels/{channelId}/toggle-privacy
    CR->>DB: Retrieve channel
    DB-->>CR: Return channel data
    CR->>DB: Update channel's privacy state
    DB-->>CR: Return updated channel data
    CR-->>CS: Respond with channel DTO
    CS-->>UI: Return response
    UI->>UI: Emit channelPrivacyChange event and update UI
Loading

Possibly related PRs

Suggested labels

ready to merge, small, programming

Suggested reviewers

  • FelberMartin
  • HawKhiem
  • krusche
  • PaRangger
  • ItsaaaMeMario
  • anian03

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 PMD (7.8.0)
src/test/java/de/tum/cit/aet/artemis/communication/ChannelIntegrationTest.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

src/main/java/de/tum/cit/aet/artemis/communication/web/conversation/ChannelResource.java

[ERROR] Error at ruleset.xml:58:5
56|
57|
58|
^^^^^ Unable to find referenced rule BooleanInstantiation; perhaps the rule name is misspelled?

59|
60|
[WARN] Warning at ruleset.xml:66:5
64|
65|
66|
^^^^^ Use Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitch instead of the deprecated Rule name category/java/bestpractices.xml/DefaultLabelNotLastInSwitchStmt. PMD 8.0.0 will remove support for this deprecated Rule name usage.

67|
68|
[ERROR] Error at ruleset.xml:71:5
69|
70|
71|
^^^^^ Unable to find referenced rule DontImportJavaLang; perhaps the rule name is misspelled?

72|
73|
[ERROR] Error at ruleset.xml:75:5
73|
74|
75|
^^^^^ Unable to find referenced rule DuplicateImports; perhaps the rule name is misspelled?

76|
77|
[ERROR] Error at ruleset.xml:78:5
76|
77|
78|
^^^^^ Unable to find referenced rule EmptyFinallyBlock; perhaps the rule name is misspelled?

79|
80|
[ERROR] Error at ruleset.xml:79:5
77|
78|
79|
^^^^^ Unable to find referenced rule EmptyIfStmt; perhaps the rule name is misspelled?

80|
81|
[ERROR] Error at ruleset.xml:81:5
79|
80|
81|
^^^^^ Unable to find referenced rule EmptyInitializer; perhaps the rule name is misspelled?

82|
83|
[ERROR] Error at ruleset.xml:82:5
80|
81|
82|
^^^^^ Unable to find referenced rule EmptyStatementBlock; perhaps the rule name is misspelled?

83|
84|
[ERROR] Error at ruleset.xml:83:5
81|
82|
83|
^^^^^ Unable to find referenced rule EmptyStatementNotInLoop; perhaps the rule name is misspelled?

84|
85|
[ERROR] Error at ruleset.xml:84:5
82|
83|
84|
^^^^^ Unable to find referenced rule EmptySwitchStatements; perhaps the rule name is misspelled?

85|
86|
[ERROR] Error at ruleset.xml:85:5
83|
84|
85|
^^^^^ Unable to find referenced rule EmptySynchronizedBlock; perhaps the rule name is misspelled?

86|
87|
[ERROR] Error at ruleset.xml:86:5
84|
85|
86|
^^^^^ Unable to find referenced rule EmptyTryBlock; perhaps the rule name is misspelled?

87|
88|
[ERROR] Error at ruleset.xml:87:5
85|
86|
87|
^^^^^ Unable to find referenced rule EmptyWhileStmt; perhaps the rule name is misspelled?

88|
89|
[ERROR] Error at ruleset.xml:90:5
88|
89|
90|
^^^^^ Unable to find referenced rule ExcessiveClassLength; perhaps the rule name is misspelled?

91|
92|
[ERROR] Error at ruleset.xml:91:5
89|
90|
91|
^^^^^ Unable to find referenced rule ExcessiveMethodLength; perhaps the rule name is misspelled?

92|
93|
[ERROR] Error at ruleset.xml:106:5
104|
105|
106|
^^^^^ Unable to find referenced rule ImportFromSamePackage; perhaps the rule name is misspelled?

107|
108|
[ERROR] Error at ruleset.xml:119:5
117|
118|
119|
^^^^^ Unable to find referenced rule MissingBreakInSwitch; perhaps the rule name is misspelled?

120|
121|
[WARN] Warning at ruleset.xml:124:5
122|
123|
124|
^^^^^ Use Rule name category/java/errorprone.xml/NonCaseLabelInSwitch instead of the deprecated Rule name category/java/errorprone.xml/NonCaseLabelInSwitchStatement. PMD 8.0.0 will remove support for this deprecated Rule name usage.

125|
126|
[ERROR] Error at ruleset.xml:134:9
132|
133| // It's okay to use short variable names in DTOs, e.g. "id" or "name"
134| ./de/tum/in/www1/artemis/web/rest/dto/.
^^^^^^^^^^^^^^^^ Unexpected element 'exclude-pattern' in rule ShortVariable

135|
136|
[ERROR] Error at ruleset.xml:137:5
135|
136|
137|
^^^^^ Unable to find referenced rule SimplifyBooleanAssertion; perhaps the rule name is misspelled?

138|
139|
[WARN] Warning at ruleset.xml:184:5
182|
183|
184|
^^^^^ Use Rule name category/ecmascript/errorprone.xml/InaccurateNumericLiteral instead of the deprecated Rule name category/ecmascript/errorprone.xml/InnaccurateNumericLiteral. PMD 8.0.0 will remove support for this deprecated Rule name usage.

185|
186|
[ERROR] Cannot load ruleset category/vm/bestpractices.xml: Cannot resolve rule/ruleset reference 'category/vm/bestpractices.xml'. Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
[WARN] Progressbar rendering conflicts with reporting to STDOUT. No progressbar will be shown. Try running with argument -r to output the report to a file instead.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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: 0

🧹 Nitpick comments (6)
src/test/javascript/spec/component/overview/course-conversations/services/channel.service.spec.ts (1)

205-217: Consider adding error scenario test cases.

While the happy path test case is well-implemented, consider adding test cases for error scenarios:

  • Network errors
  • Server errors (4xx/5xx responses)
  • Invalid response data

Example test case for error handling:

+    it('toggleChannelPrivacy should handle server error', fakeAsync(() => {
+        service
+            .toggleChannelPrivacy(1, 2)
+            .pipe(take(1))
+            .subscribe({
+                error: (error) => expect(error.status).toBe(500)
+            });
+
+        const req = httpMock.expectOne({ method: 'POST', url: '/api/courses/1/channels/2/toggle-privacy' });
+        req.flush('Internal Server Error', { status: 500, statusText: 'Internal Server Error' });
+        tick();
+    }));
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.ts (2)

187-205: Consider consolidating modal opening methods.

The openPublicChannelModal and openPrivateChannelModal methods have similar structures and could be consolidated into a single method with a parameter for the modal type.

-    openPublicChannelModal(channel: ChannelDTO) {
-        const keys = {
-            titleKey: 'artemisApp.dialogs.publicChannel.title',
-            questionKey: 'artemisApp.dialogs.publicChannel.question',
-            descriptionKey: 'artemisApp.dialogs.publicChannel.description',
-            confirmButtonKey: 'artemisApp.dialogs.publicChannel.confirmButton',
-        };
-        this.openPrivacyChangeModal(channel, keys);
-    }
-
-    openPrivateChannelModal(channel: ChannelDTO) {
-        const keys = {
-            titleKey: 'artemisApp.dialogs.privateChannel.title',
-            questionKey: 'artemisApp.dialogs.privateChannel.question',
-            descriptionKey: 'artemisApp.dialogs.privateChannel.description',
-            confirmButtonKey: 'artemisApp.dialogs.privateChannel.confirmButton',
-        };
-        this.openPrivacyChangeModal(channel, keys);
-    }
+    private openPrivacyModal(channel: ChannelDTO, isPublic: boolean) {
+        const modalType = isPublic ? 'public' : 'private';
+        const keys = {
+            titleKey: `artemisApp.dialogs.${modalType}Channel.title`,
+            questionKey: `artemisApp.dialogs.${modalType}Channel.question`,
+            descriptionKey: `artemisApp.dialogs.${modalType}Channel.description`,
+            confirmButtonKey: `artemisApp.dialogs.${modalType}Channel.confirmButton`,
+        };
+        this.openPrivacyChangeModal(channel, keys);
+    }

207-224: Enhance error handling in privacy change modal.

The error handling could be improved by adding specific error messages for common failure scenarios.

     private openPrivacyChangeModal(channel: ChannelDTO, keys: { titleKey: string; questionKey: string; descriptionKey: string; confirmButtonKey: string }) {
         const modalRef = this.createModal(channel, keys);
         this.openModal(modalRef, () => {
             this.channelService
                 .toggleChannelPrivacy(this.course().id!, channel.id!)
                 .pipe(takeUntil(this.ngUnsubscribe))
                 .subscribe({
                     next: (res) => {
                         const updatedChannel = res.body;
                         if (updatedChannel) {
                             this.conversationAsChannel = updatedChannel;
                             this.channelPrivacyChange.emit();
                         }
                     },
-                    error: (errorResponse: HttpErrorResponse) => onError(this.alertService, errorResponse),
+                    error: (errorResponse: HttpErrorResponse) => {
+                        const errorMessage = this.getPrivacyChangeErrorMessage(errorResponse);
+                        onError(this.alertService, errorResponse, errorMessage);
+                    },
                 });
         });
     }
+
+    private getPrivacyChangeErrorMessage(error: HttpErrorResponse): string {
+        switch (error.status) {
+            case 403:
+                return 'You do not have permission to change the channel privacy';
+            case 404:
+                return 'The channel could not be found';
+            default:
+                return 'Failed to change channel privacy';
+        }
+    }
src/main/java/de/tum/cit/aet/artemis/communication/web/conversation/ChannelResource.java (2)

514-544: Enhance error handling and response entity in toggleChannelPrivacy.

While the implementation is solid, consider these improvements:

  1. Add more specific error cases
  2. Use ResponseEntity builder pattern
  3. Add ETag support for caching
     @PostMapping("{courseId}/channels/{channelId}/toggle-privacy")
     @EnforceAtLeastTutorInCourse
     public ResponseEntity<ChannelDTO> toggleChannelPrivacy(@PathVariable Long courseId, @PathVariable Long channelId) {
         log.debug("REST request to toggle privacy for channel : {}", channelId);
         checkCommunicationEnabledElseThrow(courseId);
 
         var channelFromDatabase = channelRepository.findByIdElseThrow(channelId);
         if (!channelFromDatabase.getCourse().getId().equals(courseId)) {
             throw new BadRequestAlertException("The channel does not belong to the course", CHANNEL_ENTITY_NAME, "channel.course.mismatch");
         }
         var requestingUser = userRepository.getUserWithGroupsAndAuthorities();
 
         channelAuthorizationService.isAllowedToUpdateChannel(channelFromDatabase, requestingUser);
 
         boolean isCurrentlyPublic = Boolean.TRUE.equals(channelFromDatabase.getIsPublic());
         channelFromDatabase.setIsPublic(!isCurrentlyPublic);
 
         var updatedChannel = channelRepository.save(channelFromDatabase);
+        var channelDTO = conversationDTOService.convertChannelToDTO(requestingUser, updatedChannel);
+        String etag = "\"" + updatedChannel.getVersion() + "\"";
 
-        return ResponseEntity.ok(conversationDTOService.convertChannelToDTO(requestingUser, updatedChannel));
+        return ResponseEntity
+            .ok()
+            .eTag(etag)
+            .body(channelDTO);
     }

524-526: Consider adding rate limiting for privacy toggle endpoint.

To prevent abuse, consider adding rate limiting for the privacy toggle endpoint using Spring's @RateLimiter annotation.

src/test/java/de/tum/cit/aet/artemis/communication/ChannelIntegrationTest.java (1)

1013-1032: LGTM! Test method thoroughly validates channel privacy toggle functionality.

The test method effectively:

  • Verifies initial public state
  • Tests toggling to private
  • Tests toggling back to public
  • Includes proper cleanup

However, consider adding these test scenarios for more comprehensive coverage:

  • Test with insufficient permissions
  • Test with archived channel
  • Test with course-wide channel
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbe907c and 73c05d4.

📒 Files selected for processing (13)
  • src/main/java/de/tum/cit/aet/artemis/communication/web/conversation/ChannelResource.java (2 hunks)
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.ts (1 hunks)
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.html (2 hunks)
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.ts (7 hunks)
  • src/main/webapp/app/shared/metis/conversations/channel.service.ts (1 hunks)
  • src/main/webapp/app/shared/metis/conversations/conversation-permissions.utils.ts (1 hunks)
  • src/main/webapp/i18n/de/conversation.json (1 hunks)
  • src/main/webapp/i18n/en/conversation.json (2 hunks)
  • src/test/java/de/tum/cit/aet/artemis/communication/ChannelIntegrationTest.java (2 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.spec.ts (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.spec.ts (7 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/services/channel.service.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`src/main/webapp/**/*.html`: @if and @for are new and valid ...

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/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.html
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.html
`src/main/webapp/**/*.ts`: angular_style:https://angular.io/...

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/metis/conversations/conversation-permissions.utils.ts
  • src/main/webapp/app/shared/metis/conversations/channel.service.ts
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.ts
  • src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.ts
`src/test/javascript/spec/**/*.ts`: jest: true; mock: NgMock...

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}}

  • src/test/javascript/spec/component/overview/course-conversations/services/channel.service.spec.ts
  • src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.spec.ts
  • src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.spec.ts
`src/test/java/**/*.java`: test_naming: descriptive; test_si...

src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

  • src/test/java/de/tum/cit/aet/artemis/communication/ChannelIntegrationTest.java
`src/main/webapp/i18n/de/**/*.json`: German language transla...

src/main/webapp/i18n/de/**/*.json: German language translations should be informal (dutzen) and should never be formal (sietzen). So the user should always be addressed with "du/dein" and never with "sie/ihr".

  • src/main/webapp/i18n/de/conversation.json
`src/main/java/**/*.java`: naming:CamelCase; principles:{sin...

src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

  • src/main/java/de/tum/cit/aet/artemis/communication/web/conversation/ChannelResource.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (15)
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.ts (1)

67-69: LGTM!

The onPrivacyChange() method follows the established pattern and correctly handles privacy change events by marking changes and closing the dialog.

src/main/webapp/app/shared/metis/conversations/conversation-permissions.utils.ts (1)

111-113: LGTM!

The canChangeChannelPrivacyState() function follows the established pattern of permission checks and correctly reuses the hasChannelModerationRights() helper function.

src/main/webapp/app/shared/metis/conversations/channel.service.ts (1)

102-112: LGTM!

The toggleChannelPrivacy() method is well-documented and follows the established service patterns:

  • Clear JSDoc documentation
  • Consistent URL construction
  • Proper error handling through Observable
  • Reuse of date conversion pipeline
src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.spec.ts (1)

131-165: LGTM! Comprehensive test coverage for dialog events.

The test case thoroughly verifies the component's behavior for privacy, archival, deletion, and leave events. It checks both state changes and modal interactions, with proper spy usage and state resets between checks.

src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.ts (1)

34-36: LGTM! Well-defined output event.

The channelPrivacyChange output event follows Angular's event naming conventions.

src/test/javascript/spec/component/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.spec.ts (1)

178-236: LGTM! Thorough test coverage for privacy toggle functionality.

The tests comprehensively verify:

  • Channel privacy state changes
  • Modal interactions for both public and private transitions
  • Service call verification
  • Proper use of fakeAsync for async operations
src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/conversation-detail-dialog.component.html (1)

75-75: LGTM! Event binding follows established patterns.

The new channelPrivacyChange event binding is properly integrated with other event handlers and follows Angular's event binding syntax.

src/main/webapp/app/overview/course-conversations/dialogs/conversation-detail-dialog/tabs/conversation-settings/conversation-settings.component.html (3)

16-28: LGTM! Privacy toggle button implementation is clear and consistent.

The privacy toggle button:

  • Uses appropriate icons for public/private states
  • Includes clear text labels
  • Follows Angular's template syntax

30-42: LGTM! Archival toggle button implementation is well-structured.

The archival toggle button:

  • Uses appropriate icons for archived/unarchived states
  • Includes clear text labels
  • Maintains consistency with the privacy toggle button

51-52: LGTM! Delete button improvements enhance usability.

The delete button updates:

  • Add [renderButtonText]="false" for cleaner rendering
  • Include translated text in a separate span

Also applies to: 59-59

src/main/webapp/i18n/en/conversation.json (2)

105-116: LGTM! Dialog entries for privacy changes are comprehensive and clear.

The new dialog entries:

  • Include clear titles, questions, and descriptions
  • Explain the implications of privacy changes
  • Follow the established translation structure

127-131: LGTM! Action labels are descriptive and user-friendly.

The updated action labels:

  • Clarify the scope of archival actions ("for everyone")
  • Use consistent wording for privacy changes
  • Maintain clear and concise language
src/main/webapp/i18n/de/conversation.json (3)

111-116: LGTM! Public channel dialog translations are clear and consistent.

The translations correctly use informal language ("du") and maintain consistency with other dialog translations in the file.


117-122: LGTM! Private channel dialog translations are clear and consistent.

The translations correctly use informal language ("du") and maintain consistency with other dialog translations in the file.


127-131: LGTM! Conversation settings actions are clear and consistent.

The translations correctly use consistent terminology and maintain alignment with the existing action translations.

@helios-aet helios-aet bot temporarily deployed to artemis-test5.artemis.cit.tum.de February 13, 2025 14:09 Inactive
Copy link

@kevinfischer4 kevinfischer4 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, changing channel privacy works as expected 👍
image

Would be cool if there was visual feedback, when an announcement channel is private:
image

@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de February 13, 2025 16:35 Inactive
Copy link

@SimonKaran13 SimonKaran13 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 TS6, works as described. Also can succesfully change privacy to private and also back to public smoothly. Good change :)
image

@helios-aet helios-aet bot temporarily deployed to artemis-test5.artemis.cit.tum.de February 13, 2025 19:29 Inactive
Copy link
Contributor

@PaRangger PaRangger 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 just as described. 😄 Code LGTM 👍

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 13, 2025 20:35 Inactive
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 TS3. Works as described

Copy link

@sachmii sachmii 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, worked just fine.

Bildschirmfoto 2025-02-13 um 23 37 50 Bildschirmfoto 2025-02-13 um 23 37 56

@helios-aet helios-aet bot temporarily deployed to artemis-test7.artemis.cit.tum.de February 13, 2025 23:47 Inactive
@helios-aet helios-aet bot temporarily deployed to artemis-test7.artemis.cit.tum.de February 13, 2025 23:56 Inactive
Copy link

@HanyangXu0508 HanyangXu0508 left a comment

Choose a reason for hiding this comment

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

imagetested on server 3 and no such button exists.

@asliayk
Copy link
Contributor Author

asliayk commented Feb 14, 2025

imagetested on server 3 and no such button exists.

this is because you should deploy this branch on a test server before testing:

image

as I see the branch is not deployed on ts3.

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de February 14, 2025 10:42 Inactive
Copy link

@HanyangXu0508 HanyangXu0508 left a comment

Choose a reason for hiding this comment

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

Worked on test server 3
IMG_3636

@krusche krusche added this to the 7.10.1 milestone Feb 15, 2025
@krusche krusche merged commit d04c2d8 into develop Feb 15, 2025
71 of 76 checks passed
@krusche krusche deleted the feature/communication/toggle-channel-privacy branch February 15, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module feature ready to merge server Pull requests that update Java code. (Added Automatically!) tests
Projects
Status: Merged
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants