feat: add task comment system with role-based permissions - #2
Merged
obvious-autobuild[bot] merged 3 commits intoJun 3, 2026
Merged
Conversation
…ice, viewset, and URL wiring
- TaskComment model in tasks/models.py: task FK, author FK, text (TextField + TEXT_FIELD_VALIDATOR),
created_at (auto_now_add), updated_at (auto_now). Ordered by created_at asc. Index on task.
- Auto-generated Django migration 0006_add_taskcomment_model.py
- TaskCommentSerializer: read-only author_name, author ID, timestamps; writable text
- ProjectCommentPermission: GET/HEAD/OPTIONS → Viewer+, POST → Member+, PUT/PATCH → author only,
DELETE → author OR Moderator+
- IsCommentAuthor permission helper
- CommentService with create_comment, update_comment, delete_comment static methods
- TaskCommentViewSet nested under TaskViewSet; works for both personal and project tasks
- tasks/urls.py: NestedSimpleRouter wires /tasks/{task_pk}/comments/
- projects/urls.py: NestedDefaultRouter wires /projects/{project_pk}/tasks/{task_pk}/comments/
Co-authored-by: Dasha Shifrina <dasha@flatfile.io>
- Fix ProjectCommentPermission to call has_object_permission directly in get_object() rather than relying on check_object_permissions (which uses permission_classes, not ProjectCommentPermission) - TaskCommentViewSet.get_object: explicitly calls ProjectCommentPermission for project tasks instead of using DRF's check_object_permissions dispatcher - Add IsCommentAuthor and ProjectCommentPermission classes in tasks/permissions.py - Add 34 tests in api/tests/test_comments.py covering: - Personal task CRUD: owner-only access, empty text, non-owner rejection - Project task CRUD: Viewer read, Member create, author edit, Moderator delete - Edge cases: wrong project, nonexistent task, validator rejection, ordering - All 108 tests pass (74 existing + 34 new) Co-authored-by: Dasha Shifrina <dasha@flatfile.io>
Co-authored-by: Dasha Shifrina <dasha@flatfile.io>
Coverage Report for CI Build 26904747932Warning No base build found for commit Coverage: 93.53%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
1 similar comment
Coverage Report for CI Build 26904747932Warning No base build found for commit Coverage: 93.53%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tasks lacked any commenting capability. The feature requires two distinct permission models: personal task comments (owner-only) and project task comments (role-based: Viewer/Member/Moderator/Admin).
Solution
Adds a full task comment CRUD system as a nested resource under
/tasks/{task_pk}/comments/and/projects/{project_pk}/tasks/{task_pk}/comments/.Files changed
tasks/models.pyTaskCommentmodeltasks/migrations/0006_add_taskcomment_model.pytasks/serializers.pyTaskCommentSerializertasks/permissions.pyIsCommentAuthor,ProjectCommentPermissiontasks/services.pyCommentServicetasks/views.pyTaskCommentViewSettasks/urls.py/tasks/{id}/comments/projects/urls.py/projects/{id}/tasks/{id}/comments/api/tests/test_comments.pyPermission matrix
Key design choices (per locked decisions)
CommentServicefollowsTaskService/CategoryServicepattern — static methods, no stateTEXT_FIELD_VALIDATORapplied toTaskComment.text(same asTask.title/Task.description)ProjectCommentPermission.has_object_permissionreceives the task'sproject(aProjectinstance) directly soIsProjectMinRole's membership lookupProjectMembership.objects.get(project=obj, user=user)works correctlyImplementation note
TaskCommentViewSet.get_object()explicitly callsProjectCommentPermission().has_object_permission(...)directly rather than relying on DRF'scheck_object_permissions(). The reason:permission_classes = [IsAuthenticated]controls viewset-level auth; for object-level decisions that vary by HTTP method AND user-role/authorship, calling the permission directly ensures the right logic runs and avoids the dispatcher only findingIsAuthenticatedinpermission_classes.Test coverage
34 tests in
api/tests/test_comments.py:All 108 tests pass (74 pre-existing + 34 new).
Human author: Dasha Shifrina dasha@flatfile.io