Polish: permissions, billed-line locking, sync and billing fixes

Permissions
- Item catalog and accounts pages, and their syncs, are admin-only (they
  push to / pull from QuickBooks); shown in the Administration layout
- Item autocomplete is allowed with Add or Edit line items
- Permissions now map to real actions (they pointed at a non-existent
  line_items controller); line_items_attributes is only accepted from
  users with a line item permission
- Line item changes are checked on the server: adding, editing and
  deleting each need their permission, and billed lines (already on a
  QBO estimate) can't be changed or removed

Bugs
- Billing on close now runs from an Issue after_commit, so closing via
  bulk edit or the context menu bills too (replaces the save hook);
  the job takes an issue id
- Full sync runs Accounts before Items, and item sync no longer fails
  when an item has no income account or its account hasn't synced
- New QBO items default to Non-inventory in the default income account
  (the account ref was being assigned to the item type)
- Choosing a blank account on an item no longer raises; set_default
  handles no selection
- Item autocomplete escapes item names, SKUs and descriptions (they were
  inserted into the page as HTML)
- Items list showed "translation missing" for Yes/No

Polish
- Fractional quantities allowed (0.5 hrs, 2.5 qts)
- Billed lines show a Billed badge and are read-only; remove button only
  where allowed; add button only with Add line items
- Removed dead code (Item belongs_to :issue, Item#ref, no-op in new,
  swallowed errors); validation failures return 422

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-28 22:37:41 -04:00
1 parent f0d6b08a3d
commit 39f6b64049
20 files changed
+182 -138

No files matched your search

+10 -11
View File
@@ -9,7 +9,13 @@
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class ItemsController < ApplicationController
before_action :require_login
layout 'admin'
menu_item :redmine_qbo_lineitems
# The item catalog is pushed to QuickBooks, so managing it is admin-only. The autocomplete feeds the
# line item form on issues and is allowed with the "Add line items" or "Edit line items" permission.
before_action :require_admin, except: :autocomplete
before_action :authorize_global, only: :autocomplete
before_action :find_item, only: [:show, :edit, :update, :destroy]
# Used for autocomplete form
@@ -32,7 +38,7 @@ class ItemsController < ApplicationController
if @item.save
redirect_to item_path(@item), notice: l(:notice_successful_create)
else
render :new
render :new, status: :unprocessable_entity
end
rescue => e
log "Unexpected error creating item: #{e.message}"
@@ -55,10 +61,6 @@ class ItemsController < ApplicationController
end
def edit
rescue => e
log "Failed to edit item"
flash[:error] = e.message
render_404
end
def index
@@ -67,7 +69,6 @@ class ItemsController < ApplicationController
def new
@item = Item.new
@item.taxable.nil? ? true : @item.taxable
end
def show
@@ -82,7 +83,7 @@ class ItemsController < ApplicationController
if @item.update(item_params)
redirect_to item_path(@item), notice: l(:notice_successful_update)
else
render :edit
render :edit, status: :unprocessable_entity
end
end
@@ -90,9 +91,7 @@ class ItemsController < ApplicationController
def find_item
@item = Item.find(params[:id])
rescue => e
log "Failed to find item"
flash[:error] = e.message
rescue ActiveRecord::RecordNotFound
render_404
end