-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAVACL.h
More file actions
265 lines (233 loc) · 8.16 KB
/
Copy pathAVACL.h
File metadata and controls
265 lines (233 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
* @file AVACL.h
* @author yang chaozhong <cyang@avoscloud.com>
* @date Fri Jul 18 17:50:49 2014
*
* @brief AVACL
*
* Copyright 2014 AVOS Cloud Inc. All rights reserved.
*/
#ifndef INCLUDE_ACL_AVACL_H_
#define INCLUDE_ACL_AVACL_H_
#include <string>
#include "json/json.h"
#include "Utils/AVPlatformMacros.h"
NS_AV_BEGIN
class AVUser;
class AVRole;
class AVACL {
private:
AVACL();
Json::Value dictionaryToReadAndWrite(bool read, bool write);
Json::Value dictionaryForKeyIfCreate(std::string key, bool create);
void allowReadForKey(bool allowed, std::string key);
bool isReadAllowedForKey(std::string key);
void allowWriteForyKey(bool allowed, std::string key);
bool isWriteAllowedForyKey(std::string key);
std::string roleName(std::string name);
public:
Json::Value permissionById;
public:
/**
* Creates an ACL with no permissions granted.
*
* @return pointer to AVACL instance
*/
static AVACL* ACL();
/**
* Creates an ACL where only the provided user has access.
*
* @param user the AVUser
*
* @return pointer to AVACL instance
*/
static AVACL* ACLWithUser(AVUser* user);
/**
* release memory.
*
*/
void release();
/**
* Set whether the public is allowed to read this object.
*
* @param allowed allowed or not
*/
void setPublicReadAccess(bool allowed);
/**
* Gets whether the public is allowed to read this object.
*
* @return true if allowed else false
*/
bool getPublicReadAccess();
/**
* Set whether the public is allowed to write this object.
*
* @param allowed allowed or not
*/
void setPublicWriteAccess(bool allowed);
/**
* Gets whether the public is allowed to write this object.
*
* @return true if allowed else false
*/
bool getPublicWriteAccess();
/**
* Set whether the given user id is allowed to read this object.
*
* @param allowed allowed or not
* @param userId the AVUser's objectId
*/
void setReadAccessForUserId(bool allowed, std::string userId);
/**
* Gets whether the given user id is *explicitly* allowed to read this object.
* Even if this returns false, the user may still be able to access it if getPublicReadAccess returns true
* or if the user belongs to a role that has access.
*
* @param userId the AVUser's objectId
*
* @return true if allowed else false
*/
bool getReadAccessForUserId(std::string userId);
/**
* Set whether the given user id is allowed to write this object.
*
* @param allowed allowed or not
* @param userId the AVUser's objectId
*/
void setWriteAccessForUserId(bool allowed, std::string userId);
/**
* Gets whether the given user id is *explicitly* allowed to write this object.
* Even if this returns false, the user may still be able to write it if getPublicWriteAccess returns true
* or if the user belongs to a role that has access.
*
* @param userId the AVUser's objectId
*
* @return true if allowed else false
*/
bool getWriteAccessForUserId(std::string userId);
/**
* Set whether the given user is allowed to read this object.
*
* @warning if the user doesn't have valid objectId, no operation is performed.
* @param allowed allowed or not
* @param user the AVUser
*/
void setReadAccessForUser(bool allowed, AVUser* user);
/**
* Gets whether the given user is *explicitly* allowed to read this object.
* Even if this returns false, the user may still be able to access it if getPublicReadAccess returns true
* or if the user belongs to a role that has access.
*
* @param user the AVUser
*
* @return true if allowed else false. if the user doesn't have valid objectId, return true.
*/
bool getReadAccessForUser(AVUser* user);
/**
* Set whether the given user is allowed to write this object.
*
* @warning if the user doesn't have valid objectId, no operation is performed.
* @param allowed allowed or not
* @param user the AVUser
*/
void setWriteAccessForUser(bool allowed, AVUser* user);
/**
* Gets whether the given user is *explicitly* allowed to write this object.
* Even if this returns false, the user may still be able to write it if getPublicWriteAccess returns true
* or if the user belongs to a role that has access.
*
* @param user the AVUser
*
* @return true if allowed else false. if the user doesn't have valid objectId, return true.
*/
bool getWriteAccessForUser(AVUser* user);
/**
* Set whether users belonging to the role with the given name are allowed
* to read this object.
*
* @param allowed The name of the role.
* @param name Whether the given role can read this object.
*/
void setReadAccessForRoleWithName(bool allowed, std::string name);
/**
* Get whether users belonging to the role with the given name are allowed
* to read this object. Even if this returns false, the role may still
* be able to read it if a parent role has read access.
*
* @param name The name of the role.
*
* @return if allowed else false
*/
bool getReadAccessForRoleWithName(std::string name);
/**
* Set whether users belonging to the role with the given name are allowed
* to write this object.
*
* @param allowed The name of the role.
* @param name Whether the given role can write this object.
*/
void setWriteAccessForRoleWithName(bool allowed, std::string name);
/**
* Get whether users belonging to the role with the given name are allowed
* to write this object. Even if this returns false, the role may still
* be able to write it if a parent role has write access.
*
* @param name The name of the role.
*
* @return if allowed else false
*/
bool getWriteAccessForRoleWithName(std::string name);
/**
* Set whether users belonging to the given role are allowed to read this
* object. The role must already be saved on the server and its data must have
* been fetched in order to use this method.
*
* @param allowed Whether the given role can read this object.
* @param role The role to assign access.
*/
void setReadAccessForRole(bool allowed, AVRole* role);
/**
* Get whether users belonging to the given role are allowed to read this
* object. Even if this returns NO, the role may still be able to
* read it if a parent role has read access. The role must already be saved on
* the server and its data must have been fetched in order to use this method.
*
* @param role the given role
*
* @return true if the role has read access. false otherwise.
*/
bool getReadAccessForRole(AVRole* role);
/**
* Set whether users belonging to the given role are allowed to write this
* object. The role must already be saved on the server and its data must have
* been fetched in order to use this method.
*
* @param allowed Whether the given role can write this object.
* @param role The role to assign access.
*/
void setWriteAccessForRole(bool allowed, AVRole* role);
/**
* Get whether users belonging to the given role are allowed to write this
* object. Even if this returns NO, the role may still be able to
* write it if a parent role has write access. The role must already be saved on
* the server and its data must have been fetched in order to use this method.
*
* @param role the given role
*
* @return true if the role has write access. false otherwise.
*/
bool getWriteAccessForRole(AVRole* role);
/**
* Sets a default ACL that will be applied to all AVObjects when they are created.
*
* @param acl The ACL to use as a template for all AVObjects created after setDefaultACL has been called.
* This value will be copied and used as a template for the creation of new ACLs, so changes to the
* instance after setDefaultACL has been called will not be reflected in new AVObjects.
* @param currentUserAccess If true, the AVACL that is applied to newly-created AVObjects will
* provide read and write access to the currentUser at the time of creation. If false,
* the provided ACL will be used without modification. If acl is nil, this value is ignored.
*/
static void setDefaultACLWithCurrentUser(AVACL* acl, bool currentUserAccess);
};
NS_AV_END
#endif // INCLUDE_ACL_AVACL_H_