Add three-layer feature gating for AI Catalog Price Check
Adds platform-level, plan-level (Enterprise only), and per-company toggles for the AI Catalog Price Check feature. Includes: - Company.AiCatalogPriceCheckEnabled per-company flag - SubscriptionPlanConfig.AllowAiCatalogPriceCheck plan-level flag - PlatformSetting 'AiCatalogPriceCheckEnabled' global kill switch - IPlatformSettingsService.GetBoolAsync helper - ISubscriptionService.CanUseAiCatalogPriceCheckAsync - UI controls in Companies/Edit, PlatformSubscription/Edit+Index, and SubscriptionManagement/Manage - Migration AddAiCatalogPriceCheckGating applied Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Generated
+9301
File diff suppressed because it is too large
Load Diff
+98
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PowderCoating.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAiCatalogPriceCheckGating : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AllowAiCatalogPriceCheck",
|
||||
table: "SubscriptionPlanConfigs",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AiCatalogPriceCheckEnabled",
|
||||
table: "Companies",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "PlatformSettings",
|
||||
columns: ["Id", "Key", "Value", "Label", "Description", "GroupName"],
|
||||
values: new object[,]
|
||||
{
|
||||
{ 9, "AiCatalogPriceCheckEnabled", "true", "AI Catalog Price Check Enabled",
|
||||
"When true (default), the AI Catalog Price Check feature is available to companies on qualifying plans. Set to false to disable it platform-wide.",
|
||||
"AI Features" }
|
||||
});
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 1,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5012));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 2,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5018));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 3,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5020));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "PlatformSettings",
|
||||
keyColumn: "Id",
|
||||
keyValue: 9);
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AllowAiCatalogPriceCheck",
|
||||
table: "SubscriptionPlanConfigs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AiCatalogPriceCheckEnabled",
|
||||
table: "Companies");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 1,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6987));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 2,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6993));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "PricingTiers",
|
||||
keyColumn: "Id",
|
||||
keyValue: 3,
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6994));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1530,6 +1530,9 @@ namespace PowderCoating.Infrastructure.Migrations
|
||||
b.Property<string>("Address")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("AiCatalogPriceCheckEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("AiInventoryAssistEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
@@ -5833,7 +5836,7 @@ namespace PowderCoating.Infrastructure.Migrations
|
||||
{
|
||||
Id = 1,
|
||||
CompanyId = 0,
|
||||
CreatedAt = new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6987),
|
||||
CreatedAt = new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5012),
|
||||
Description = "Standard pricing for regular customers",
|
||||
DiscountPercent = 0m,
|
||||
IsActive = true,
|
||||
@@ -5844,7 +5847,7 @@ namespace PowderCoating.Infrastructure.Migrations
|
||||
{
|
||||
Id = 2,
|
||||
CompanyId = 0,
|
||||
CreatedAt = new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6993),
|
||||
CreatedAt = new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5018),
|
||||
Description = "5% discount for preferred customers",
|
||||
DiscountPercent = 5m,
|
||||
IsActive = true,
|
||||
@@ -5855,7 +5858,7 @@ namespace PowderCoating.Infrastructure.Migrations
|
||||
{
|
||||
Id = 3,
|
||||
CompanyId = 0,
|
||||
CreatedAt = new DateTime(2026, 4, 25, 22, 34, 50, 1, DateTimeKind.Utc).AddTicks(6994),
|
||||
CreatedAt = new DateTime(2026, 4, 26, 12, 26, 21, 727, DateTimeKind.Utc).AddTicks(5020),
|
||||
Description = "10% discount for premium customers",
|
||||
DiscountPercent = 10m,
|
||||
IsActive = true,
|
||||
@@ -7183,6 +7186,9 @@ namespace PowderCoating.Infrastructure.Migrations
|
||||
b.Property<bool>("AllowAccounting")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("AllowAiCatalogPriceCheck")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("AllowAiInventoryAssist")
|
||||
.HasColumnType("bit");
|
||||
|
||||
|
||||
@@ -41,6 +41,17 @@ public class PlatformSettingsService : IPlatformSettingsService
|
||||
return setting?.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a platform setting as a boolean. Returns <paramref name="defaultValue"/> when
|
||||
/// the key is missing or the stored value cannot be parsed as a boolean.
|
||||
/// </summary>
|
||||
public async Task<bool> GetBoolAsync(string key, bool defaultValue = false)
|
||||
{
|
||||
var value = await GetAsync(key);
|
||||
if (value == null) return defaultValue;
|
||||
return bool.TryParse(value, out var result) ? result : defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates or updates the platform setting identified by <paramref name="key"/>.
|
||||
/// Records <paramref name="updatedBy"/> (typically the SuperAdmin's username) and
|
||||
|
||||
@@ -323,6 +323,19 @@ public class SubscriptionService : ISubscriptionService
|
||||
/// (3) monthly usage quota from <see cref="GetAiPhotoQuoteUsageAsync"/>.
|
||||
/// Comped companies bypass all three gates.
|
||||
/// </summary>
|
||||
public async Task<bool> CanUseAiCatalogPriceCheckAsync(int companyId)
|
||||
{
|
||||
var (company, config) = await GetCompanyAndConfigAsync(companyId);
|
||||
if (company == null) return false;
|
||||
if (company.IsComped) return true;
|
||||
|
||||
// Plan-level gate: Enterprise plan must have this feature enabled
|
||||
if (config != null && !config.AllowAiCatalogPriceCheck) return false;
|
||||
|
||||
// Company-level toggle: SuperAdmin can disable per company
|
||||
return company.AiCatalogPriceCheckEnabled;
|
||||
}
|
||||
|
||||
public async Task<bool> CanUseAiPhotoQuoteAsync(int companyId)
|
||||
{
|
||||
var (company, config) = await GetCompanyAndConfigAsync(companyId);
|
||||
|
||||
Reference in New Issue
Block a user