2 -----------------------------------------------------------------
3 -- data Management = RolesRights | NodesRights | OperationsRights
4 -----------------------------------------------------------------
5 -----------------------------------------------------------------
6 -- Role Rights Management
7 -- rights to create roles (group)
8 -- Node Rights Management
9 -- rights to read/write Node
10 -- Operation Rights Management
11 -- rights for which operations
12 -----------------------------------------------------------------
13 -- Roles Rights Management
14 -----------------------------------------------------------------
16 -- admin : can create group and assign Node Rights to it
17 -- user : can not create group and assign Node rights inside his group (if he has the rights)
20 -- if all user are in public and have read/write permissions: everything is free inside the public group
22 -- in X institution x admin can create an gx group or a gy group for each department and assign user to it
23 -- users y can share with user y withing the group if he has the rights for it
24 -- an admin can give admin group to a user
26 -- Roles Rights Management are stored in "User Node"
27 -- right to read on group called "x" == can share permissions inside group x
28 -- right to write on group called "x" == can modify group x itself
30 -- Question: how to manage the hierarchy of roles/groups ?
31 -- Example: use can create a group inside a group but not outside of it
33 -----------------------------------------------------------------
34 -- Node Rights Management
35 -----------------------------------------------------------------
36 -- Les actions sur un Node (if /= Graph) depends on the rights of his parent
39 -- technically : get the column Node (in table nodes) with rights (ACL)
40 rightsOf :: Node -> Rights
41 rightsOf n = undefined
43 rightsOfNode :: User -> Node -> Rights
44 rightsOfNode u n = case n of
45 UserNode -> rightsOf n
46 ProjectNode -> rightsOf n
47 CorpusNode -> rightsOf n
48 GraphNode -> rightsOf n
49 _ -> rightsOf (parentOf n)
51 rightsOfNodeNgram :: User -> NodeNgram -> Rights
52 rightsOfNodeNgram u n = rightsOf n'
56 rightsOfNodeNgramNgram :: User -> NodeNgramNgram -> Rights
57 rightsOfNodeNgramNgram u n = rightsOf n'
65 -----------------------------------------------------------------
66 -- Operation Rights Management
67 -----------------------------------------------------------------
68 data Operation = Read | Write
69 -- Starting with simple case:
70 -- type ModifyRights = Write
73 data Rights = { _rightsRead :: Bool
74 , _rightsWrite :: Bool
76 deriving (Show, Read, Eq)
78 data LogRightsMessage = RightsSuccess | RightsError
79 deriving (Show, Read, Eq)
85 -----------------------------------------------------------------
87 -- find the tables where there is the relation Node / User / Rights
88 getRightsOfNodeWithUser :: Node -> User -> IO Rights
89 getRightsOfNodeWithUser n u = undefined
91 userCan :: Operation -> User -> Node -> IO Bool
93 rights <- getRightsOfNodeWithUser u n
95 Read -> _rightsRead rights
96 Write -> _rightsWrite rights
99 -- | User can (or can not) give/change rights of the Node
100 userCanModifyRights :: User -> Node -> IO Bool
101 userCanModifyRights u n = True `==` <$> userCan Write u n
103 -- | User can see who has access to the Node
104 userCanReadRights :: User -> Node -> IO Bool
105 userCanReadRights u n = True `==` <$> userCan Read u n
108 chmod :: Rights -> User -> Node -> IO LogRightsMessage
109 chmod r u n = undefined
111 chmod' :: Read -> Write -> User -> Node -> IO LogRightsMessage
112 chmod' r w u n = chmod rights u n
117 readAccessOnly :: User -> Node -> IO LogRightsMessage
118 readAccessOnly u n = chmod r u n
120 r = Rights True False
123 stopAccess :: User -> Node -> IO LogRightsMessage
126 chmodAll :: Rights -> User -> [Node] -> IO [LogRightsMessage]
127 chmd b r u ns = map (chmod b r u n) ns
129 chmodChildren :: Rights -> User -> [Node] -> IO [LogRightsMessage]
130 chmodChildren b r u n = map (chmod br u n) ns'