-
Notifications
You must be signed in to change notification settings - Fork 3
Feature: redesign orderscreen #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
7775c9b
a884ff7
cb7b4ed
b010cf4
b0924b3
d236a84
b2974c7
dcdba74
4b8babb
53c7df1
a5dedaa
b7a3961
4369fc5
5329711
51ecf4d
99955cf
c5bd856
08d6ae5
ab71c13
4f2c9a5
20bd86c
adf39c0
acfa7a6
a0091fb
778d290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,78 @@ | ||||||||
| class ProductPriceFoldersController < ApplicationController | ||||||||
| before_action :authenticate_user! | ||||||||
| before_action :set_price_list, only: %i[index create reorder] | ||||||||
| before_action :set_folder, only: %i[update destroy] | ||||||||
|
|
||||||||
| def index | ||||||||
| authorize ProductPriceFolder, :index? | ||||||||
| @folders = @price_list.product_price_folders.order(:position) | ||||||||
| render json: @folders | ||||||||
| end | ||||||||
|
|
||||||||
| def create | ||||||||
| @folder = @price_list.product_price_folders.new(folder_params) | ||||||||
| authorize @folder | ||||||||
|
|
||||||||
| if @folder.save | ||||||||
| render json: @folder, status: :created | ||||||||
| else | ||||||||
| render json: { errors: @folder.errors.full_messages }, status: :unprocessable_content | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| def update | ||||||||
| authorize @folder | ||||||||
|
|
||||||||
| if @folder.update(folder_params) | ||||||||
| render json: @folder | ||||||||
| else | ||||||||
| render json: { errors: @folder.errors.full_messages }, status: :unprocessable_content | ||||||||
| end | ||||||||
| end | ||||||||
|
|
||||||||
| def destroy | ||||||||
| authorize @folder | ||||||||
|
|
||||||||
| orphaned_products = @folder.product_prices | ||||||||
| max_position = @folder.price_list.product_price.without_folder.maximum(:position) || -1 | ||||||||
|
||||||||
| max_position = @folder.price_list.product_price.without_folder.maximum(:position) || -1 | |
| max_position = @folder.price_list.product_prices.without_folder.maximum(:position) || -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical bug: product_price should be product_prices on line 37.
PriceList was updated (in app/models/price_list.rb, line 2) to use has_many :product_prices (plural). This line still uses the old singular name product_price, which will raise NoMethodError and break the entire destroy action.
Additionally, the individual product updates (lines 39–41) are not wrapped in a transaction, so a failure mid-way would leave partially reassigned products.
🐛 Proposed fix
def destroy
authorize `@folder`
orphaned_products = `@folder.product_prices`
- max_position = `@folder.price_list.product_price.without_folder.maximum`(:position) || -1
+ max_position = `@folder.price_list.product_prices.without_folder.maximum`(:position) || -1
- orphaned_products.each_with_index do |product_price, index|
- product_price.update(product_price_folder_id: nil, position: max_position + index + 1)
- end
-
- `@folder.destroy`
+ ActiveRecord::Base.transaction do
+ orphaned_products.each_with_index do |product_price, index|
+ product_price.update!(product_price_folder_id: nil, position: max_position + index + 1)
+ end
+ `@folder.destroy`!
+ end
head :no_content
end🤖 Prompt for AI Agents
In `@app/controllers/product_price_folders_controller.rb` around lines 33 - 46,
The destroy action references the wrong association name and lacks transactional
safety: change the call from `@folder.price_list.product_price` to
`@folder.price_list.product_prices` (plural) when computing max_position, and wrap
the reassignment loop and `@folder.destroy` inside a single database transaction
(e.g., ApplicationRecord.transaction or PriceList.transaction) so that updating
orphaned_products (product_price updates) and deleting the folder are atomic and
roll back on failure.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reorder action only authorizes at the class level (ProductPriceFolder) but doesn't authorize each individual folder being reordered. While this might be acceptable since all folders belong to the same price list, consider adding authorization for each folder to ensure consistency with the ProductPricesController pattern (line 32 in product_prices_controller.rb), which authorizes each product_price individually in its reorder action.
| folder = @price_list.product_price_folders.find(folder_data[:id]) | |
| folder = @price_list.product_price_folders.find(folder_data[:id]) | |
| authorize folder, :reorder? |
lodewiges marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new ProductPriceFoldersController lacks test coverage. The codebase has comprehensive test coverage for other controllers (as evidenced by the spec/controllers directory), but there are no tests for this new controller. Tests should be added to cover the index, create, update, destroy, and reorder actions, including authorization checks for different user roles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line uses the incorrect association name '.product_price' (singular) which should be '.product_prices' (plural) to match the corrected association in the PriceList model. This will cause a NoMethodError at runtime.