Skip to content

Commit

Permalink
Oops.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Feb 8, 2023
1 parent 99c1a9f commit b1d530c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions services/brig/src/Brig/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Brig.Options where
import Brig.Queue.Types (Queue (..))
import Brig.SMTP (SMTPConnType (..))
import Brig.User.Auth.Cookie.Limit
import Brig.Whitelist (WhitelistEmailDomains (..), WhitelistPhonePrefixes (..))
import Brig.Whitelist (AllowlistEmailDomains (..), AllowlistPhonePrefixes (..))
import qualified Brig.ZAuth as ZAuth
import Control.Applicative
import qualified Control.Lens as Lens
Expand Down Expand Up @@ -492,8 +492,8 @@ data Settings = Settings
-- | STOMP broker credentials
setStomp :: !(Maybe FilePathSecrets),
-- | Whitelist of allowed emails/phones
setAllowlistEmailDomains :: !(Maybe WhitelistEmailDomains),
setAllowlistPhonePrefixes :: !(Maybe WhitelistPhonePrefixes),
setAllowlistEmailDomains :: !(Maybe AllowlistEmailDomains),
setAllowlistPhonePrefixes :: !(Maybe AllowlistPhonePrefixes),
-- | Max. number of sent/accepted
-- connections per user
setUserMaxConnections :: !Int64,
Expand Down
18 changes: 9 additions & 9 deletions services/brig/src/Brig/Whitelist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
--
-- Email/phone whitelist.
module Brig.Whitelist
( WhitelistEmailDomains (..),
WhitelistPhonePrefixes (..),
( AllowlistEmailDomains (..),
AllowlistPhonePrefixes (..),
verify,
)
where
Expand All @@ -31,20 +31,20 @@ import Imports
import Wire.API.User.Identity

-- | A service providing a whitelist of allowed email addresses and phone numbers
data WhitelistEmailDomains = WhitelistEmailDomains [Text]
data AllowlistEmailDomains = AllowlistEmailDomains [Text]
deriving (Show, Generic)

instance FromJSON WhitelistEmailDomains
instance FromJSON AllowlistEmailDomains

data WhitelistPhonePrefixes = WhitelistPhonePrefixes [Text]
data AllowlistPhonePrefixes = AllowlistPhonePrefixes [Text]
deriving (Show, Generic)

instance FromJSON WhitelistPhonePrefixes
instance FromJSON AllowlistPhonePrefixes

-- | Consult the whitelist settings in brig's config file and verify that the provided
-- email/phone address is whitelisted.
verify :: Maybe WhitelistEmailDomains -> Maybe WhitelistPhonePrefixes -> Either Email Phone -> Bool
verify (Just (WhitelistEmailDomains allowed)) _ (Left email) = emailDomain email `elem` allowed
verify _ (Just (WhitelistPhonePrefixes allowed)) (Right phone) = any (`Text.isPrefixOf` fromPhone phone) allowed
verify :: Maybe AllowlistEmailDomains -> Maybe AllowlistPhonePrefixes -> Either Email Phone -> Bool
verify (Just (AllowlistEmailDomains allowed)) _ (Left email) = emailDomain email `elem` allowed
verify _ (Just (AllowlistPhonePrefixes allowed)) (Right phone) = any (`Text.isPrefixOf` fromPhone phone) allowed
verify Nothing _ (Left _) = True
verify _ Nothing (Right _) = True

0 comments on commit b1d530c

Please sign in to comment.