Skip to content

Communication: Fix missing length check when forwarding messages#12516

Open
anian03 wants to merge 17 commits intodevelopfrom
bugfix/communication/fix-missing-length-check-for-forwarding
Open

Communication: Fix missing length check when forwarding messages#12516
anian03 wants to merge 17 commits intodevelopfrom
bugfix/communication/fix-missing-length-check-for-forwarding

Conversation

@anian03
Copy link
Copy Markdown
Member

@anian03 anian03 commented Apr 12, 2026

Summary

Resolves #12309. There was no client-side check for the length of a message during forwarding. This could result in strange internal server errors.

Checklist

General

Client

  • I strictly followed the client coding guidelines.
  • I strictly followed the AET UI-UX guidelines.
  • I added multiple integration tests (Vitest) related to the features (with a high test coverage), while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.

Motivation and Context

A missing client side check for the message length when forwarding a message could result in strange errors when sending long messages.

Description

Adds a length check to the forward message dialog and disables the send button if the max length is exceeded.

Steps for Testing

Prerequisites:

  • 1 User
  • 1 Course with Communication enabled
  1. Open Communication in a course of your choice
  2. Forward a message
  3. Enter a message longer than 5000 characters and see that you can no longer press send

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

Client

Class/File Line Coverage Lines Expects Ratio
forward-message-dialog.component.ts 85.08% 251 ? ?
posting-create-edit.directive.ts 96.42% 55 ? ?

Last updated: 2026-04-19 20:36:46 UTC

Screenshots

IMG_7112

Summary by CodeRabbit

  • New Features

    • Live character count shown while composing a forwarded message (current / maximum).
    • Inline validation with visual feedback—message length indicator turns red when invalid.
    • Send button is disabled when no recipients are selected or when the message is invalid, preventing oversized sends.
  • Tests

    • Added unit tests covering message-length validation and send-button enabled/disabled states.

@anian03 anian03 self-assigned this Apr 12, 2026
@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Apr 12, 2026
@github-actions github-actions bot added client Pull requests that update TypeScript code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Apr 12, 2026
@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@github-actions

This comment was marked as duplicate.

@anian03 anian03 moved this from Todo to In Progress in Communication Webclient Apr 12, 2026
@github-actions
Copy link
Copy Markdown

@anian03 Test coverage has been automatically updated in the PR description.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 12, 2026

End-to-End Test Results

Phase Status Details
Phase 1 (Relevant) ✅ Passed
TestsPassed ✅SkippedFailedTime ⏱
Phase 1: E2E Test Report14 ran14 passed0 skipped0 failed2m 0s
Phase 2 (Remaining) ❌ Failed
TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
Phase 2: E2E Test Report238 ran235 passed2 skipped1 failed29m 18s

Test Strategy: Two-phase execution

  • Phase 1: e2e/Login.spec.ts e2e/Logout.spec.ts e2e/SystemHealth.spec.ts e2e/course/CourseMessages.spec.ts
  • Phase 2: e2e/atlas/ e2e/course/CourseChannelMessages.spec.ts e2e/course/CourseDirectMessages.spec.ts e2e/course/CourseExercise.spec.ts e2e/course/CourseGroupChatMessages.spec.ts e2e/course/CourseManagement.spec.ts e2e/course/CourseMessageInteractions.spec.ts e2e/course/CourseOnboarding.spec.ts e2e/exam/ExamAssessment.spec.ts e2e/exam/ExamChecklists.spec.ts e2e/exam/ExamCreationDeletion.spec.ts e2e/exam/ExamDateVerification.spec.ts e2e/exam/ExamManagement.spec.ts e2e/exam/ExamParticipation.spec.ts e2e/exam/ExamResults.spec.ts e2e/exam/ExamTestRun.spec.ts e2e/exam/test-exam/ e2e/exercise/ExerciseImport.spec.ts e2e/exercise/file-upload/ e2e/exercise/modeling/ e2e/exercise/programming/ e2e/exercise/quiz-exercise/ e2e/exercise/text/ e2e/lecture/

Overall: ❌ Phase 2 (remaining tests) failed

🔗 Workflow Run · 📊 Test Report

@anian03 anian03 marked this pull request as ready for review April 12, 2026 17:59
@anian03 anian03 requested a review from a team as a code owner April 12, 2026 17:59
@github-actions
Copy link
Copy Markdown

@anian03 Test coverage has been automatically updated in the PR description.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

Walkthrough

Adds client-side character-length validation to the forward message dialog: exports MAX_CONTENT_LENGTH, exposes maxContentLength and isMessageValid() on the forward dialog component, shows a live character count in the dialog template (turns red when invalid), and disables the send button when the message exceeds the limit or there are no selections.

Changes

