Files
inter-hub/Web/Controller/ArchiveRecords.hs
Bernd Worsch ce42607fca fix(WP-0014/A2): close remaining pure-param and structural compilation errors
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>
2026-04-10 01:14:08 +00:00

58 lines
2.7 KiB
Haskell

module Web.Controller.ArchiveRecords where
import Web.Types
import Web.View.ArchiveRecords.Index
import Web.View.ArchiveRecords.Show
import Web.View.ArchiveRecords.LineageInspector
import Generated.Types
import IHP.Prelude
import IHP.ControllerPrelude
import Data.Coerce (coerce)
instance Controller ArchiveRecordsController where
beforeAction = ensureIsUser
action ArchiveRecordsAction = do
records <- query @ArchiveRecord |> orderByDesc #archivedAt |> fetch
render IndexView { records }
action ShowArchiveRecordAction { archiveRecordId } = do
record <- fetch archiveRecordId
render ShowView { record }
action ArchiveWidgetAction { widgetId } = do
widget <- fetch widgetId
now <- getCurrentTime
widget |> set #isArchived True |> updateRecord
newRecord @ArchiveRecord
|> set #subjectType "Widget"
|> set #subjectId (coerce widgetId)
|> set #archivedAt now
|> set #reason "Archived via UI"
|> set #archivedBy "operator"
|> createRecord
setSuccessMessage "Widget archived"
redirectTo ShowWidgetAction { widgetId }
action LineageInspectorAction { widgetId } = do
widget <- fetch widgetId
events <- sqlQuery "SELECT * FROM interaction_events WHERE widget_id = ? ORDER BY occurred_at DESC LIMIT 50" (Only widgetId)
annotations <- query @Annotation |> filterWhere (#widgetId, widgetId) |> orderByDesc #createdAt |> fetch
candidates <- query @RequirementCandidate |> filterWhere (#sourceWidgetId, widgetId) |> fetch
let candidateIds = map (.id) candidates
acceptedIds = map (.id) (filter (\c -> c.status == "accepted") candidates)
requirements <- query @Requirement |> filterWhereIn (#sourceCandidateId, acceptedIds) |> fetch
let reqIds = map (.id) requirements
decisions <- query @DecisionRecord |> filterWhereIn (#requirementId, map Just reqIds) |> fetch
let decisionIds = map (.id) decisions
deployments <- query @DeploymentRecord |> filterWhereIn (#decisionId, decisionIds) |> fetch
signals <- query @OutcomeSignal |> filterWhere (#widgetId, widgetId) |> fetch
archiveEntry <- fetchOneOrNothing (Id (coerce widgetId) :: Id ArchiveRecord)
-- archiveEntry lookup by subject_id
mArchive <- do
rs <- sqlQuery "SELECT * FROM archive_records WHERE subject_id = ? AND subject_type = 'Widget' ORDER BY archived_at DESC LIMIT 1" (Only widgetId)
pure (listToMaybe (rs :: [ArchiveRecord]))
render LineageInspectorView
{ widget, events, annotations, candidates, requirements
, decisions, deployments, signals, mArchive }