make associations
This commit is contained in:
parent
8303d8688a
commit
28063cfffe
3 changed files with 25 additions and 5 deletions
|
@ -27,7 +27,10 @@ roleUpdate _ _ = notImplemented
|
||||||
|
|
||||||
roleDelete _ _ = notImplemented
|
roleDelete _ _ = notImplemented
|
||||||
|
|
||||||
roleAssociationList = notImplemented
|
roleAssociationList
|
||||||
|
:: MateHandler [RoleAssociation]
|
||||||
|
roleAssociationList =
|
||||||
|
selectAllRoleAssociations =<< asks rsConnection
|
||||||
|
|
||||||
roleAssociationSubmit _ _ = notImplemented
|
roleAssociationSubmit _ _ = notImplemented
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ initRole = mconcat
|
||||||
initUserToRole :: PGS.Query
|
initUserToRole :: PGS.Query
|
||||||
initUserToRole = mconcat
|
initUserToRole = mconcat
|
||||||
[ "CREATE TABLE IF NOT EXISTS \"user_to_role\" ("
|
[ "CREATE TABLE IF NOT EXISTS \"user_to_role\" ("
|
||||||
, "user_id INTEGER NOT NULL,"
|
, "user_id INTEGER NOT NULL REFERENCES \"user\"(\"user_id\"),"
|
||||||
, "role_id INTEGER NOT NULL,"
|
, "role_id INTEGER NOT NULL REFERENCES \"role\"(\"role_id\"),"
|
||||||
, "PRIMARY KEY (user_id, role_id)"
|
, "PRIMARY KEY (user_id, role_id)"
|
||||||
, ")"
|
, ")"
|
||||||
]
|
]
|
||||||
|
@ -261,6 +261,24 @@ queryRoleIdByCapabilities (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11) conn =
|
||||||
]
|
]
|
||||||
return $ (\(rid, _, _, _, _, _, _, _, _, _, _, _, _) -> rid) (head roles)
|
return $ (\(rid, _, _, _, _, _, _, _, _, _, _, _, _) -> rid) (head roles)
|
||||||
|
|
||||||
|
|
||||||
|
selectAllRoleAssociations
|
||||||
|
:: PGS.Connection
|
||||||
|
-> MateHandler [RoleAssociation]
|
||||||
|
selectAllRoleAssociations conn = do
|
||||||
|
rawRoleAssocs <- liftIO $ runSelect conn (
|
||||||
|
queryTable userToRoleTable
|
||||||
|
) :: MateHandler
|
||||||
|
[
|
||||||
|
( Int
|
||||||
|
, Int
|
||||||
|
)
|
||||||
|
]
|
||||||
|
return $ map
|
||||||
|
(\(uid, rid) -> RoleAssociation uid rid)
|
||||||
|
rawRoleAssocs
|
||||||
|
|
||||||
|
|
||||||
associateUserToRole
|
associateUserToRole
|
||||||
:: Int -- ^ User id
|
:: Int -- ^ User id
|
||||||
-> Int -- ^ Role id
|
-> Int -- ^ Role id
|
||||||
|
|
|
@ -50,8 +50,7 @@ instance ToJSON RoleSubmit where
|
||||||
instance FromJSON RoleSubmit
|
instance FromJSON RoleSubmit
|
||||||
|
|
||||||
data RoleAssociation = RoleAssociation
|
data RoleAssociation = RoleAssociation
|
||||||
{ roleAssociationId :: Int
|
{ roleAssociationUser :: Int
|
||||||
, roleAssociationUser :: Int
|
|
||||||
, roleAssociationRole :: Int
|
, roleAssociationRole :: Int
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
Loading…
Reference in a new issue