Cohort / File(s) Summary
Forward Message Dialog (template + logic)
src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.html, src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.ts
Adds readonly maxContentLength (imported from exported MAX_CONTENT_LENGTH) and isMessageValid() to the component; template displays live character count (newPost.content?.length ?? 0 / maxContentLength), switches counter color to red when invalid, and extends the send button's [disabled] condition to include !isMessageValid().
Unit tests
src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-messages-dialog.component.spec.ts
Adds tests that set newPost.content around maxContentLength, ensure selections exist, run change detection, and assert the primary send button is enabled at maxContentLength and disabled at maxContentLength + 1; also assert isMessageValid() for those cases.
Shared constant export
src/main/webapp/app/communication/directive/posting-create-edit.directive.ts
Changes MAX_CONTENT_LENGTH from a file-local const to an exported export const MAX_CONTENT_LENGTH = 5000; so other components can import it.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Communication: Fix missing length check when forwarding messages' accurately describes the main change: adding character-length validation to the forward message dialog component.
Linked Issues check ✅ Passed All coding requirements from issue #12309 are met: client-side character-length validation using the 5000-character limit is implemented in the forward dialog, the send button is disabled when content exceeds the limit, and a character counter is displayed.
Out of Scope Changes check ✅ Passed All changes are within scope: the constant export, component validation logic, template display, and tests directly address the issue of missing length validation when forwarding messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/communication/fix-missing-length-check-for-forwarding

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.html`:
- Around line 124-130: Replace the Bootstrap button with PrimeNG's pButton in
the template: update the button element in forward-message-dialog.component.html
to use the pButton directive and class="p-button-primary" instead of class="btn
btn-primary", keeping the same type, [disabled], (click)="send()" and
jhiTranslate attributes; also add ButtonModule to the component's NgModule
imports (or the component's imports array) so the pButton directive is available
for the ForwardMessageDialogComponent.

In
`@src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.ts`:
- Around line 287-291: The isMessageValid() function currently rejects messages
whose length equals maxContentLength because it uses '<'; update
isMessageValid() (referencing this.newPost.content and this.maxContentLength) to
allow lengths up to and including the limit by using '<=' for the comparison so
a 5000-character message is accepted. Ensure the null-coalescing to '' remains
and the return type stays boolean.

In
`@src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-messages-dialog.component.spec.ts`:
- Around line 312-323: Add an exact-boundary unit test that uses
component.maxContentLength (not maxContentLength - 1) to ensure the allowed
limit is accepted: create longText = 'a'.repeat(component.maxContentLength),
call component.updateField(longText), set component.selectedChannels and
component.selectedUsers as in the existing test, call fixture.detectChanges(),
then assert component.isMessageValid() is true and the send button is enabled
(query the button via
fixture.debugElement.query(By.css('button.btn-primary')).nativeElement and
assert disabled is false). Ensure the new spec references
component.maxContentLength, updateField, isMessageValid, selectedChannels,
selectedUsers, and the same fixture/button query so it runs alongside the
existing test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d328ceaa-aedd-46c3-8328-43f29b442c2e

📥 Commits

Reviewing files that changed from the base of the PR and between 988e40b and 4c07eb0.

📒 Files selected for processing (4)
  • src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.html
  • src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-message-dialog.component.ts
  • src/main/webapp/app/communication/course-conversations-components/forward-message-dialog/forward-messages-dialog.component.spec.ts
  • src/main/webapp/app/communication/directive/posting-create-edit.directive.ts

@github-project-automation github-project-automation bot moved this from Work In Progress to Ready For Review in Artemis Development Apr 12, 2026
@github-actions
Copy link
Copy Markdown

@anian03 Test coverage has been automatically updated in the PR description.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 12, 2026
Copy link
Copy Markdown
Contributor

@Claudia-Anthropica Claudia-Anthropica left a comment

Choose a reason for hiding this comment

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

@anian03 Clean, well-scoped bugfix. The length validation logic is correct, boundary tests are solid, and reusing the existing MAX_CONTENT_LENGTH constant is the right call. Nice work.

@github-actions
Copy link
Copy Markdown

@anian03 Test coverage has been automatically updated in the PR description.

Copy link
Copy Markdown
Contributor

@Claudia-Anthropica Claudia-Anthropica left a comment

Choose a reason for hiding this comment

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

@anian03 Clean, well-scoped fix. All previous feedback addressed — the off-by-one is fixed, boundary test is in place, and the ngStyle cleanup looks good. Nice work.

@github-actions
Copy link
Copy Markdown

@anian03 Test coverage has been automatically updated in the PR description.

@SedaOran SedaOran self-requested a review April 20, 2026 14:38
Copy link
Copy Markdown
Contributor

@SedaOran SedaOran left a comment

Choose a reason for hiding this comment

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

Nice addition, the client-side validation and UX improvements look good to me, and the boundary tests are solid.

One question: should we also enforce this limit on the backend? Relying only on client-side validation might not be sufficient (e.g. direct API calls), so it could be safer to have a corresponding server-side check as well.

Otherwise looks good 👍 Thanks.

@anian03
Copy link
Copy Markdown
Member Author

anian03 commented Apr 20, 2026

One question: should we also enforce this limit on the backend? Relying only on client-side validation might not be sufficient (e.g. direct API calls), so it could be safer to have a corresponding server-side check as well.

The server already does not accept messages longer than 5000 characters, which is the reason for this PR :)
But we can definitely consider adding this limit directly to the api endpoint as soon as we convert it to DTOs and client-server contracts in the future

@SedaOran SedaOran self-requested a review April 20, 2026 15:37
Copy link
Copy Markdown
Contributor

@SedaOran SedaOran left a comment

Choose a reason for hiding this comment

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

Code looks good. Approving.

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 ready for review

Projects

Status: Ready For Review
Status: In Progress

Development

Successfully merging this pull request may close these issues.

Communication: Check for amount of characters of added message when forwarding a message is not happening in client

3 participants