Skip to content

Commit da38328

Browse files
authored
fix(Role): use noDefaultACL flag while creating Role interally (#461)
1 parent d09e161 commit da38328

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

src/av.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ AV._decode = function(value, key) {
291291
var className;
292292
if (value.__type === "Pointer") {
293293
className = value.className;
294-
var pointer = AV.Object._create(className);
294+
var pointer = AV.Object._create(className, undefined, undefined, /* noDefaultACL*/ true);
295295
if(Object.keys(value).length > 3) {
296296
const v = _.clone(value);
297297
delete v.__type;
@@ -308,7 +308,7 @@ AV._decode = function(value, key) {
308308
const v = _.clone(value);
309309
delete v.__type;
310310
delete v.className;
311-
var object = AV.Object._create(className);
311+
var object = AV.Object._create(className, undefined, undefined, /* noDefaultACL*/ true);
312312
object._finishFetch(v, true);
313313
return object;
314314
}

src/object.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ module.exports = function(AV) {
12391239
* @return {AV.Object} A new subclass instance of AV.Object.
12401240
*/
12411241
AV.Object.createWithoutData = function(className, id, hasData){
1242-
var result = new AV.Object(className);
1242+
var result = AV.Object._create(className, undefined, undefined, /* noDefaultACL*/ true);
12431243
result.id = id;
12441244
result._hasData = hasData;
12451245
return result;
@@ -1293,9 +1293,9 @@ module.exports = function(AV) {
12931293
* Creates an instance of a subclass of AV.Object for the given classname.
12941294
* @private
12951295
*/
1296-
AV.Object._create = function(className, attributes, options) {
1296+
AV.Object._create = function(className, attributes, options, noDefaultACL) {
12971297
var ObjectClass = AV.Object._getSubclass(className);
1298-
return new ObjectClass(attributes, options);
1298+
return new ObjectClass(attributes, options, noDefaultACL);
12991299
};
13001300

13011301
// Set up a map of className to class so that we can create new instances of

src/role.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ module.exports = function(AV) {
2121
* @param {AV.ACL} [acl] The ACL for this role. if absent, the default ACL
2222
* `{'*': { read: true }}` will be used.
2323
*/
24-
constructor: function(name, acl) {
24+
constructor: function(name, acl, noDefaultACL) {
2525
if (_.isString(name)) {
2626
AV.Object.prototype.constructor.call(this, null, null);
2727
this.setName(name);
2828
} else {
2929
AV.Object.prototype.constructor.call(this, name, acl);
3030
}
3131
if (acl === undefined) {
32-
var defaultAcl = new AV.ACL();
33-
defaultAcl.setPublicReadAccess(true);
34-
if(!this.getACL()) {
35-
this.setACL(defaultAcl);
32+
if (!noDefaultACL) {
33+
if(!this.getACL()) {
34+
console.warn('DEPRECATED: To create a Role without ACL(a default ACL will be used) is deprecated. Please specify an ACL.');
35+
var defaultAcl = new AV.ACL();
36+
defaultAcl.setPublicReadAccess(true);
37+
this.setACL(defaultAcl);
38+
}
3639
}
3740
} else if (!(acl instanceof AV.ACL)) {
3841
throw new TypeError('acl must be an instance of AV.ACL');

test/role.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ describe("Role", function() {
1717
}
1818
});
1919
});
20+
it('no default ACL', () => {
21+
expect(AV.Object.createWithoutData('_Role').getACL()).to.eql(undefined);
22+
expect(AV._decode({
23+
__type: 'Pointer',
24+
className: '_Role',
25+
name: 'Admin',
26+
objectId: '577e50c3165abd005549f210',
27+
}).getACL()).to.eql(undefined);
28+
expect((new AV.Object('_Role')).getACL()).not.to.eql(undefined);
29+
});
2030
it("type check", function() {
2131
expect(function() {
2232
new AV.Role('foo', {});

0 commit comments

Comments
 (0)