1 {-# LANGUAGE TemplateHaskell, RecordWildCards #-} 2 module Databrary.Model.VolumeAccess.Types 3 ( VolumeAccess(..) 4 , getShareFullDefault 5 ) where 6 7 import Data.Int (Int16) 8 9 -- import Databrary.Has (Has(..)) 10 import Databrary.Model.Id.Types 11 import Databrary.Model.Permission.Types 12 import Databrary.Model.Volume.Types 13 import Databrary.Model.Party.Types 14 15 data VolumeAccess = VolumeAccess 16 { volumeAccessIndividual, volumeAccessChildren :: Permission 17 , volumeAccessSort :: Maybe Int16 18 , volumeAccessShareFull :: Maybe Bool 19 , volumeAccessParty :: Party 20 , volumeAccessVolume :: Volume 21 } 22 23 getShareFullDefault :: Party -> Permission -> Maybe Bool 24 getShareFullDefault targetParty individualAccessLevel = 25 if (getPartyId targetParty, individualAccessLevel) == (nobodyId, PermissionPUBLIC) 26 then nobodyPublicLegacyDefault 27 else generalDefault 28 where 29 nobodyId :: Id Party 30 nobodyId = (getPartyId . accountParty . siteAccount) nobodySiteAuth 31 nobodyPublicLegacyDefault = Just True 32 generalDefault = Nothing 33 34 {- 35 instance Has Volume VolumeAccess where 36 view = volumeAccessVolume 37 instance Has (Id Volume) VolumeAccess where 38 view = (Databrary.Has.view . volumeAccessVolume) 39 instance Has Party VolumeAccess where 40 view = volumeAccessParty 41 instance Has (Id Party) VolumeAccess where 42 view = (view . volumeAccessParty) 43 -}