generated from block/oss-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
When a comment is created via the API, author_id is set to @api_token.id (the API token's ID), not the user's ID. This forces CommentsHelper#comment_author_name to do a raw SQL join through coplan_api_tokens to resolve the user's name, hardcoding the users table name in the process.
Current behavior
# API controller sets token ID as author:
author_id: @api_token.id
# Helper has to join through token to get user name:
CoPlan.user_class
.joins("INNER JOIN coplan_api_tokens ON coplan_api_tokens.user_id = users.id")
.where("coplan_api_tokens.id = ?", comment.author_id)
.pick(:name)Proposed fix
Store @api_token.user_id as author_id for local_agent comments. Then the helper can use CoPlan.user_class.find_by(id: comment.author_id) for both human and local_agent types — no join, no hardcoded table name.
The agent_name field (already required for local_agent comments) distinguishes which agent made the comment.
Files involved
engine/app/controllers/coplan/api/v1/comments_controller.rb— changeauthor_id: @api_token.id→author_id: @api_token.user_idengine/app/helpers/coplan/comments_helper.rb— simplify local_agent branch to a direct user lookup- Backfill migration for any existing comments with token IDs as author_id
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels