File tree Expand file tree Collapse file tree 4 files changed +12
-20
lines changed
Expand file tree Collapse file tree 4 files changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,7 @@ module.exports = function(AV) {
1818 * cloud.
1919 * @class AV.Role
2020 * @param {String } name The name of the Role to create.
21- * @param {AV.ACL } [acl] The ACL for this role. if absent, the default ACL
22- * `{'*': { read: true }}` will be used.
21+ * @param {AV.ACL } acl The ACL for this role.
2322 */
2423 constructor : function ( name , acl ) {
2524 if ( _ . isString ( name ) ) {
@@ -28,16 +27,12 @@ module.exports = function(AV) {
2827 } else {
2928 AV . Object . prototype . constructor . call ( this , name , acl ) ;
3029 }
31- if ( acl === undefined ) {
32- var defaultAcl = new AV . ACL ( ) ;
33- defaultAcl . setPublicReadAccess ( true ) ;
34- if ( ! this . getACL ( ) ) {
35- this . setACL ( defaultAcl ) ;
30+ if ( acl ) {
31+ if ( ! ( acl instanceof AV . ACL ) ) {
32+ throw new TypeError ( 'acl must be an instance of AV.ACL' ) ;
33+ } else {
34+ this . setACL ( acl ) ;
3635 }
37- } else if ( ! ( acl instanceof AV . ACL ) ) {
38- throw new TypeError ( 'acl must be an instance of AV.ACL' ) ;
39- } else {
40- this . setACL ( acl ) ;
4136 }
4237 } ,
4338
Original file line number Diff line number Diff line change @@ -478,7 +478,7 @@ declare namespace AV {
478478 */
479479 export class Role extends Object {
480480
481- constructor ( name : string , acl ? : ACL ) ;
481+ constructor ( name : string , acl : ACL ) ;
482482
483483 getRoles ( ) : Relation ;
484484 getUsers ( ) : Relation ;
Original file line number Diff line number Diff line change @@ -8,14 +8,9 @@ describe("Role", function() {
88 expect ( role . getName ( ) ) . to . be ( 'foo' ) ;
99 expect ( role . getACL ( ) ) . to . be ( acl ) ;
1010 } ) ;
11- it ( "acl is optional " , function ( ) {
11+ it ( "acl is required " , function ( ) {
1212 var role = new AV . Role ( 'foo' ) ;
13- expect ( role . getName ( ) ) . to . be ( 'foo' ) ;
14- expect ( role . getACL ( ) . toJSON ( ) ) . to . eql ( {
15- '*' : {
16- read : true
17- }
18- } ) ;
13+ return role . save ( ) . should . be . rejected ( ) ;
1914 } ) ;
2015 it ( "type check" , function ( ) {
2116 expect ( function ( ) {
Original file line number Diff line number Diff line change @@ -135,7 +135,9 @@ describe("User", function() {
135135 } ) . catch ( function ( ) {
136136 // already destroyed
137137 } ) . then ( function ( ) {
138- var role = new AV . Role ( "testRole" ) ;
138+ const acl = new AV . ACL ( ) ;
139+ acl . setPublicReadAccess ( true ) ;
140+ var role = new AV . Role ( "testRole" , acl ) ;
139141 role . getUsers ( ) . add ( user ) ;
140142 return role . save ( )
141143 } ) . then ( function ( ) {
You can’t perform that action at this time.
0 commit comments