@@ -27,6 +27,7 @@ function RestWrite(config, auth, className, query, data, originalData) {
2727 this . auth = auth ;
2828 this . className = className ;
2929 this . storage = { } ;
30+ this . runOptions = { } ;
3031
3132 if ( ! query && data . objectId ) {
3233 throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , 'objectId ' +
@@ -66,6 +67,8 @@ function RestWrite(config, auth, className, query, data, originalData) {
6667// status and location are optional.
6768RestWrite . prototype . execute = function ( ) {
6869 return Promise . resolve ( ) . then ( ( ) => {
70+ return this . getUserAndRoleACL ( ) ;
71+ } ) . then ( ( ) => {
6972 return this . validateSchema ( ) ;
7073 } ) . then ( ( ) => {
7174 return this . handleInstallation ( ) ;
@@ -88,6 +91,25 @@ RestWrite.prototype.execute = function() {
8891 } ) ;
8992} ;
9093
94+ // Uses the Auth object to get the list of roles, adds the user id
95+ RestWrite . prototype . getUserAndRoleACL = function ( ) {
96+ if ( this . auth . isMaster ) {
97+ return Promise . resolve ( ) ;
98+ }
99+
100+ this . runOptions . acl = [ '*' ] ;
101+
102+ if ( this . auth . user ) {
103+ return this . auth . getUserRoles ( ) . then ( ( roles ) => {
104+ roles . push ( this . auth . user . id ) ;
105+ this . runOptions . acl = this . runOptions . acl . concat ( roles ) ;
106+ return Promise . resolve ( ) ;
107+ } ) ;
108+ } else {
109+ return Promise . resolve ( ) ;
110+ }
111+ } ;
112+
91113// Validates this operation against the schema.
92114RestWrite . prototype . validateSchema = function ( ) {
93115 return this . config . database . validateObject ( this . className , this . data ) ;
@@ -690,18 +712,10 @@ RestWrite.prototype.runDatabaseOperation = function() {
690712 throw new Parse . Error ( Parse . Error . INVALID_ACL , 'Invalid ACL.' ) ;
691713 }
692714
693- var options = { } ;
694- if ( ! this . auth . isMaster ) {
695- options . acl = [ '*' ] ;
696- if ( this . auth . user ) {
697- options . acl . push ( this . auth . user . id ) ;
698- }
699- }
700-
701715 if ( this . query ) {
702716 // Run an update
703717 return this . config . database . update (
704- this . className , this . query , this . data , options ) . then ( ( resp ) => {
718+ this . className , this . query , this . data , this . runOptions ) . then ( ( resp ) => {
705719 this . response = resp ;
706720 this . response . updatedAt = this . updatedAt ;
707721 } ) ;
@@ -714,7 +728,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
714728 this . data . ACL = ACL ;
715729 }
716730 // Run a create
717- return this . config . database . create ( this . className , this . data , options )
731+ return this . config . database . create ( this . className , this . data , this . runOptions )
718732 . then ( ( ) => {
719733 var resp = {
720734 objectId : this . data . objectId ,
0 commit comments