Skip to content

fix(items): add explicit sentinel value for clearing supplier in bulk edit - #4617

Merged
objecttothis merged 15 commits into
masterfrom
bugfix-mass-assignment-in-bulk-edit
Aug 20, 2026
Merged

objecttothis merged 15 commits into
masterfrom
bugfix-mass-assignment-in-bulk-edit

Conversation

@objecttothis

@objecttothis objecttothis commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

This fixes a regression introduced in the fix for https://github.com/opensourcepos/opensourcepos/security/advisories/GHSA-49mq-h2g4-grr9 Introduce Item::CLEAR_SUPPLIER_OPTION = 'NONE' to distinguish between "leave supplier_id unchanged" (empty string) and "clear supplier_id" (sentinel). Previously, empty string was ambiguous.

  • Add CLEAR_SUPPLIER_OPTION constant with doc comment explaining intent
  • Update supplier dropdown to include sentinel as first real option
  • Shift empty string to mean "do nothing" across all bulk edit fields

Summary by CodeRabbit

  • New Features

    • Bulk item editing now provides separate options to leave suppliers unchanged or clear the selected supplier.
    • Selecting “None” removes the supplier from the chosen items.
  • Bug Fixes

    • Bulk updates now apply only supported, non-empty fields, preventing unintended changes from invalid or blank input.
    • Invalid prices, quantities, supplier selections, and boolean values are ignored.
    • Valid zero values and locale-formatted numbers are handled correctly.
    • Updates with no valid changes are rejected instead of being processed.

… edit

This fixes a regression introduced in the fix for https://github.com/opensourcepos/opensourcepos/security/advisories/GHSA-49mq-h2g4-grr9
Introduce `Item::CLEAR_SUPPLIER_OPTION = 'NONE'` to distinguish between
\"leave supplier_id unchanged\" (empty string) and \"clear supplier_id\"
(sentinel). Previously, empty string was ambiguous.

- Add `CLEAR_SUPPLIER_OPTION` constant with doc comment explaining intent
- Update supplier dropdown to include sentinel as first real option
- Shift empty string to mean \"do nothing\" across all bulk edit fields

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis objecttothis added this to the 3.4.2 milestone Aug 4, 2026
@objecttothis
objecttothis requested a review from jekkos August 4, 2026 14:25
@objecttothis objecttothis self-assigned this Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Bulk item editing separates unchanged and cleared supplier values. Shared field filtering removes invalid or empty inputs, converts the clear sentinel to null, and is enforced before database updates. Database-backed tests cover the filtering and update behavior.

Changes

Bulk item edit handling

Layer / File(s) Summary
Bulk edit field normalization
app/Models/Item.php, app/Controllers/Items.php
The model adds the CLEAR_SUPPLIER_OPTION sentinel and shared field-filtering logic. The controller exposes separate unchanged and clear supplier choices and uses the shared filter.
Bulk update enforcement
app/Models/Item.php
update_multiple() independently applies the whitelist and returns false when no permitted fields remain.
Bulk update validation
tests/Models/ItemBulkUpdateTest.php
Database-backed tests cover permitted fields, rejected fields, supplier selection and clearing, empty values, zero values, multi-ID updates, and sentinel safety.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: jekkos

Sequence Diagram(s)

sequenceDiagram
  participant ItemsController
  participant Item
  participant Database

  ItemsController->>Item: filterBulkEditFields(input)
  Item-->>ItemsController: filtered bulk-edit fields
  ItemsController->>Item: update_multiple(itemIds, fields)
  Item->>Database: update permitted fields
  Database-->>Item: update result
  Item-->>ItemsController: update result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding an explicit sentinel to clear suppliers during bulk item editing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix-mass-assignment-in-bulk-edit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]

This comment was marked as resolved.

Cover GHSA-49mq-h2g4-grr9: Item::update_multiple() bypasses model
$allowedFields via Query Builder, allowing unintended field writes
during bulk edit operations.

Signed-off-by: Travis Garrison <[email protected]>
coderabbitai[bot]

This comment was marked as resolved.

filterBulkEditFields now validates field values before accepting them:
- Non-scalar values are rejected (array injection guard)
- Price/quantity fields are locale-parsed to floats, invalid strings skipped
- Boolean fields must be 0 or 1, other values skipped
- supplier_id must be numeric; CLEAR_SUPPLIER_OPTION still nulls it

Update tests to assert parsed types (float for prices, int for
supplier_id) and replace the fill-all-fields fixture with a realistic
input that only covers fields a form would actually submit.

Signed-off-by: Travis Garrison <[email protected]>
coderabbitai[bot]

This comment was marked as resolved.

Travis Garrison and others added 3 commits August 5, 2026 12:11
…ests

- Track created supplier person IDs for teardown cleanup
- Delete supplier records in tearDown to prevent test pollution
- Extract item/supplier creation into reusable helper methods

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos I've been plugging away at these advisories so that we can get them all patched and get 3.4.2 out the door. I think that's the only thing blocking 3.4.2. The faster you can do code reviews on these the better.

Convert Item model, Items controller, and bulk update tests to
PSR-compliant camelCase naming per project conventions.

- Rename update_multiple to updateMultiple in Item model
- Rename local variables (item_data, items_to_update, tax_names, etc.)
  to camelCase across Items controller and Item model
- Update ItemBulkUpdateTest to use new updateMultiple method name
- Reorder and update AGENTS.md naming conventions

Signed-off-by: Travis Garrison <[email protected]>
@objecttothis

