(config, auth, className, objectId, context)
| 166 | |
| 167 | // Returns a promise that doesn't resolve to any useful value. |
| 168 | function del(config, auth, className, objectId, context) { |
| 169 | if (typeof objectId !== 'string') { |
| 170 | throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad objectId'); |
| 171 | } |
| 172 | |
| 173 | if (className === '_User' && auth.isUnauthenticated()) { |
| 174 | throw new Parse.Error(Parse.Error.SESSION_MISSING, 'Insufficient auth to delete user'); |
| 175 | } |
| 176 | |
| 177 | enforceRoleSecurity('delete', className, auth, config); |
| 178 | |
| 179 | let inflatedObject; |
| 180 | let schemaController; |
| 181 | |
| 182 | return Promise.resolve() |
| 183 | .then(async () => { |
| 184 | const hasTriggers = checkTriggers(className, config, ['beforeDelete', 'afterDelete']); |
| 185 | const hasLiveQuery = checkLiveQuery(className, config); |
| 186 | if (hasTriggers || hasLiveQuery || className == '_Session') { |
| 187 | const query = await RestQuery({ |
| 188 | method: RestQuery.Method.get, |
| 189 | config, |
| 190 | auth, |
| 191 | className, |
| 192 | restWhere: { objectId }, |
| 193 | }); |
| 194 | return query.execute({ op: 'delete' }).then(response => { |
| 195 | if (response && response.results && response.results.length) { |
| 196 | const firstResult = response.results[0]; |
| 197 | firstResult.className = className; |
| 198 | if (className === '_Session' && !auth.isMaster && !auth.isMaintenance) { |
| 199 | if (!auth.user || firstResult.user.objectId !== auth.user.id) { |
| 200 | throw createSanitizedError(Parse.Error.INVALID_SESSION_TOKEN, 'Invalid session token', config); |
| 201 | } |
| 202 | } |
| 203 | var cacheAdapter = config.cacheController; |
| 204 | cacheAdapter.user.del(firstResult.sessionToken); |
| 205 | inflatedObject = Parse.Object.fromJSON(firstResult); |
| 206 | return triggers.maybeRunTrigger( |
| 207 | triggers.Types.beforeDelete, |
| 208 | auth, |
| 209 | inflatedObject, |
| 210 | null, |
| 211 | config, |
| 212 | context |
| 213 | ); |
| 214 | } |
| 215 | throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found for delete.'); |
| 216 | }); |
| 217 | } |
| 218 | return Promise.resolve({}); |
| 219 | }) |
| 220 | .then(() => { |
| 221 | if (!auth.isMaster && !auth.isMaintenance) { |
| 222 | return auth.getUserRoles(); |
| 223 | } else { |
| 224 | return; |
| 225 | } |
nothing calls this directly
no test coverage detected