-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathParseCLP.d.ts
289 lines (289 loc) · 11.1 KB
/
ParseCLP.d.ts
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import ParseRole from './ParseRole';
import ParseUser from './ParseUser';
type Entity = ParseUser | ParseRole | string;
type UsersMap = Record<string, boolean | any>;
export type PermissionsMap = {
writeUserFields?: string[];
readUserFields?: string[];
} & Record<string, UsersMap>;
/**
* Creates a new CLP.
* If no argument is given, the CLP has no permissions for anyone.
* If the argument is a Parse.User or Parse.Role, the CLP will have read and write
* permission for only that user or role.
* If the argument is any other JSON object, that object will be interpretted
* as a serialized CLP created with toJSON().
*
* <p>A CLP, or Class Level Permissions can be added to any
* <code>Parse.Schema</code> to restrict access to only a subset of users
* of your application.</p>
*
* <p>
* For get/count/find/create/update/delete/addField using the following functions:
*
* Entity is type Parse.User or Parse.Role or string
* Role is type Parse.Role or Name of Parse.Role
*
* getGetRequiresAuthentication()
* setGetRequiresAuthentication(allowed: boolean)
* getGetPointerFields()
* setGetPointerFields(pointerFields: string[])
* getGetAccess(entity: Entity)
* setGetAccess(entity: Entity, allowed: boolean)
* getPublicGetAccess()
* setPublicGetAccess(allowed: boolean)
* getRoleGetAccess(role: Role)
* setRoleGetAccess(role: Role, allowed: boolean)
* getFindRequiresAuthentication()
* setFindRequiresAuthentication(allowed: boolean)
* getFindPointerFields()
* setFindPointerFields(pointerFields: string[])
* getFindAccess(entity: Entity)
* setFindAccess(entity: Entity, allowed: boolean)
* getPublicFindAccess()
* setPublicFindAccess(allowed: boolean)
* getRoleFindAccess(role: Role)
* setRoleFindAccess(role: Role, allowed: boolean)
* getCountRequiresAuthentication()
* setCountRequiresAuthentication(allowed: boolean)
* getCountPointerFields()
* setCountPointerFields(pointerFields: string[])
* getCountAccess(entity: Entity)
* setCountAccess(entity: Entity, allowed: boolean)
* getPublicCountAccess()
* setPublicCountAccess(allowed: boolean)
* getRoleCountAccess(role: Role)
* setRoleCountAccess(role: Role, allowed: boolean)
* getCreateRequiresAuthentication()
* setCreateRequiresAuthentication(allowed: boolean)
* getCreatePointerFields()
* setCreatePointerFields(pointerFields: string[])
* getCreateAccess(entity: Entity)
* setCreateAccess(entity: Entity, allowed: boolean)
* getPublicCreateAccess()
* setPublicCreateAccess(allowed: Boolean)
* getRoleCreateAccess(role: Role)
* setRoleCreateAccess(role: Role, allowed: boolean)
* getUpdateRequiresAuthentication()
* setUpdateRequiresAuthentication(allowed: boolean)
* getUpdatePointerFields()
* setUpdatePointerFields(pointerFields: string[])
* getUpdateAccess(entity: Entity)
* setUpdateAccess(entity: Entity, allowed: boolean)
* getPublicUpdateAccess()
* setPublicUpdateAccess(allowed: boolean)
* getRoleUpdateAccess(role: Role)
* setRoleUpdateAccess(role: Role, allowed: boolean)
* getDeleteRequiresAuthentication()
* setDeleteRequiresAuthentication(allowed: boolean)
* getDeletePointerFields()
* setDeletePointerFields(pointerFields: string[])
* getDeleteAccess(entity: Entity)
* setDeleteAccess(entity: Entity, allowed: boolean)
* getPublicDeleteAccess()
* setPublicDeleteAccess(allowed: boolean)
* getRoleDeleteAccess(role: Role)
* setRoleDeleteAccess(role: Role, allowed: boolean)
* getAddFieldRequiresAuthentication()
* setAddFieldRequiresAuthentication(allowed: boolean)
* getAddFieldPointerFields()
* setAddFieldPointerFields(pointerFields: string[])
* getAddFieldAccess(entity: Entity)
* setAddFieldAccess(entity: Entity, allowed: boolean)
* getPublicAddFieldAccess()
* setPublicAddFieldAccess(allowed: boolean)
* getRoleAddFieldAccess(role: Role)
* setRoleAddFieldAccess(role: Role, allowed: boolean)
* </p>
*
* @alias Parse.CLP
*/
declare class ParseCLP {
permissionsMap: PermissionsMap;
/**
* @param {(Parse.User | Parse.Role | object)} userId The user to initialize the CLP for
*/
constructor(userId: ParseUser | ParseRole | PermissionsMap);
/**
* Returns a JSON-encoded version of the CLP.
*
* @returns {object}
*/
toJSON(): PermissionsMap;
/**
* Returns whether this CLP is equal to another object
*
* @param other The other object to compare to
* @returns {boolean}
*/
equals(other: ParseCLP): boolean;
_getRoleName(role: ParseRole | string): string;
_parseEntity(entity: Entity): string;
_setAccess(permission: string, userId: Entity, allowed: boolean): void;
_getAccess(permission: string, userId: Entity, returnBoolean?: boolean): boolean | string[];
_setArrayAccess(permission: string, userId: Entity, fields: string[]): void;
_setGroupPointerPermission(operation: string, pointerFields: string[]): void;
_getGroupPointerPermissions(operation: 'readUserFields' | 'writeUserFields'): string[];
/**
* Sets user pointer fields to allow permission for get/count/find operations.
*
* @param {string[]} pointerFields User pointer fields
*/
setReadUserFields(pointerFields: string[]): void;
/**
* @returns {string[]} User pointer fields
*/
getReadUserFields(): string[];
/**
* Sets user pointer fields to allow permission for create/delete/update/addField operations
*
* @param {string[]} pointerFields User pointer fields
*/
setWriteUserFields(pointerFields: string[]): void;
/**
* @returns {string[]} User pointer fields
*/
getWriteUserFields(): string[];
/**
* Sets whether the given user is allowed to retrieve fields from this class.
*
* @param userId An instance of Parse.User or its objectId.
* @param {string[]} fields fields to be protected
*/
setProtectedFields(userId: Entity, fields: string[]): void;
/**
* Returns array of fields are accessable to this user.
*
* @param userId An instance of Parse.User or its objectId, or a Parse.Role.
* @returns {string[]}
*/
getProtectedFields(userId: Entity): string[];
/**
* Sets whether the given user is allowed to read from this class.
*
* @param userId An instance of Parse.User or its objectId.
* @param {boolean} allowed whether that user should have read access.
*/
setReadAccess(userId: Entity, allowed: boolean): void;
/**
* Get whether the given user id is *explicitly* allowed to read from this class.
* Even if this returns false, the user may still be able to access it if
* getPublicReadAccess returns true or a role that the user belongs to has
* write access.
*
* @param userId An instance of Parse.User or its objectId, or a Parse.Role.
* @returns {boolean}
*/
getReadAccess(userId: Entity): boolean;
/**
* Sets whether the given user id is allowed to write to this class.
*
* @param userId An instance of Parse.User or its objectId, or a Parse.Role..
* @param {boolean} allowed Whether that user should have write access.
*/
setWriteAccess(userId: Entity, allowed: boolean): void;
/**
* Gets whether the given user id is *explicitly* allowed to write to this class.
* Even if this returns false, the user may still be able to write it if
* getPublicWriteAccess returns true or a role that the user belongs to has
* write access.
*
* @param userId An instance of Parse.User or its objectId, or a Parse.Role.
* @returns {boolean}
*/
getWriteAccess(userId: Entity): boolean;
/**
* Sets whether the public is allowed to read from this class.
*
* @param {boolean} allowed
*/
setPublicReadAccess(allowed: boolean): void;
/**
* Gets whether the public is allowed to read from this class.
*
* @returns {boolean}
*/
getPublicReadAccess(): boolean;
/**
* Sets whether the public is allowed to write to this class.
*
* @param {boolean} allowed
*/
setPublicWriteAccess(allowed: boolean): void;
/**
* Gets whether the public is allowed to write to this class.
*
* @returns {boolean}
*/
getPublicWriteAccess(): boolean;
/**
* Sets whether the public is allowed to protect fields in this class.
*
* @param {string[]} fields
*/
setPublicProtectedFields(fields: string[]): void;
/**
* Gets whether the public is allowed to read fields from this class.
*
* @returns {string[]}
*/
getPublicProtectedFields(): string[];
/**
* Gets whether users belonging to the given role are allowed
* to read from this class. Even if this returns false, the role may
* still be able to write it if a parent role has read access.
*
* @param role The name of the role, or a Parse.Role object.
* @returns {boolean} true if the role has read access. false otherwise.
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
getRoleReadAccess(role: ParseRole | string): boolean;
/**
* Gets whether users belonging to the given role are allowed
* to write to this user. Even if this returns false, the role may
* still be able to write it if a parent role has write access.
*
* @param role The name of the role, or a Parse.Role object.
* @returns {boolean} true if the role has write access. false otherwise.
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
getRoleWriteAccess(role: ParseRole | string): boolean;
/**
* Sets whether users belonging to the given role are allowed
* to read from this class.
*
* @param role The name of the role, or a Parse.Role object.
* @param {boolean} allowed Whether the given role can read this object.
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
setRoleReadAccess(role: ParseRole | string, allowed: boolean): void;
/**
* Sets whether users belonging to the given role are allowed
* to write to this class.
*
* @param role The name of the role, or a Parse.Role object.
* @param {boolean} allowed Whether the given role can write this object.
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
setRoleWriteAccess(role: ParseRole | string, allowed: boolean): void;
/**
* Gets whether users belonging to the given role are allowed
* to count to this user. Even if this returns false, the role may
* still be able to count it if a parent role has count access.
*
* @param role The name of the role, or a Parse.Role object.
* @returns {string[]}
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
getRoleProtectedFields(role: ParseRole | string): string[];
/**
* Sets whether users belonging to the given role are allowed
* to set access field in this class.
*
* @param role The name of the role, or a Parse.Role object.
* @param {string[]} fields Fields to be protected by Role.
* @throws {TypeError} If role is neither a Parse.Role nor a String.
*/
setRoleProtectedFields(role: ParseRole | string, fields: string[]): void;
}
export default ParseCLP;