using Dapr; using EntitlementBLL.Common; using EntitlementBLL.Interfaces; using Microsoft.AspNetCore.Mvc; namespace EntitlementSL.Subscriptions; // eap.capability.disabled → mirrors the disable as a FLAGSTATUS=2 kill switch for the mapped // feature. Per the plan's OL-3 default: the mechanism (Dapr-subscribe + kill-switch-write) is // implemented now; the exact capability-name → FEATURECODE mapping is a TODO pending IDMS/EAP // alignment — do not block the rest of the build on it. // // TODO(IDMS/EAP alignment): CapabilityName currently maps to FEATURECODE via the literal // convention "EAP." + CapabilityName (e.g. capability "MULTI_WH" → feature code "EAP.MULTI_WH"). // Replace with whatever real mapping IDMS/EAP settle on once that alignment session happens. [ApiController] public class CapabilityDisabledSubscriber : ControllerBase { private readonly IFeatureFlagBLL _FlagBLL; private readonly IFeatureFlagService _FlagService; private readonly IEntitlementLoginFactory _LoginFactory; private readonly ILogger _Logger; public CapabilityDisabledSubscriber( IFeatureFlagBLL flagBLL, IFeatureFlagService flagService, IEntitlementLoginFactory loginFactory, ILogger logger) { _FlagBLL = flagBLL; _FlagService = flagService; _LoginFactory = loginFactory; _Logger = logger; } [Topic("goodbooks-pubsub", "eap.capability.disabled")] [HttpPost("/lic/Subscriptions/CapabilityDisabled")] public async Task HandleAsync([FromBody] CapabilityDisabledEvent evt, CancellationToken ct) { try { var login = _LoginFactory.Create(-1); var featureCode = $"EAP.{evt.CapabilityName}"; // TODO: see class header note var flag = await _FlagBLL.GetByFeatureCodeAsync(featureCode, login, ct); if (flag is null) { _Logger.LogWarning( "CapabilityDisabledSubscriber: no MENTITLEMENTFEATUREFLAG mapped for capability {CapabilityName} " + "(looked up FeatureCode {FeatureCode}) — no-op pending IDMS/EAP mapping alignment.", evt.CapabilityName, featureCode); return Ok(); } await _FlagService.ActivateKillSwitchAsync(flag.FeatureFlagId, $"EAP capability disabled: {evt.CapabilityName}", -1, ct); _Logger.LogInformation("Mirrored EAP capability disable as kill switch: FeatureFlagId {FeatureFlagId}", flag.FeatureFlagId); return Ok(); } catch (Exception ex) { _Logger.LogError(ex, "CapabilityDisabledSubscriber failed for CapabilityName {CapabilityName}", evt.CapabilityName); return StatusCode(500, ex.Message); } } public record CapabilityDisabledEvent(string CapabilityName, string Reason); }