Skip to content

feat(task-comments): allow editing own recent human comments - #441

Merged
artempartos merged 1 commit into
developfrom
feature/edit-task-comments
Oct 8, 2026
Merged

artempartos merged 1 commit into
developfrom
feature/edit-task-comments

Conversation

@Evgeniy-DB

Copy link
Copy Markdown
Collaborator

Summary

Adds the ability to edit comments on tasks. Editing is allowed only when all
three conditions hold:

  • the editor is the comment's own author;
  • the comment is human-authored (author_type == human, not agent/system);
  • the comment is younger than 3 hours.

The server is the source of truth; the UI only hides the Edit affordance when
the rules are not met.

Design notes

  • The rules are centralised in TaskComment#editable_by? with
    TaskComment::EDIT_WINDOW = 3.hours.
  • They are enforced in CommentsController#update, not in the policy. This
    tree uses authorize-by-default (AuthorizationConcern#dynamic_authorize!),
    which passes the policy a namespace symbol rather than the record, so a
    record-level update? cannot inspect the comment. The policy therefore keeps
    the plain project_writable? check (the same shape as assets#destroy), and
    the own/human/age rules run in the action, returning 403 on a violation.
  • update permits only :body — tags and author_type cannot be
    changed through it.
  • A successful edit records a comment_updated board activity (new event type),
    mirroring comment_added.
  • No schema change: task_comments has no updated_at, and edits are not
    marked "edited". Age is computed from created_at.

Changes

Backend

  • config/routes.rb: add update to task comments.
  • app/models/task_comment.rb: EDIT_WINDOW + editable_by?.
  • app/models/board_activity.rb: comment_updated event type.
  • app/services/task_service.rb: update_comment (saves body, records activity).
  • app/controllers/api/v1/projects/board/task/comments_controller.rb: update.
  • app/policies/{api/v1,web/company}/.../comments_policy.rb: update?.

Frontend

  • canEditComment.ts: pure gating helper (own + human + <3h).
  • TaskDetailSidebar.tsx: currentUserId prop, Edit button + inline form,
    PATCH via apiMutate with a partial reload of task_comments.
  • BoardPage.tsx: pass currentUserId.
  • shared/routes.ts: apiV1ProjectTaskCommentPath helper.

Tests

  • Model: editable_by? across owner / other user / agent / system / over-window
    / edge cases.
  • Integration (API authz): owner can edit a fresh human comment; non-author
    collaborator, read-only viewer, agent-authored, and over-3h comments all get
    403; tags/author_type are not changed by an edit.
  • Frontend: canEditComment gating.

Verification

  • Green locally: yarn tsc, yarn eslint (0 errors), canEditComment.test.ts
    (6/6), BoardPage.test.tsx (129/129).
  • Ruby files pass ruby -c.
    Please run make rails-test and make rubocop in CI / a networked env.
  • app/frontend/shared/routes.ts was edited by hand following the generator's
    exact format; regenerate with bin/rails ts:routes to confirm no drift.

Related issues

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore
  • Breaking change

Checklist

  • I read CONTRIBUTING.md.
  • All my commits are signed off for the DCO (git commit -s).
  • I have signed (or will sign) the CLA when the bot prompts me — or my
    organization has executed the Corporate CLA.
  • make check_all passes locally (tests, rubocop, brakeman, eslint, typescript).
  • I added/updated tests where it makes sense.
  • I updated documentation where it makes sense.
  • My commits use clear, descriptive messages.

  Add the ability to edit a task comment, restricted to the comment's own
  author, human-authored comments only, and comments younger than 3 hours.

  The three rules live in TaskComment#editable_by? (window TaskComment::
  EDIT_WINDOW = 3.hours) and are enforced server-side in the controller
  rather than the policy: the authorize-by-default path (AuthorizationConcern)
  hands the policy a namespace symbol, not the record, so the policy keeps the
  plain project-write check (mirroring assets#destroy) and the record-level
  rules are applied in the action, returning 403 on a violation. The update
  permits only :body, so tags and author_type cannot be changed. A successful
  edit records a comment_updated board activity.

  The frontend offers an inline Edit affordance in the comment actions row,
  gated by the same rules (canEditComment); the server remains the source of
  truth.

  Backend:
  - route: add update to task comments
  - TaskComment: EDIT_WINDOW + editable_by?
  - BoardActivity: add comment_updated event type
  - TaskService.update_comment (records comment_updated)
  - CommentsController#update (record-level 403, body-only)
  - CommentsPolicy#update? = project_writable? (api + web)

  Frontend:
  - thread currentUserId into TaskDetailSidebar
  - canEditComment helper (own + human + <3h)
  - inline edit form (PATCH + partial reload)
  - apiV1ProjectTaskCommentPath route helper

  Tests:
  - model: editable_by? (owner/other/agent/system/age/edge)
  - integration: update authz (owner ok; non-author/viewer/agent/stale 403;
    tags/author_type unchanged)
  - frontend: canEditComment gating

Signed-off-by: Evgeniy Yagnenkov <[email protected]>
@artempartos
artempartos merged commit 8ec0440 into develop Oct 8, 2026
8 checks passed
@artempartos artempartos mentioned this pull request Oct 8, 2026
artempartos added a commit that referenced this pull request Oct 8, 2026
Adds the entries #441, #445 and #447 merged without, then moves
[Unreleased] into 1.1.0. Minor, not patch: the release carries new
features (comment editing, custom analytics range, Sessions & Runs
sorting and date filters, /changelog, Managed by Aixle).

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants