Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type UITable = Map.Map User ([Permission], Map.Map Role [Permission])
- joinResults :: [(Int, String, Maybe Int, Maybe String, Maybe String, Maybe String, Maybe Int, Maybe String, Maybe Int, Maybe String, Maybe String, Maybe String)]
- joinResults = [
- (2765, "user1@gmail.com", Just 2, Just "manage_calendar ", Just "Trips::Trip", Just " Allowed to edit Departure calendar", Just 1, Just "Basic user", Just 3, Just "manage_content ", Just "Trips::Trip ", Just "Allowed to edit trip content"),
- (2766, "user2@gmail.com", Just 8, Just "manage_post_trip_email", Just "Trips::Trip", Just " Allowed to edit post trip email", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing),
- (1041, "user3@gmail.com", Nothing, Nothing, Nothing, Nothing, Nothing , Nothing , Nothing , Nothing , Nothing , Nothing ),
- (1429, "user4@gmail.com", Nothing, Nothing, Nothing, Nothing, Just 2, Just "Product manager", Just 6, Just "manage_confirmation_email ", Just "Trips::Trip", Just "Allowed to edit confirmation email")
- ]
- prepareUITable11 :: UITable
- prepareUITable11 =
- fromList (DL.map ((uid1,email,pid1,_,_,_,rid1,_,_,_,_,_)->(
- User {userId=uid1,userEmail=email},( (permissionIndividual uid1 pid1),
- (rolePermission uid1 rid1 )
- )
- )) joinResults)
- where
- permissionIndividual uid1 pid1 =
- case pid1 of
- Nothing -> []
- Just iPid -> DL.foldl' (arr x ->
- case x of
- (uid2,_,Just pid2,Just pact2,Just pclas2,Just pdes2,_,_,_,_,_,_)->
- if (iPid == pid2 && uid1 == uid2)
- then arr++[Permission {permissionId=pid2,permissionAction=pact2,permissionClass=pclas2,permissionDescripton=pdes2}]
- else arr
- _-> arr ) [] joinResults
- rolePermission uid1 rid1 =
- case rid1 of
- Nothing -> fromList []
- Just roleid -> fromList (DL.foldl' (arr1 x ->
- case x of
- (uid3,_,_,_,_,_,Just rrid1,Just rname1,_,_,_,_) ->
- if (uid1 == uid3 && roleid == rrid1)
- then arr1++[(Role {roleId=rrid1,roleName=rname1},DL.foldl' (arr2 y->
- case y of
- (uid4,_,_,_,_,_,Just rid4,_,Just rpid4,Just ract4,Just rclas4,Just rdes4)->
- if (uid1 == uid3 && uid3 == uid4 && roleid==rrid1 && rid4 == rrid1)
- then arr2++ [Permission {permissionId=rpid4,permissionAction=ract4,permissionClass=rclas4,permissionDescripton=rdes4}]
- else arr2
- _->arr2 ) [] joinResults)]
- else arr1
- _->arr1 ) [] joinResults)
Add Comment
Please, Sign In to add comment