1 {-# LANGUAGE TemplateHaskell #-}
    2 module Databrary.Model.Authorize.Types
    3   ( Authorization(..)
    4   , Authorize(..)
    5   , mkAuthorizeRequest
    6   , with1210Utc
    7   ) where
    8 
    9 import Data.Time
   10 
   11 import Databrary.Has (Has(..))
   12 import Databrary.Model.Time
   13 import Databrary.Model.Permission.Types
   14 import Databrary.Model.Party.Types
   15 
   16 data Authorization = Authorization
   17   { authorizeAccess :: !Access
   18   , authorizeChild :: Party
   19   , authorizeParent :: Party
   20   }
   21 
   22 -- makeHasRec ''Authorization ['authorizeAccess]
   23 instance Has Access Authorization where
   24   view = authorizeAccess
   25 
   26 data Authorize = Authorize
   27   { authorization :: Authorization
   28   , authorizeExpires :: Maybe Timestamp
   29   }
   30 
   31 -- makeHasRec ''Authorize ['authorization]
   32 -- instance Has Authorization Authorize where
   33 --   view = authorization
   34 instance Has Access Authorize where
   35   view = (view . authorization)
   36 
   37 mkAuthorizeRequest :: Party -> Party -> Authorize
   38 mkAuthorizeRequest child parent =
   39     Authorize (Authorization mempty child parent) Nothing
   40 
   41 with1210Utc :: Day -> UTCTime
   42 with1210Utc d = UTCTime d 43210