generated from coulomb/repo-seed
fix(WP-0017/E3): Layer 3 error fixes — controllers and views
Fix compilation errors across 6 controllers and 29 views: import cleanup, ResponseException pattern for API auth, type fixes, unused import removal. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import qualified Data.Text.Encoding as TE
|
||||
import qualified "cryptohash-sha256" Crypto.Hash.SHA256 as SHA256
|
||||
import qualified Data.ByteString.Base16 as Base16
|
||||
import Network.Wai (requestHeaders, responseLBS)
|
||||
import IHP.Controller.Response (ResponseException (..))
|
||||
|
||||
-- | Extract Bearer token from Authorization header and validate it
|
||||
-- against the api_keys table. Returns the ApiConsumer on success,
|
||||
@@ -52,12 +53,10 @@ unauthorized401 = respondWithStatus 401 $ object
|
||||
]
|
||||
|
||||
respondWithStatus :: (?respond :: Respond) => Int -> Value -> IO a
|
||||
respondWithStatus status body = do
|
||||
respondAndExit $ responseLBS
|
||||
(toEnum status)
|
||||
[("Content-Type", "application/json")]
|
||||
(encode body)
|
||||
error "respondAndExit: unreachable"
|
||||
respondWithStatus status body = throwIO $ ResponseException $ responseLBS
|
||||
(toEnum status)
|
||||
[("Content-Type", "application/json")]
|
||||
(encode body)
|
||||
|
||||
-- | SHA-256 hex hash of the key (same as stored in key_hash column)
|
||||
hashApiKey :: Text -> Text
|
||||
|
||||
@@ -5,6 +5,7 @@ import Web.View.ApiDashboard.Show
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ControllerPrelude
|
||||
import Web.Routes ()
|
||||
import Database.PostgreSQL.Simple (Only(..))
|
||||
|
||||
instance Controller ApiDashboardController where
|
||||
|
||||
@@ -6,6 +6,7 @@ import Web.View.EnvelopeEmissionContracts.Show
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ControllerPrelude
|
||||
import Web.Routes ()
|
||||
|
||||
instance Controller EnvelopeEmissionContractsController where
|
||||
beforeAction = ensureIsUser
|
||||
|
||||
@@ -30,8 +30,7 @@ instance Controller HubRegistryController where
|
||||
|> limit 10
|
||||
|> fetch
|
||||
adoptedPatterns <- sqlQuery
|
||||
"SELECT wp.id, wp.name, wp.widget_type, wp.hub_id, \
|
||||
\ pa.id AS adoption_id, pa.is_version_pinned, pa.adopted_at \
|
||||
"SELECT wp.id, wp.name, wp.widget_type, pa.is_version_pinned, pa.adopted_at \
|
||||
\ FROM pattern_adoptions pa \
|
||||
\ JOIN widget_patterns wp ON wp.id = pa.widget_pattern_id \
|
||||
\ WHERE pa.adopting_hub_id = ? \
|
||||
|
||||
@@ -5,7 +5,6 @@ import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ControllerPrelude
|
||||
import Data.Aeson (object, (.=), decode, Value)
|
||||
import Data.Coerce (coerce)
|
||||
import qualified Data.Aeson as A
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.ByteString.Lazy.Char8 as LBSC
|
||||
@@ -27,8 +26,8 @@ instance Controller InteractionEventsController where
|
||||
unless (eventType `elem` validEventTypes) do
|
||||
renderJsonWithStatusCode status422 (object ["error" .= ("unknown event_type" :: Text), "valid" .= validEventTypes])
|
||||
|
||||
let mUser = currentUserOrNothing
|
||||
let actorId = fmap (.id) mUser
|
||||
let mUser = currentUserOrNothing @User
|
||||
let actorId = fmap (\(Id uuid) -> uuid) (fmap (.id) mUser)
|
||||
actorType = maybe "anonymous" (const "user") mUser
|
||||
actorTypeParam = paramOrDefault @Text actorType "actor_type"
|
||||
viewContextRef = paramOrNothing @Text "view_context_ref"
|
||||
@@ -41,7 +40,7 @@ instance Controller InteractionEventsController where
|
||||
event <- newRecord @InteractionEvent
|
||||
|> set #widgetId widgetId
|
||||
|> set #eventType eventType
|
||||
|> set #actorId (coerce actorId)
|
||||
|> set #actorId actorId
|
||||
|> set #actorType actorTypeParam
|
||||
|> set #viewContextRef viewContextRef
|
||||
|> set #metadata metadata
|
||||
|
||||
@@ -6,6 +6,7 @@ import Web.View.Requirements.Show
|
||||
import Generated.Types
|
||||
import IHP.Prelude
|
||||
import IHP.ControllerPrelude
|
||||
import Web.Routes ()
|
||||
|
||||
instance Controller RequirementsController where
|
||||
beforeAction = ensureIsUser
|
||||
|
||||
Reference in New Issue
Block a user