Add explicit CompanyId to tenant-scoped FindAsync queries (partial sweep)
Multi-tenant defense-in-depth sweep, FindAsync/FirstOrDefaultAsync vector. Adds explicit CompanyId predicates to list/index/validation queries that previously relied only on the global tenant filter (exposure: raw platform-admin sessions where the filter is bypassed). Done this pass: - Financial: Budgets, CreditMemos, FixedAssets, GiftCertificates, TaxRates, PricingTiers, VendorCredits, Accounts (year-end close), Invoices (tax-rate default, merchandise). - Operational: Inventory (bin/sample-panels/vendors/usage-edit), OvenScheduler (ovens/batches/queue), Customers (pricing tiers), InAppNotifications (mark-all-read), CatalogItems (by-category / merchandise / price-check lists). - AI: AiQuickQuote and Quotes (powder cost, predictions, walk-in customer, benchmark), Reports (budgets, 1099 vendors). Child-by-parent-FK and by-PK queries were left as-is (already scoped via the verified parent). Builds clean; 293 unit tests pass. REMAINING (next session): ReportsController.Analytics powder-usage query (line ~593) and the ~20 CompanySettings delete-protection Count/Any + dup-code checks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -193,8 +193,9 @@ public class InventoryController : Controller
|
||||
return RedirectToAction(nameof(Index));
|
||||
|
||||
var loc = location.Trim();
|
||||
var companyId = _tenantContext.GetCurrentCompanyId() ?? 0;
|
||||
var items = await _unitOfWork.InventoryItems.FindAsync(
|
||||
i => i.Location != null && i.Location.ToLower() == loc.ToLower());
|
||||
i => i.CompanyId == companyId && i.Location != null && i.Location.ToLower() == loc.ToLower());
|
||||
|
||||
var dtos = _mapper.Map<List<InventoryListDto>>(items.OrderBy(i => i.Name).ToList());
|
||||
ViewBag.Location = loc;
|
||||
@@ -1531,8 +1532,9 @@ public class InventoryController : Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
var companyId = _tenantContext.GetCurrentCompanyId() ?? 0;
|
||||
var allCoatings = (await _unitOfWork.InventoryItems.FindAsync(
|
||||
i => i.InventoryCategory != null && i.InventoryCategory.IsCoating,
|
||||
i => i.CompanyId == companyId && i.InventoryCategory != null && i.InventoryCategory.IsCoating,
|
||||
false,
|
||||
i => i.InventoryCategory))
|
||||
.OrderBy(i => i.Manufacturer).ThenBy(i => i.ColorName).ThenBy(i => i.Name)
|
||||
@@ -1609,7 +1611,7 @@ public class InventoryController : Controller
|
||||
var companyId = _tenantContext.GetCurrentCompanyId() ?? 0;
|
||||
ViewBag.AiInventoryAssistEnabled = await _subscriptionService.IsAiInventoryAssistEnabledAsync(companyId);
|
||||
|
||||
var vendors = (await _unitOfWork.Vendors.FindAsync(v => v.IsActive, false, v => v.Categories))
|
||||
var vendors = (await _unitOfWork.Vendors.FindAsync(v => v.CompanyId == companyId && v.IsActive, false, v => v.Categories))
|
||||
.OrderBy(v => v.CompanyName).ToList();
|
||||
ViewBag.Vendors = new SelectList(vendors, "Id", "CompanyName");
|
||||
|
||||
@@ -2225,7 +2227,7 @@ public class InventoryController : Controller
|
||||
return BadRequest("Only usage transactions can be edited here.");
|
||||
|
||||
var allJobs = await _unitOfWork.Jobs.FindAsync(
|
||||
j => !j.JobStatus.IsTerminalStatus,
|
||||
j => j.CompanyId == txn.CompanyId && !j.JobStatus.IsTerminalStatus,
|
||||
false,
|
||||
j => j.Customer,
|
||||
j => j.JobStatus);
|
||||
|
||||
Reference in New Issue
Block a user