@@ -27,6 +27,7 @@ function RestWrite(config, auth, className, query, data, originalData) {
27
27
this . auth = auth ;
28
28
this . className = className ;
29
29
this . storage = { } ;
30
+ this . runOptions = { } ;
30
31
31
32
if ( ! query && data . objectId ) {
32
33
throw new Parse . Error ( Parse . Error . INVALID_KEY_NAME , 'objectId ' +
@@ -66,6 +67,8 @@ function RestWrite(config, auth, className, query, data, originalData) {
66
67
// status and location are optional.
67
68
RestWrite . prototype . execute = function ( ) {
68
69
return Promise . resolve ( ) . then ( ( ) => {
70
+ return this . getUserAndRoleACL ( ) ;
71
+ } ) . then ( ( ) => {
69
72
return this . validateSchema ( ) ;
70
73
} ) . then ( ( ) => {
71
74
return this . handleInstallation ( ) ;
@@ -88,6 +91,25 @@ RestWrite.prototype.execute = function() {
88
91
} ) ;
89
92
} ;
90
93
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
+
91
113
// Validates this operation against the schema.
92
114
RestWrite . prototype . validateSchema = function ( ) {
93
115
return this . config . database . validateObject ( this . className , this . data ) ;
@@ -690,18 +712,10 @@ RestWrite.prototype.runDatabaseOperation = function() {
690
712
throw new Parse . Error ( Parse . Error . INVALID_ACL , 'Invalid ACL.' ) ;
691
713
}
692
714
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
-
701
715
if ( this . query ) {
702
716
// Run an update
703
717
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 ) => {
705
719
this . response = resp ;
706
720
this . response . updatedAt = this . updatedAt ;
707
721
} ) ;
@@ -714,7 +728,7 @@ RestWrite.prototype.runDatabaseOperation = function() {
714
728
this . data . ACL = ACL ;
715
729
}
716
730
// 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 )
718
732
. then ( ( ) => {
719
733
var resp = {
720
734
objectId : this . data . objectId ,
0 commit comments