Comments & Mentions
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/com/example/demo/controllers/CommentController.java
- src/main/java/com/example/demo/services/CommentService.java
- src/main/java/com/example/demo/entity/Comment.java
- src/main/java/com/example/demo/entity/CommentMention.java
- src/main/java/com/example/demo/repositories/CommentMentionRepository.java
- src/main/resources/static/js/task-detail.js
- README.md
The Comments & Mentions system is a core collaborative feature of the Dashboard Task Management application. It allows team members to communicate directly on specific tasks, notify relevant stakeholders, and tag specific users using the @mention syntax. This system ensures that communication is contextualized within the task's lifecycle and that relevant users are promptly notified of updates.
The system is integrated with the notification engine, triggering different types of alerts based on whether a user is a general task participant or specifically mentioned in a comment text.
Sources: README.md:120-130, src/main/java/com/example/demo/services/CommentService.java:62-85
System Architecture & Data Flow
The Comments system follows a standard Spring Boot tiered architecture consisting of a REST controller, a transactional service layer, and JPA repositories.
Comment Submission Flow
When a user submits a comment, the system performs several concurrent actions: persisting the comment text, parsing and saving mentions, and dispatching notifications to various user groups.
The data flow ensures that even if a user is both a participant and mentioned, the system can handle distinct notification types (NEW_COMMENT vs MENTION).
Sources: src/main/java/com/example/demo/services/CommentService.java:62-95, src/main/java/com/example/demo/controllers/CommentController.java:34-43
Data Models
The persistence layer uses two primary entities to manage communication data and user relationships.
Comment Entity
The Comment entity serves as the root for all communication on a task. It includes metadata for auditing and links to the author and parent task.
| Field | Type | Description |
|---|---|---|
id | Long | Primary key |
task | Task | The parent task the comment belongs to |
author | User | The user who created the comment |
content | String | The actual text (TEXT column definition) |
mentions | List | Collection of user mentions within this comment |
createdAt | LocalDateTime | Timestamp of creation |
updatedAt | LocalDateTime | Timestamp of last modification |
Sources: src/main/java/com/example/demo/entity/Comment.java:15-50
CommentMention Entity
This join entity facilitates the many-to-many relationship between comments and users who are tagged.
Access Control & Permissions
Access to comments is strictly governed by the user's role and their relationship to the task or project.
- ADMIN: Full CRUD access (Create, Read, Update, Delete) for all comments across the system.
- MANAGER: Access to comments within tasks belonging to their department.
- PM (Project Manager): Access to comments for tasks within their assigned projects.
- TEAM: Access restricted to comments on tasks they are actively assigned to.
Notably, the ability to edit or delete existing comments is restricted exclusively to the ADMIN role to maintain an immutable audit trail for standard users.
Sources: src/main/java/com/example/demo/services/CommentService.java:141-175, src/main/java/com/example/demo/controllers/CommentController.java:45-64, README.md:32-50
API Endpoints
The CommentController exposes the following RESTful endpoints for managing task communications.
| Method | Endpoint | Description | Role Required |
|---|---|---|---|
GET | /api/tasks/{taskId}/comments | Retrieves all comments for a task, supports asc/desc sorting. | ADMIN, MANAGER, PM, TEAM |
POST | /api/tasks/{taskId}/comments | Adds a new comment and triggers notifications. | ADMIN, MANAGER, PM, TEAM |
PATCH | /api/comments/{commentId} | Updates the content of an existing comment. | ADMIN |
DELETE | /api/comments/{commentId} | Permanently removes a comment. | ADMIN |
Sources: src/main/java/com/example/demo/controllers/CommentController.java:23-65
Mentions and Notifications
The notification logic is handled within the CommentService during the creation of a new comment.
- Task Participants: The task creator and all assigned executors receive a
NEW_COMMENTnotification. - Mentioned Users: Users included in the
mentionUserIdslist of theCommentRequestreceive aMENTIONnotification.
The system includes a safeguard to prevent authors from receiving notifications for their own actions.
Frontend Implementation
On the client side, comments are managed via task-detail.js. The interface fetches comments on page load and provides a real-time update experience by reloading the comment list after a successful POST request.
async function sendComment() {
const input = document.getElementById('commentInput');
const content = input.value.trim();
if (!content) return;
try {
await API.addComment(taskId, content); // Source: api.js
input.value = '';
loadComments();
} catch (e) {
alert('Ошибка: ' + e.message);
}
}
The UI also supports a Ctrl+Enter shortcut for sending comments and escapes HTML to prevent XSS attacks when rendering comment content.
Sources: src/main/resources/static/js/task-detail.js:80-110, src/main/resources/static/js/api.js:63-68
Summary
The Comments & Mentions system provides a secure and collaborative environment for task-based communication. By integrating strict role-based access control with a dual-tier notification system (participants and mentions), the project ensures that users stay informed without compromising data integrity, as modifications are strictly controlled by administrative roles.