Refine task form and schema: add user assignment logic to task creati…#1083
Refine task form and schema: add user assignment logic to task creati…#1083
Conversation
…on, update form to display available users, introduce `bugs` and `add_bugs` tables, adjust foreign keys, and enhance `defects` constraints.
There was a problem hiding this comment.
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
bugsandadd_bugstables - 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.
app/controllers/tasks_controller.rb
Outdated
| # 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) |
There was a problem hiding this comment.
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.
| @task.users << assignee if assignee && !@task.users.exists?(assignee.id) | |
| @task.users << assignee if assignee && !@task.users.include?(assignee) |
| <%= f.collection_select :user_id, | ||
| available_users, | ||
| :id, | ||
| :name, # change to :display_name if you add one |
There was a problem hiding this comment.
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.
| :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. |
|
|
||
| <% if available_users.any? %> | ||
| <%= f.collection_select :user_id, | ||
| available_users, |
There was a problem hiding this comment.
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.
| available_users, | |
| <% if @available_users.any? %> | |
| <%= f.collection_select :user_id, | |
| @available_users, |
…ure proper check for existing assignees.
… for client ticket limit.
…r)` in tickets count query.
…on, update form to display available users, introduce
bugsandadd_bugstables, adjust foreign keys, and enhancedefectsconstraints.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:
TasksController#createto assign a selected user as an assignee when a new task is created, provided the user is valid and not already assigned._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:
bugsandadd_bugstables to the database schema, with appropriate columns and foreign key relationships to defects, users, and related entities. [1] [2] [3] [4]Defect Table Adjustments:
defectstable to remove columns now present in the newbugstable and madeproduct_idanduser_idrequired fields, updating foreign key constraints accordingly. [1] [2]Other Schema Updates:
positioncolumn to theuserstable.status_bugsto referencebugs.