-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module ExRoles where | ||
|
||
import MockAPI | ||
import Permissions | ||
|
||
import Data.Set (Set) | ||
import qualified Data.Set as Set | ||
|
||
import Data.Map (Map) | ||
import qualified Data.Map as Map | ||
|
||
import Data.Monoid | ||
|
||
exRoles = Roles $ accountAdministrator <> productAdministrator <> productEditor | ||
|
||
allPermissions :: [Permission] | ||
allPermissions = concat [ map PP [minBound .. maxBound] | ||
, map OP [minBound .. maxBound] | ||
, map UP [minBound .. maxBound] | ||
] | ||
|
||
accountAdministrator = Map.singleton "Account administrator" (RoleAttributes roles users) | ||
where | ||
roles = Set.fromList allPermissions | ||
users = Set.fromList [ User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
] | ||
|
||
productAdministrator = Map.singleton "Product administrator" (RoleAttributes roles users) | ||
where | ||
roles = Set.fromList $ map PP [minBound .. maxBound] | ||
users = Set.fromList [ User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
] | ||
|
||
productEditor = Map.singleton "Product editor" (RoleAttributes roles users) | ||
where | ||
roles = Set.fromList $ map PP [ViewAllProductDetails, EditProdTextualContent, EditProdPhotos] | ||
users = Set.fromList [ User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,18 @@ import qualified Data.Map as Map | |
|
||
import Permissions | ||
|
||
type Email = Text | ||
|
||
data User = User | ||
{ userMail :: Text | ||
{ userMail :: Email | ||
} deriving (Show, Eq, Ord, Generic) | ||
|
||
instance FromHttpApiData User where | ||
parseUrlPiece mail = Right (User mail) | ||
|
||
instance ToHttpApiData User where | ||
toUrlPiece (User mail) = mail | ||
|
||
instance ToJSON User | ||
instance FromJSON User | ||
|
||
|
@@ -45,18 +53,10 @@ instance Wrapped Roles where | |
type Unwrapped Roles = Map RoleName RoleAttributes | ||
_Wrapped' = iso unRoles Roles | ||
|
||
exRoles = Roles $ Map.singleton "Account administrator" (RoleAttributes roles users) | ||
where | ||
roles = Set.fromList [ PP ViewAllProductDetails ] | ||
users = Set.fromList [ User "[email protected]" | ||
, User "[email protected]" | ||
, User "[email protected]" | ||
] | ||
|
||
instance ToJSON Roles | ||
instance FromJSON Roles | ||
|
||
type MockApi = "deleteUserRole" :> ReqBody '[JSON] RoleName :> "user" :> ReqBody '[JSON] User :> Delete '[JSON] NoContent | ||
:<|> "showRoles" :> Get '[JSON] Roles | ||
type MockApi = "delete" :> Capture "role" RoleName :> Capture "user" User :> Delete '[JSON] NoContent | ||
:<|> "roles" :> Get '[JSON] Roles | ||
:<|> "assets" :> Raw | ||
:<|> Raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters