SharedRest.js 4.7 KB

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. const classesWithMasterOnlyAccess = ['_JobStatus', '_PushStatus', '_Hooks', '_GlobalConfig', '_JobSchedule', '_Idempotency'];
  3. // Disallowing access to the _Role collection except by master key
  4. function enforceRoleSecurity(method, className, auth) {
  5. if (className === '_Installation' && !auth.isMaster && !auth.isMaintenance) {
  6. if (method === 'delete' || method === 'find') {
  7. const error = `Clients aren't allowed to perform the ${method} operation on the installation collection.`;
  8. throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, error);
  9. }
  10. }
  11. //all volatileClasses are masterKey only
  12. if (classesWithMasterOnlyAccess.indexOf(className) >= 0 && !auth.isMaster && !auth.isMaintenance) {
  13. const error = `Clients aren't allowed to perform the ${method} operation on the ${className} collection.`;
  14. throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, error);
  15. }
  16. // readOnly masterKey is not allowed
  17. if (auth.isReadOnly && (method === 'delete' || method === 'create' || method === 'update')) {
  18. const error = `read-only masterKey isn't allowed to perform the ${method} operation.`;
  19. throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, error);
  20. }
  21. }
  22. module.exports = {
  23. enforceRoleSecurity
  24. };
  25. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJjbGFzc2VzV2l0aE1hc3Rlck9ubHlBY2Nlc3MiLCJlbmZvcmNlUm9sZVNlY3VyaXR5IiwibWV0aG9kIiwiY2xhc3NOYW1lIiwiYXV0aCIsImlzTWFzdGVyIiwiaXNNYWludGVuYW5jZSIsImVycm9yIiwiUGFyc2UiLCJFcnJvciIsIk9QRVJBVElPTl9GT1JCSURERU4iLCJpbmRleE9mIiwiaXNSZWFkT25seSIsIm1vZHVsZSIsImV4cG9ydHMiXSwic291cmNlcyI6WyIuLi9zcmMvU2hhcmVkUmVzdC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBjbGFzc2VzV2l0aE1h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