Copy link
Copy Markdown
Member Author

🧹 Nitpick comments (1)

tests/Models/ItemBulkUpdateTest.php (1)> 24-75: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use typed properties and camelCase variables in the new fixture.
Declare compatible types for $migrate, $refresh, and $namespace. Rename $created_item_ids, $item_data, and $item_id to camelCase, including all references.
As per coding guidelines, PHP code must use camelCase variables and proper type declarations.

🤖 Prompt for AI Agents

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Models/ItemBulkUpdateTest.php` around lines 24 - 75, Update
ItemBulkUpdateTest fixture properties with compatible type declarations for
$migrate, $refresh, and $namespace. Rename $created_item_ids to camelCase and
update every reference, and rename the local $item_data and $item_id variables
in createItem to camelCase while preserving the existing fixture creation and
cleanup behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents

ℹ️ Review info

Typing these creates an inheritance problem as they are not typed in the parent class.

Travis Garrison and others added 4 commits August 6, 2026 10:43
@jekkos

jekkos commented Aug 9, 2026

Copy link
Copy Markdown
Member

@objecttothis thanks a lot for the extra work, advisories kept coming so I got a bit overwhelmed.

@CodeRabbit can you check if we can have similar issue with other field than supplier and do we need sentinel value for those in order to fix?

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Locate relevant files =='
fd -t f . app tests | rg '(^|/)(Items\.php|Item\.php|ItemBulkUpdateTest\.php)$|[Ii]tem.*[Bb]ulk|[Bb]ulk.*[Ii]tem'

printf '%s\n' '== Model and controller outlines =='
ast-grep outline app/Models/Item.php --items all --view expanded || true
ast-grep outline app/Controllers/Items.php --items all --view expanded || true

printf '%s\n' '== Bulk-edit-related references with context =='
rg -n -i -C 4 'bulk.{0,20}(edit|update)|filterBulkEditFields|update_multiple|CLEAR_SUPPLIER_OPTION|supplier_id' app tests

printf '%s\n' '== View/form candidates =='
fd -t f . app | rg -i '(item|items).*\.(php|js)$' | while IFS= read -r file; do
  if rg -q -i 'bulk.{0,20}(edit|update)|supplier_id|item_type|tax|category' "$file"; then
    echo "--- $file"
    rg -n -i -C 3 'bulk.{0,20}(edit|update)|supplier_id|item_type|tax|category' "$file"
  fi
done

Length of output: 154946


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== app/Views/items/form_bulk.php =='
cat -n app/Views/items/form_bulk.php

printf '%s\n' '== Item bulk-edit methods and whitelist context =='
rg -n -C 20 'function (filterBulkEditFields|update_multiple)|BULK|bulk.*(field|edit)|supplier_id' app/Models/Item.php

printf '%s\n' '== Items bulk-edit actions =='
rg -n -C 18 'function (bulkEdit|bulkUpdate)|filterBulkEditFields|update_multiple' app/Controllers/Items.php

printf '%s\n' '== Targeted bulk-update test names and assertions =='
rg -n -C 8 'function test|filterBulkEditFields|CLEAR_SUPPLIER_OPTION|supplier_id|tax_|category|description|item_type' tests/Models/ItemBulkUpdateTest.php

Length of output: 37272


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '== Supplier options used by bulk edit =='
rg -n -C 10 'CLEAR_SUPPLIER_OPTION|suppliers.*\[|supplier_id.*(bulk|NONE)|bulkEdit' app/Controllers/Items.php app

printf '%s\n' '== Item table schema definitions =='
rg -n -i -C 8 'CREATE TABLE.*items|`supplier_id`|supplier_id|`description`|`category`|`name`|reorder_level|allow_alt_description|is_serialized' \
  -g '*.sql' -g '*.php' database app tests

printf '%s\n' '== Item tax bulk update implementation =='
rg -n -C 15 'function save_multiple|save_multiple\(|class Item_taxes|class ItemTaxes' app tests

printf '%s\n' '== Tax table schema definitions =='
rg -n -i -C 8 'CREATE TABLE.*item_taxes|item_taxes.*CREATE|`percent`|`name`' -g '*.sql' -g '*.php' database app tests

Length of output: 188926


@jekkos I checked the bulk-edit fields.

No additional sentinel is needed for the current fields:

  • allow_alt_description and is_serialized use 0 and 1. 0 is an explicit update value.
  • cost_price, unit_price, and reorder_level accept 0 as an explicit update value.
  • name should not be cleared because it is required.
  • Tax updates use a separate bulk-update path. They do not use the item-field filter.

name, category, and description have the same representation limitation: an empty string means “do not change.” Therefore, the current bulk editor cannot clear category or description.

That is not the same regression as supplier_id. The supplier field must support a third state:

  1. Leave unchanged.
  2. Set to a supplier ID.
  3. Clear the nullable foreign key by writing NULL.

Item::CLEAR_SUPPLIER_OPTION provides state 3 without changing state 1.

Add a sentinel for category or description only if bulk edit must support clearing those fields. A generic sentinel should not be added now. It would expand behavior without a current requirement.

You are interacting with an AI system.

@objecttothis

Copy link
Copy Markdown
Member Author

@jekkos can you review this PR for me?

@objecttothis
objecttothis merged commit cc93c31 into master Aug 20, 2026
14 checks passed
@objecttothis
objecttothis deleted the bugfix-mass-assignment-in-bulk-edit branch August 20, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants