generated from coulomb/repo-seed
Convert all remaining `<- paramOrNothing / param / paramOrDefault /
currentUserOrNothing` monadic binds to `let` — these functions are pure
(ImplicitParams-based) in IHP v1.5, so `<-` is a type error in an IO
do-block.
Controllers fixed:
AgentDelegations, AiGovernancePolicies, Annotations, ApiConsumers,
CollectiveProposals, DecisionRecords, DeploymentRecords,
HubCapabilityManifests, HubRoutingRules, InstitutionalKnowledge,
OutcomeCorrelations, RequirementCandidates, TypeRegistries,
WebhookSubscriptions, Widgets,
Api/V2/{Annotations,InteractionEvents,Token}
WebhookSubscriptions: remove orphaned `Right () ->` case arm that was
left inside a bare `unless` block (structural parse error).
Also carries forward all in-progress fixes from the working tree:
helpers (AgentBridge, ApiRateLimit, BottleneckDetector,
CrossHubPropagation, FrictionScore),
views (CanSelect instances, HSX lambda extraction, formFor wrappers),
env/build (envrc GHCi perms, flake.nix Tailwind + GHC resource limits,
static/app.css additional Tailwind output).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
2.5 KiB
Haskell
68 lines
2.5 KiB
Haskell
module Web.Controller.WebhookSubscriptions where
|
|
|
|
import Web.Types
|
|
import Web.View.WebhookSubscriptions.New
|
|
import Generated.Types
|
|
import IHP.Prelude
|
|
import IHP.ControllerPrelude
|
|
import qualified Data.ByteString.Random as Random
|
|
import qualified Data.Text.Encoding as TE
|
|
import qualified Data.ByteString.Base16 as Base16
|
|
|
|
-- Webhook event topics are framework lifecycle events, not interaction event types
|
|
allowedWebhookTopics :: [Text]
|
|
allowedWebhookTopics =
|
|
[ "interaction_event.created"
|
|
, "annotation.created"
|
|
, "requirement_candidate.created"
|
|
, "decision_record.created"
|
|
, "deployment_record.created"
|
|
, "outcome_signal.created"
|
|
]
|
|
|
|
instance Controller WebhookSubscriptionsController where
|
|
beforeAction = ensureIsUser
|
|
|
|
action WebhookSubscriptionsAction { apiConsumerId } = do
|
|
redirectTo (ShowApiConsumerAction apiConsumerId)
|
|
|
|
action NewWebhookSubscriptionAction { apiConsumerId } = do
|
|
consumer <- fetch apiConsumerId
|
|
let subscription = newRecord @WebhookSubscription
|
|
render NewView { subscription, consumer }
|
|
|
|
action CreateWebhookSubscriptionAction = do
|
|
let apiConsumerId = param @(Id ApiConsumer) "apiConsumerId"
|
|
eventType = param @Text "eventType"
|
|
targetUrl = param @Text "targetUrl"
|
|
consumer <- fetch apiConsumerId
|
|
|
|
-- Validate against allowed webhook topics
|
|
unless (eventType `elem` allowedWebhookTopics) $ do
|
|
setErrorMessage ("Unknown webhook topic: " <> eventType)
|
|
redirectTo (NewWebhookSubscriptionAction apiConsumerId)
|
|
|
|
-- Generate HMAC signing secret
|
|
secretBytes <- liftIO $ Random.random 32
|
|
let secret = TE.decodeUtf8 (Base16.encode secretBytes)
|
|
_sub <- newRecord @WebhookSubscription
|
|
|> set #apiConsumerId consumer.id
|
|
|> set #eventType eventType
|
|
|> set #targetUrl targetUrl
|
|
|> set #secret secret
|
|
|> set #isActive True
|
|
|> createRecord
|
|
redirectTo (ShowApiConsumerAction apiConsumerId)
|
|
|
|
action ToggleWebhookSubscriptionAction { webhookSubscriptionId } = do
|
|
sub <- fetch webhookSubscriptionId
|
|
sub |> set #isActive (not sub.isActive) |> updateRecord
|
|
consumer <- fetch sub.apiConsumerId
|
|
redirectTo (ShowApiConsumerAction consumer.id)
|
|
|
|
action DeleteWebhookSubscriptionAction { webhookSubscriptionId } = do
|
|
sub <- fetch webhookSubscriptionId
|
|
consumerId <- pure sub.apiConsumerId
|
|
deleteRecord sub
|
|
redirectTo (ShowApiConsumerAction consumerId)
|