Skip to content

Refine task form and schema: add user assignment logic to task creati…#1083

Open
ger619 wants to merge 4 commits intodevfrom
assigning-user-to-task
Open

Refine task form and schema: add user assignment logic to task creati…#1083
ger619 wants to merge 4 commits intodevfrom
assigning-user-to-task

Conversation

@ger619
Copy link
Copy Markdown
Owner

@ger619 ger619 commented Aug 13, 2025

…on, update form to display available users, introduce bugs and add_bugs tables, adjust foreign keys, and enhance defects constraints.
This pull request introduces several updates to the task assignment workflow and the database schema, primarily focusing on enabling user assignment for tasks at creation and adding support for bug tracking. The most important changes are grouped below by theme.

Task Assignment Improvements:

  • Added logic in TasksController#create to assign a selected user as an assignee when a new task is created, provided the user is valid and not already assigned.
  • Updated the task form (_form.html.erb) to include a user selection dropdown, allowing assignment of available users with the agent role who are part of the product but not already assigned to the task.

Bug Tracking Schema Additions:

  • Added new bugs and add_bugs tables to the database schema, with appropriate columns and foreign key relationships to defects, users, and related entities. [1] [2] [3] [4]

Defect Table Adjustments:

  • Modified the defects table to remove columns now present in the new bugs table and made product_id and user_id required fields, updating foreign key constraints accordingly. [1] [2]

Other Schema Updates:

  • Added a new position column to the users table.
  • Added foreign key for status_bugs to reference bugs.

…on, update form to display available users, introduce `bugs` and `add_bugs` tables, adjust foreign keys, and enhance `defects` constraints.
@ger619 ger619 requested a review from Copilot August 13, 2025 11:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces comprehensive changes to enable user assignment during task creation and establishes a bug tracking system with enhanced database schema. The changes restructure the defects table and add new bug-related entities while improving the task creation workflow.

  • Added user assignment functionality to task creation with dropdown selection
  • Introduced new bug tracking system with bugs and add_bugs tables
  • Refactored defects table by moving bug-related columns to the new bugs table and making product_id/user_id required

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
db/schema.rb Adds bugs/add_bugs tables, refactors defects table structure, adds position column to users, and establishes new foreign key relationships
app/views/tasks/_form.html.erb Adds user selection dropdown for task assignment during creation
app/controllers/tasks_controller.rb Implements user assignment logic in task creation workflow

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

# Assign one or more users to the task on creation
if (assignee_id = params.dig(:task, :user_id).presence)
assignee = User.find_by(id: assignee_id)
@task.users << assignee if assignee && !@task.users.exists?(assignee.id)
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The @task.users.exists?(assignee.id) check will always return false because the task was just saved and the users association hasn't been loaded yet. This could result in duplicate assignments or unexpected behavior. Consider using @task.users.include?(assignee) or reload the association before checking.

Suggested change
@task.users << assignee if assignee && !@task.users.exists?(assignee.id)
@task.users << assignee if assignee && !@task.users.include?(assignee)

Copilot uses AI. Check for mistakes.
<%= f.collection_select :user_id,
available_users,
:id,
:name, # change to :display_name if you add one
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The inline comment suggests using :display_name but provides no context about when or why this change should be made. This comment should either be removed or expanded to explain the conditions under which this change would be necessary.

Suggested change
:name, # change to :display_name if you add one
:name, # Use :display_name instead of :name if the User model has a display_name method or attribute for user-friendly display.

Copilot uses AI. Check for mistakes.

<% if available_users.any? %>
<%= f.collection_select :user_id,
available_users,
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

The user query is executed in the view template, which violates MVC separation of concerns and could cause performance issues. This logic should be moved to the controller and passed as an instance variable to the view.

Suggested change
available_users,
<% if @available_users.any? %>
<%= f.collection_select :user_id,
@available_users,

Copilot uses AI. Check for mistakes.
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