parse 5.2.0-alpha.1 → 5.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parse.js +10519 -15246
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +10499 -15371
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +7 -11
- package/lib/browser/AnonymousUtils.js +17 -22
- package/lib/browser/Cloud.js +23 -41
- package/lib/browser/CoreManager.js +71 -79
- package/lib/browser/CryptoController.js +14 -9
- package/lib/browser/EventEmitter.js +9 -2
- package/lib/browser/EventuallyQueue.js +156 -357
- package/lib/browser/FacebookUtils.js +23 -28
- package/lib/browser/IndexedDBStorageController.js +18 -14
- package/lib/browser/InstallationController.js +55 -121
- package/lib/browser/LiveQueryClient.js +312 -485
- package/lib/browser/LiveQuerySubscription.js +25 -28
- package/lib/browser/LocalDatastore.js +258 -624
- package/lib/browser/LocalDatastoreController.default.js +42 -226
- package/lib/browser/LocalDatastoreController.js +11 -1
- package/lib/browser/LocalDatastoreController.react-native.js +66 -160
- package/lib/browser/LocalDatastoreUtils.js +4 -7
- package/lib/browser/ObjectStateMutations.js +54 -96
- package/lib/browser/OfflineQuery.js +106 -198
- package/lib/browser/Parse.js +44 -60
- package/lib/browser/ParseACL.js +242 -288
- package/lib/browser/ParseCLP.js +372 -572
- package/lib/browser/ParseConfig.js +115 -138
- package/lib/browser/ParseError.js +85 -182
- package/lib/browser/ParseFile.js +294 -438
- package/lib/browser/ParseGeoPoint.js +121 -146
- package/lib/browser/ParseHooks.js +23 -25
- package/lib/browser/ParseInstallation.js +225 -367
- package/lib/browser/ParseLiveQuery.js +74 -148
- package/lib/browser/ParseObject.js +2014 -2621
- package/lib/browser/ParseOp.js +343 -484
- package/lib/browser/ParsePolygon.js +101 -120
- package/lib/browser/ParseQuery.js +1708 -2052
- package/lib/browser/ParseRelation.js +99 -118
- package/lib/browser/ParseRole.js +88 -140
- package/lib/browser/ParseSchema.js +372 -434
- package/lib/browser/ParseSession.js +62 -110
- package/lib/browser/ParseUser.js +941 -1284
- package/lib/browser/Push.js +15 -38
- package/lib/browser/RESTController.js +85 -124
- package/lib/browser/SingleInstanceStateController.js +57 -86
- package/lib/browser/Socket.weapp.js +50 -33
- package/lib/browser/Storage.js +23 -28
- package/lib/browser/StorageController.browser.js +16 -13
- package/lib/browser/StorageController.default.js +15 -14
- package/lib/browser/StorageController.js +14 -1
- package/lib/browser/StorageController.react-native.js +31 -30
- package/lib/browser/StorageController.weapp.js +19 -13
- package/lib/browser/TaskQueue.js +31 -43
- package/lib/browser/UniqueInstanceStateController.js +65 -86
- package/lib/browser/WebSocketController.js +11 -4
- package/lib/browser/Xhr.weapp.js +90 -78
- package/lib/browser/arrayContainsObject.js +3 -3
- package/lib/browser/canBeSerialized.js +10 -11
- package/lib/browser/decode.js +11 -11
- package/lib/browser/encode.js +11 -11
- package/lib/browser/equals.js +9 -10
- package/lib/browser/escape.js +2 -2
- package/lib/browser/isRevocableSession.js +1 -1
- package/lib/browser/parseDate.js +10 -10
- package/lib/browser/promiseUtils.js +19 -19
- package/lib/browser/unique.js +4 -4
- package/lib/browser/unsavedChildren.js +20 -21
- package/lib/browser/uuid.js +2 -4
- package/lib/node/Analytics.js +5 -9
- package/lib/node/AnonymousUtils.js +10 -15
- package/lib/node/Cloud.js +11 -11
- package/lib/node/CoreManager.js +59 -67
- package/lib/node/CryptoController.js +8 -3
- package/lib/node/EventEmitter.js +7 -1
- package/lib/node/EventuallyQueue.js +20 -39
- package/lib/node/FacebookUtils.js +4 -8
- package/lib/node/IndexedDBStorageController.js +14 -10
- package/lib/node/InstallationController.js +12 -13
- package/lib/node/LiveQueryClient.js +23 -21
- package/lib/node/LiveQuerySubscription.js +6 -7
- package/lib/node/LocalDatastore.js +23 -23
- package/lib/node/LocalDatastoreController.default.js +11 -12
- package/lib/node/LocalDatastoreController.js +14 -1
- package/lib/node/LocalDatastoreController.react-native.js +25 -21
- package/lib/node/LocalDatastoreUtils.js +4 -7
- package/lib/node/ObjectStateMutations.js +12 -22
- package/lib/node/OfflineQuery.js +37 -23
- package/lib/node/Parse.js +36 -50
- package/lib/node/ParseACL.js +21 -30
- package/lib/node/ParseCLP.js +38 -40
- package/lib/node/ParseConfig.js +10 -17
- package/lib/node/ParseError.js +460 -461
- package/lib/node/ParseFile.js +27 -47
- package/lib/node/ParseGeoPoint.js +16 -17
- package/lib/node/ParseHooks.js +16 -18
- package/lib/node/ParseInstallation.js +10 -11
- package/lib/node/ParseLiveQuery.js +9 -14
- package/lib/node/ParseObject.js +142 -173
- package/lib/node/ParseOp.js +35 -47
- package/lib/node/ParsePolygon.js +14 -20
- package/lib/node/ParseQuery.js +100 -123
- package/lib/node/ParseRelation.js +10 -19
- package/lib/node/ParseRole.js +10 -11
- package/lib/node/ParseSchema.js +29 -42
- package/lib/node/ParseSession.js +10 -11
- package/lib/node/ParseUser.js +76 -87
- package/lib/node/Push.js +7 -12
- package/lib/node/RESTController.js +24 -36
- package/lib/node/SingleInstanceStateController.js +41 -69
- package/lib/node/Socket.weapp.js +23 -2
- package/lib/node/Storage.js +14 -19
- package/lib/node/StorageController.browser.js +10 -8
- package/lib/node/StorageController.default.js +9 -9
- package/lib/node/StorageController.js +16 -1
- package/lib/node/StorageController.react-native.js +20 -20
- package/lib/node/StorageController.weapp.js +14 -8
- package/lib/node/TaskQueue.js +2 -3
- package/lib/node/UniqueInstanceStateController.js +43 -63
- package/lib/node/WebSocketController.js +15 -2
- package/lib/node/Xhr.weapp.js +11 -2
- package/lib/node/arrayContainsObject.js +4 -4
- package/lib/node/canBeSerialized.js +5 -5
- package/lib/node/decode.js +4 -4
- package/lib/node/encode.js +5 -5
- package/lib/node/equals.js +4 -4
- package/lib/node/escape.js +1 -1
- package/lib/node/isRevocableSession.js +1 -1
- package/lib/node/parseDate.js +1 -1
- package/lib/node/promiseUtils.js +7 -7
- package/lib/node/unique.js +5 -5
- package/lib/node/unsavedChildren.js +5 -5
- package/lib/node/uuid.js +2 -4
- package/lib/react-native/Analytics.js +2 -2
- package/lib/react-native/AnonymousUtils.js +3 -4
- package/lib/react-native/CoreManager.js +2 -3
- package/lib/react-native/CryptoController.js +6 -1
- package/lib/react-native/EventEmitter.js +6 -1
- package/lib/react-native/EventuallyQueue.js +1 -2
- package/lib/react-native/FacebookUtils.js +1 -2
- package/lib/react-native/IndexedDBStorageController.js +11 -5
- package/lib/react-native/InstallationController.js +1 -2
- package/lib/react-native/LiveQueryClient.js +8 -7
- package/lib/react-native/LiveQuerySubscription.js +2 -4
- package/lib/react-native/LocalDatastore.js +3 -3
- package/lib/react-native/LocalDatastoreController.default.js +1 -2
- package/lib/react-native/LocalDatastoreController.js +11 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
- package/lib/react-native/LocalDatastoreUtils.js +3 -6
- package/lib/react-native/OfflineQuery.js +25 -20
- package/lib/react-native/Parse.js +24 -38
- package/lib/react-native/ParseACL.js +4 -6
- package/lib/react-native/ParseCLP.js +2 -4
- package/lib/react-native/ParseConfig.js +4 -6
- package/lib/react-native/ParseError.js +13 -31
- package/lib/react-native/ParseFile.js +3 -4
- package/lib/react-native/ParseGeoPoint.js +2 -4
- package/lib/react-native/ParseInstallation.js +13 -30
- package/lib/react-native/ParseLiveQuery.js +2 -4
- package/lib/react-native/ParseObject.js +77 -87
- package/lib/react-native/ParseOp.js +41 -79
- package/lib/react-native/ParsePolygon.js +2 -4
- package/lib/react-native/ParseQuery.js +43 -45
- package/lib/react-native/ParseRelation.js +2 -4
- package/lib/react-native/ParseRole.js +13 -30
- package/lib/react-native/ParseSchema.js +3 -5
- package/lib/react-native/ParseSession.js +12 -29
- package/lib/react-native/ParseUser.js +24 -49
- package/lib/react-native/RESTController.js +10 -4
- package/lib/react-native/SingleInstanceStateController.js +23 -37
- package/lib/react-native/Socket.weapp.js +9 -4
- package/lib/react-native/Storage.js +1 -2
- package/lib/react-native/StorageController.browser.js +6 -1
- package/lib/react-native/StorageController.default.js +6 -1
- package/lib/react-native/StorageController.js +13 -1
- package/lib/react-native/StorageController.react-native.js +11 -6
- package/lib/react-native/StorageController.weapp.js +6 -1
- package/lib/react-native/TaskQueue.js +2 -4
- package/lib/react-native/UniqueInstanceStateController.js +23 -37
- package/lib/react-native/WebSocketController.js +9 -1
- package/lib/react-native/Xhr.weapp.js +9 -4
- package/lib/react-native/unsavedChildren.js +3 -3
- package/lib/react-native/uuid.js +1 -2
- package/lib/weapp/Analytics.js +7 -11
- package/lib/weapp/AnonymousUtils.js +17 -22
- package/lib/weapp/Cloud.js +23 -41
- package/lib/weapp/CoreManager.js +71 -79
- package/lib/weapp/CryptoController.js +14 -9
- package/lib/weapp/EventEmitter.js +9 -2
- package/lib/weapp/EventuallyQueue.js +156 -357
- package/lib/weapp/FacebookUtils.js +23 -28
- package/lib/weapp/IndexedDBStorageController.js +18 -14
- package/lib/weapp/InstallationController.js +55 -121
- package/lib/weapp/LiveQueryClient.js +312 -485
- package/lib/weapp/LiveQuerySubscription.js +25 -28
- package/lib/weapp/LocalDatastore.js +258 -624
- package/lib/weapp/LocalDatastoreController.default.js +42 -226
- package/lib/weapp/LocalDatastoreController.js +11 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
- package/lib/weapp/LocalDatastoreUtils.js +4 -7
- package/lib/weapp/ObjectStateMutations.js +54 -96
- package/lib/weapp/OfflineQuery.js +106 -198
- package/lib/weapp/Parse.js +44 -59
- package/lib/weapp/ParseACL.js +242 -288
- package/lib/weapp/ParseCLP.js +372 -572
- package/lib/weapp/ParseConfig.js +115 -138
- package/lib/weapp/ParseError.js +85 -182
- package/lib/weapp/ParseFile.js +295 -440
- package/lib/weapp/ParseGeoPoint.js +121 -146
- package/lib/weapp/ParseHooks.js +23 -25
- package/lib/weapp/ParseInstallation.js +225 -367
- package/lib/weapp/ParseLiveQuery.js +74 -148
- package/lib/weapp/ParseObject.js +2014 -2621
- package/lib/weapp/ParseOp.js +343 -484
- package/lib/weapp/ParsePolygon.js +101 -120
- package/lib/weapp/ParseQuery.js +1708 -2052
- package/lib/weapp/ParseRelation.js +99 -118
- package/lib/weapp/ParseRole.js +88 -140
- package/lib/weapp/ParseSchema.js +372 -434
- package/lib/weapp/ParseSession.js +62 -110
- package/lib/weapp/ParseUser.js +941 -1284
- package/lib/weapp/Push.js +15 -38
- package/lib/weapp/RESTController.js +86 -125
- package/lib/weapp/SingleInstanceStateController.js +57 -86
- package/lib/weapp/Socket.weapp.js +50 -33
- package/lib/weapp/Storage.js +23 -28
- package/lib/weapp/StorageController.browser.js +16 -13
- package/lib/weapp/StorageController.default.js +15 -14
- package/lib/weapp/StorageController.js +14 -1
- package/lib/weapp/StorageController.react-native.js +31 -30
- package/lib/weapp/StorageController.weapp.js +19 -13
- package/lib/weapp/TaskQueue.js +31 -43
- package/lib/weapp/UniqueInstanceStateController.js +65 -86
- package/lib/weapp/WebSocketController.js +11 -4
- package/lib/weapp/Xhr.weapp.js +90 -78
- package/lib/weapp/arrayContainsObject.js +3 -3
- package/lib/weapp/canBeSerialized.js +10 -11
- package/lib/weapp/decode.js +11 -11
- package/lib/weapp/encode.js +11 -11
- package/lib/weapp/equals.js +9 -10
- package/lib/weapp/escape.js +2 -2
- package/lib/weapp/isRevocableSession.js +1 -1
- package/lib/weapp/parseDate.js +10 -10
- package/lib/weapp/promiseUtils.js +19 -19
- package/lib/weapp/unique.js +4 -4
- package/lib/weapp/unsavedChildren.js +20 -21
- package/lib/weapp/uuid.js +6 -8
- package/package.json +24 -30
package/lib/weapp/ParseACL.js
CHANGED
|
@@ -7,19 +7,9 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
|
|
11
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
13
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
14
11
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
15
|
-
|
|
16
|
-
* @flow
|
|
17
|
-
*/
|
|
18
|
-
/*:: import type ParseRole from './ParseRole';*/
|
|
19
|
-
/*:: import type ParseUser from './ParseUser';*/
|
|
20
|
-
/*:: type PermissionsMap = { [permission: string]: boolean };*/
|
|
21
|
-
/*:: type ByIdMap = { [userId: string]: PermissionsMap };*/
|
|
22
|
-
var PUBLIC_KEY = '*';
|
|
12
|
+
const PUBLIC_KEY = '*';
|
|
23
13
|
|
|
24
14
|
/**
|
|
25
15
|
* Creates a new ACL.
|
|
@@ -35,32 +25,31 @@ var PUBLIC_KEY = '*';
|
|
|
35
25
|
*
|
|
36
26
|
* @alias Parse.ACL
|
|
37
27
|
*/
|
|
38
|
-
|
|
28
|
+
class ParseACL {
|
|
39
29
|
/**
|
|
40
30
|
* @param {(Parse.User | object)} arg1 The user to initialize the ACL for
|
|
41
31
|
*/
|
|
42
|
-
|
|
43
|
-
(0, _classCallCheck2.default)(this, ParseACL);
|
|
32
|
+
constructor(arg1) {
|
|
44
33
|
(0, _defineProperty2.default)(this, "permissionsById", void 0);
|
|
45
34
|
this.permissionsById = {};
|
|
46
|
-
if (arg1 &&
|
|
47
|
-
|
|
48
|
-
if (arg1 instanceof
|
|
35
|
+
if (arg1 && typeof arg1 === 'object') {
|
|
36
|
+
const ParseUser = _CoreManager.default.getParseUser();
|
|
37
|
+
if (arg1 instanceof ParseUser) {
|
|
49
38
|
this.setReadAccess(arg1, true);
|
|
50
39
|
this.setWriteAccess(arg1, true);
|
|
51
40
|
} else {
|
|
52
|
-
for (
|
|
53
|
-
|
|
54
|
-
this.permissionsById[
|
|
55
|
-
for (
|
|
56
|
-
|
|
57
|
-
if (
|
|
41
|
+
for (const userId in arg1) {
|
|
42
|
+
const accessList = arg1[userId];
|
|
43
|
+
this.permissionsById[userId] = {};
|
|
44
|
+
for (const permission in accessList) {
|
|
45
|
+
const allowed = accessList[permission];
|
|
46
|
+
if (permission !== 'read' && permission !== 'write') {
|
|
58
47
|
throw new TypeError('Tried to create an ACL with an invalid permission type.');
|
|
59
48
|
}
|
|
60
49
|
if (typeof allowed !== 'boolean') {
|
|
61
50
|
throw new TypeError('Tried to create an ACL with an invalid permission value.');
|
|
62
51
|
}
|
|
63
|
-
this.permissionsById[
|
|
52
|
+
this.permissionsById[userId][permission] = allowed;
|
|
64
53
|
}
|
|
65
54
|
}
|
|
66
55
|
}
|
|
@@ -74,298 +63,263 @@ var ParseACL = /*#__PURE__*/function () {
|
|
|
74
63
|
*
|
|
75
64
|
* @returns {object}
|
|
76
65
|
*/
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
for (var p in this.permissionsById) {
|
|
82
|
-
permissions[p] = this.permissionsById[p];
|
|
83
|
-
}
|
|
84
|
-
return permissions;
|
|
66
|
+
toJSON() {
|
|
67
|
+
const permissions = {};
|
|
68
|
+
for (const p in this.permissionsById) {
|
|
69
|
+
permissions[p] = this.permissionsById[p];
|
|
85
70
|
}
|
|
71
|
+
return permissions;
|
|
72
|
+
}
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Returns whether this ACL is equal to another object
|
|
76
|
+
*
|
|
77
|
+
* @param {ParseACL} other The other object's ACL to compare to
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
equals(other) {
|
|
81
|
+
if (!(other instanceof ParseACL)) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const users = (0, _keys.default)(this.permissionsById);
|
|
85
|
+
const otherUsers = (0, _keys.default)(other.permissionsById);
|
|
86
|
+
if (users.length !== otherUsers.length) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
for (const u in this.permissionsById) {
|
|
90
|
+
if (!other.permissionsById[u]) {
|
|
97
91
|
return false;
|
|
98
92
|
}
|
|
99
|
-
|
|
100
|
-
var otherUsers = (0, _keys.default)(other.permissionsById);
|
|
101
|
-
if (users.length !== otherUsers.length) {
|
|
93
|
+
if (this.permissionsById[u].read !== other.permissionsById[u].read) {
|
|
102
94
|
return false;
|
|
103
95
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
if (this.permissionsById[u].read !== other.permissionsById[u].read) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (this.permissionsById[u].write !== other.permissionsById[u].write) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
96
|
+
if (this.permissionsById[u].write !== other.permissionsById[u].write) {
|
|
97
|
+
return false;
|
|
114
98
|
}
|
|
115
|
-
return true;
|
|
116
99
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
userId = 'role:' + name;
|
|
130
|
-
}
|
|
131
|
-
if (typeof userId !== 'string') {
|
|
132
|
-
throw new TypeError('userId must be a string.');
|
|
133
|
-
}
|
|
134
|
-
if (typeof allowed !== 'boolean') {
|
|
135
|
-
throw new TypeError('allowed must be either true or false.');
|
|
136
|
-
}
|
|
137
|
-
var permissions = this.permissionsById[userId];
|
|
138
|
-
if (!permissions) {
|
|
139
|
-
if (!allowed) {
|
|
140
|
-
// The user already doesn't have this permission, so no action is needed
|
|
141
|
-
return;
|
|
142
|
-
} else {
|
|
143
|
-
permissions = {};
|
|
144
|
-
this.permissionsById[userId] = permissions;
|
|
145
|
-
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
_setAccess(accessType, userId, allowed) {
|
|
103
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
104
|
+
const ParseUser = _CoreManager.default.getParseUser();
|
|
105
|
+
if (userId instanceof ParseUser) {
|
|
106
|
+
userId = userId.id;
|
|
107
|
+
} else if (userId instanceof ParseRole) {
|
|
108
|
+
const name = userId.getName();
|
|
109
|
+
if (!name) {
|
|
110
|
+
throw new TypeError('Role must have a name');
|
|
146
111
|
}
|
|
147
|
-
|
|
148
|
-
|
|
112
|
+
userId = 'role:' + name;
|
|
113
|
+
}
|
|
114
|
+
if (typeof userId !== 'string') {
|
|
115
|
+
throw new TypeError('userId must be a string.');
|
|
116
|
+
}
|
|
117
|
+
if (typeof allowed !== 'boolean') {
|
|
118
|
+
throw new TypeError('allowed must be either true or false.');
|
|
119
|
+
}
|
|
120
|
+
let permissions = this.permissionsById[userId];
|
|
121
|
+
if (!permissions) {
|
|
122
|
+
if (!allowed) {
|
|
123
|
+
// The user already doesn't have this permission, so no action is needed
|
|
124
|
+
return;
|
|
149
125
|
} else {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
delete this.permissionsById[userId];
|
|
153
|
-
}
|
|
126
|
+
permissions = {};
|
|
127
|
+
this.permissionsById[userId] = permissions;
|
|
154
128
|
}
|
|
155
129
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
userId = userId.id;
|
|
163
|
-
if (!userId) {
|
|
164
|
-
throw new Error('Cannot get access for a ParseUser without an ID');
|
|
165
|
-
}
|
|
166
|
-
} else if (userId instanceof ParseRole) {
|
|
167
|
-
var name = userId.getName();
|
|
168
|
-
if (!name) {
|
|
169
|
-
throw new TypeError('Role must have a name');
|
|
170
|
-
}
|
|
171
|
-
userId = 'role:' + name;
|
|
130
|
+
if (allowed) {
|
|
131
|
+
this.permissionsById[userId][accessType] = true;
|
|
132
|
+
} else {
|
|
133
|
+
delete permissions[accessType];
|
|
134
|
+
if ((0, _keys.default)(permissions).length === 0) {
|
|
135
|
+
delete this.permissionsById[userId];
|
|
172
136
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
_getAccess(accessType, userId) {
|
|
140
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
141
|
+
const ParseUser = _CoreManager.default.getParseUser();
|
|
142
|
+
if (userId instanceof ParseUser) {
|
|
143
|
+
userId = userId.id;
|
|
144
|
+
if (!userId) {
|
|
145
|
+
throw new Error('Cannot get access for a ParseUser without an ID');
|
|
146
|
+
}
|
|
147
|
+
} else if (userId instanceof ParseRole) {
|
|
148
|
+
const name = userId.getName();
|
|
149
|
+
if (!name) {
|
|
150
|
+
throw new TypeError('Role must have a name');
|
|
176
151
|
}
|
|
177
|
-
|
|
152
|
+
userId = 'role:' + name;
|
|
178
153
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
*
|
|
183
|
-
* @param userId An instance of Parse.User or its objectId.
|
|
184
|
-
* @param {boolean} allowed Whether that user should have read access.
|
|
185
|
-
*/
|
|
186
|
-
}, {
|
|
187
|
-
key: "setReadAccess",
|
|
188
|
-
value: function (userId /*: ParseUser | ParseRole | string*/, allowed /*: boolean*/) {
|
|
189
|
-
this._setAccess('read', userId, allowed);
|
|
154
|
+
const permissions = this.permissionsById[userId];
|
|
155
|
+
if (!permissions) {
|
|
156
|
+
return false;
|
|
190
157
|
}
|
|
158
|
+
return !!permissions[accessType];
|
|
159
|
+
}
|
|
191
160
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}, {
|
|
202
|
-
key: "getReadAccess",
|
|
203
|
-
value: function (userId /*: ParseUser | ParseRole | string*/) /*: boolean*/{
|
|
204
|
-
return this._getAccess('read', userId);
|
|
205
|
-
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets whether the given user is allowed to read this object.
|
|
163
|
+
*
|
|
164
|
+
* @param userId An instance of Parse.User or its objectId.
|
|
165
|
+
* @param {boolean} allowed Whether that user should have read access.
|
|
166
|
+
*/
|
|
167
|
+
setReadAccess(userId, allowed) {
|
|
168
|
+
this._setAccess('read', userId, allowed);
|
|
169
|
+
}
|
|
206
170
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Get whether the given user id is *explicitly* allowed to read this object.
|
|
173
|
+
* Even if this returns false, the user may still be able to access it if
|
|
174
|
+
* getPublicReadAccess returns true or a role that the user belongs to has
|
|
175
|
+
* write access.
|
|
176
|
+
*
|
|
177
|
+
* @param userId An instance of Parse.User or its objectId, or a Parse.Role.
|
|
178
|
+
* @returns {boolean}
|
|
179
|
+
*/
|
|
180
|
+
getReadAccess(userId) {
|
|
181
|
+
return this._getAccess('read', userId);
|
|
182
|
+
}
|
|
218
183
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}, {
|
|
229
|
-
key: "getWriteAccess",
|
|
230
|
-
value: function (userId /*: ParseUser | ParseRole | string*/) /*: boolean*/{
|
|
231
|
-
return this._getAccess('write', userId);
|
|
232
|
-
}
|
|
184
|
+
/**
|
|
185
|
+
* Sets whether the given user id is allowed to write this object.
|
|
186
|
+
*
|
|
187
|
+
* @param userId An instance of Parse.User or its objectId, or a Parse.Role..
|
|
188
|
+
* @param {boolean} allowed Whether that user should have write access.
|
|
189
|
+
*/
|
|
190
|
+
setWriteAccess(userId, allowed) {
|
|
191
|
+
this._setAccess('write', userId, allowed);
|
|
192
|
+
}
|
|
233
193
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Gets whether the given user id is *explicitly* allowed to write this object.
|
|
196
|
+
* Even if this returns false, the user may still be able to write it if
|
|
197
|
+
* getPublicWriteAccess returns true or a role that the user belongs to has
|
|
198
|
+
* write access.
|
|
199
|
+
*
|
|
200
|
+
* @param userId An instance of Parse.User or its objectId, or a Parse.Role.
|
|
201
|
+
* @returns {boolean}
|
|
202
|
+
*/
|
|
203
|
+
getWriteAccess(userId) {
|
|
204
|
+
return this._getAccess('write', userId);
|
|
205
|
+
}
|
|
244
206
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return this.getReadAccess(PUBLIC_KEY);
|
|
254
|
-
}
|
|
207
|
+
/**
|
|
208
|
+
* Sets whether the public is allowed to read this object.
|
|
209
|
+
*
|
|
210
|
+
* @param {boolean} allowed
|
|
211
|
+
*/
|
|
212
|
+
setPublicReadAccess(allowed) {
|
|
213
|
+
this.setReadAccess(PUBLIC_KEY, allowed);
|
|
214
|
+
}
|
|
255
215
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
this.setWriteAccess(PUBLIC_KEY, allowed);
|
|
265
|
-
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets whether the public is allowed to read this object.
|
|
218
|
+
*
|
|
219
|
+
* @returns {boolean}
|
|
220
|
+
*/
|
|
221
|
+
getPublicReadAccess() {
|
|
222
|
+
return this.getReadAccess(PUBLIC_KEY);
|
|
223
|
+
}
|
|
266
224
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return this.getWriteAccess(PUBLIC_KEY);
|
|
276
|
-
}
|
|
225
|
+
/**
|
|
226
|
+
* Sets whether the public is allowed to write this object.
|
|
227
|
+
*
|
|
228
|
+
* @param {boolean} allowed
|
|
229
|
+
*/
|
|
230
|
+
setPublicWriteAccess(allowed) {
|
|
231
|
+
this.setWriteAccess(PUBLIC_KEY, allowed);
|
|
232
|
+
}
|
|
277
233
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Gets whether the public is allowed to write this object.
|
|
236
|
+
*
|
|
237
|
+
* @returns {boolean}
|
|
238
|
+
*/
|
|
239
|
+
getPublicWriteAccess() {
|
|
240
|
+
return this.getWriteAccess(PUBLIC_KEY);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Gets whether users belonging to the given role are allowed
|
|
245
|
+
* to read this object. Even if this returns false, the role may
|
|
246
|
+
* still be able to write it if a parent role has read access.
|
|
247
|
+
*
|
|
248
|
+
* @param role The name of the role, or a Parse.Role object.
|
|
249
|
+
* @returns {boolean} true if the role has read access. false otherwise.
|
|
250
|
+
* @throws {TypeError} If role is neither a Parse.Role nor a String.
|
|
251
|
+
*/
|
|
252
|
+
getRoleReadAccess(role) {
|
|
253
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
254
|
+
if (role instanceof ParseRole) {
|
|
255
|
+
// Normalize to the String name
|
|
256
|
+
role = role.getName();
|
|
257
|
+
}
|
|
258
|
+
if (typeof role !== 'string') {
|
|
259
|
+
throw new TypeError('role must be a ParseRole or a String');
|
|
299
260
|
}
|
|
261
|
+
return this.getReadAccess('role:' + role);
|
|
262
|
+
}
|
|
300
263
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (typeof role !== 'string') {
|
|
319
|
-
throw new TypeError('role must be a ParseRole or a String');
|
|
320
|
-
}
|
|
321
|
-
return this.getWriteAccess('role:' + role);
|
|
264
|
+
/**
|
|
265
|
+
* Gets whether users belonging to the given role are allowed
|
|
266
|
+
* to write this object. Even if this returns false, the role may
|
|
267
|
+
* still be able to write it if a parent role has write access.
|
|
268
|
+
*
|
|
269
|
+
* @param role The name of the role, or a Parse.Role object.
|
|
270
|
+
* @returns {boolean} true if the role has write access. false otherwise.
|
|
271
|
+
* @throws {TypeError} If role is neither a Parse.Role nor a String.
|
|
272
|
+
*/
|
|
273
|
+
getRoleWriteAccess(role) {
|
|
274
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
275
|
+
if (role instanceof ParseRole) {
|
|
276
|
+
// Normalize to the String name
|
|
277
|
+
role = role.getName();
|
|
278
|
+
}
|
|
279
|
+
if (typeof role !== 'string') {
|
|
280
|
+
throw new TypeError('role must be a ParseRole or a String');
|
|
322
281
|
}
|
|
282
|
+
return this.getWriteAccess('role:' + role);
|
|
283
|
+
}
|
|
323
284
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
// Normalize to the String name
|
|
338
|
-
role = role.getName();
|
|
339
|
-
}
|
|
340
|
-
if (typeof role !== 'string') {
|
|
341
|
-
throw new TypeError('role must be a ParseRole or a String');
|
|
342
|
-
}
|
|
343
|
-
this.setReadAccess('role:' + role, allowed);
|
|
285
|
+
/**
|
|
286
|
+
* Sets whether users belonging to the given role are allowed
|
|
287
|
+
* to read this object.
|
|
288
|
+
*
|
|
289
|
+
* @param role The name of the role, or a Parse.Role object.
|
|
290
|
+
* @param {boolean} allowed Whether the given role can read this object.
|
|
291
|
+
* @throws {TypeError} If role is neither a Parse.Role nor a String.
|
|
292
|
+
*/
|
|
293
|
+
setRoleReadAccess(role, allowed) {
|
|
294
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
295
|
+
if (role instanceof ParseRole) {
|
|
296
|
+
// Normalize to the String name
|
|
297
|
+
role = role.getName();
|
|
344
298
|
}
|
|
299
|
+
if (typeof role !== 'string') {
|
|
300
|
+
throw new TypeError('role must be a ParseRole or a String');
|
|
301
|
+
}
|
|
302
|
+
this.setReadAccess('role:' + role, allowed);
|
|
303
|
+
}
|
|
345
304
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (typeof role !== 'string') {
|
|
363
|
-
throw new TypeError('role must be a ParseRole or a String');
|
|
364
|
-
}
|
|
365
|
-
this.setWriteAccess('role:' + role, allowed);
|
|
305
|
+
/**
|
|
306
|
+
* Sets whether users belonging to the given role are allowed
|
|
307
|
+
* to write this object.
|
|
308
|
+
*
|
|
309
|
+
* @param role The name of the role, or a Parse.Role object.
|
|
310
|
+
* @param {boolean} allowed Whether the given role can write this object.
|
|
311
|
+
* @throws {TypeError} If role is neither a Parse.Role nor a String.
|
|
312
|
+
*/
|
|
313
|
+
setRoleWriteAccess(role, allowed) {
|
|
314
|
+
const ParseRole = _CoreManager.default.getParseRole();
|
|
315
|
+
if (role instanceof ParseRole) {
|
|
316
|
+
// Normalize to the String name
|
|
317
|
+
role = role.getName();
|
|
318
|
+
}
|
|
319
|
+
if (typeof role !== 'string') {
|
|
320
|
+
throw new TypeError('role must be a ParseRole or a String');
|
|
366
321
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
var _default = ParseACL;
|
|
371
|
-
exports.default = _default;
|
|
322
|
+
this.setWriteAccess('role:' + role, allowed);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
var _default = exports.default = ParseACL;
|