Guest User

Untitled

a guest
Feb 23rd, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. type UITable = Map.Map User ([Permission], Map.Map Role [Permission])
  2.  
  3. joinResults :: [(Int, String, Maybe Int, Maybe String, Maybe String, Maybe String, Maybe Int, Maybe String, Maybe Int, Maybe String, Maybe String, Maybe String)]
  4. joinResults = [
  5. (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"),
  6. (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),
  7. (1041, "user3@gmail.com", Nothing, Nothing, Nothing, Nothing, Nothing , Nothing , Nothing , Nothing , Nothing , Nothing ),
  8. (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")
  9. ]
  10.  
  11.  
  12.  
  13.  
  14.  
  15. prepareUITable11 :: UITable
  16. prepareUITable11 =
  17. fromList (DL.map ((uid1,email,pid1,_,_,_,rid1,_,_,_,_,_)->(
  18. User {userId=uid1,userEmail=email},( (permissionIndividual uid1 pid1),
  19. (rolePermission uid1 rid1 )
  20. )
  21. )) joinResults)
  22. where
  23. permissionIndividual uid1 pid1 =
  24. case pid1 of
  25. Nothing -> []
  26. Just iPid -> DL.foldl' (arr x ->
  27. case x of
  28. (uid2,_,Just pid2,Just pact2,Just pclas2,Just pdes2,_,_,_,_,_,_)->
  29. if (iPid == pid2 && uid1 == uid2)
  30. then arr++[Permission {permissionId=pid2,permissionAction=pact2,permissionClass=pclas2,permissionDescripton=pdes2}]
  31. else arr
  32. _-> arr ) [] joinResults
  33.  
  34. rolePermission uid1 rid1 =
  35. case rid1 of
  36. Nothing -> fromList []
  37. Just roleid -> fromList (DL.foldl' (arr1 x ->
  38. case x of
  39. (uid3,_,_,_,_,_,Just rrid1,Just rname1,_,_,_,_) ->
  40. if (uid1 == uid3 && roleid == rrid1)
  41. then arr1++[(Role {roleId=rrid1,roleName=rname1},DL.foldl' (arr2 y->
  42. case y of
  43. (uid4,_,_,_,_,_,Just rid4,_,Just rpid4,Just ract4,Just rclas4,Just rdes4)->
  44. if (uid1 == uid3 && uid3 == uid4 && roleid==rrid1 && rid4 == rrid1)
  45. then arr2++ [Permission {permissionId=rpid4,permissionAction=ract4,permissionClass=rclas4,permissionDescripton=rdes4}]
  46. else arr2
  47. _->arr2 ) [] joinResults)]
  48. else arr1
  49. _->arr1 ) [] joinResults)
Add Comment
Please, Sign In to add comment