Skip to content

Commit 21e92ce

Browse files
committed
getResources & getRoles methods added
1 parent e0e5af1 commit 21e92ce

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

dist/acl.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
347347
return _resources[resource].id;
348348
};
349349

350+
/**
351+
* @return {Array.<string>} of registered resources
352+
*/
353+
this.getResources = function () {
354+
return Object.keys(_resources);
355+
};
356+
350357
/**
351358
* Returns true if and only if the Resource exists in the ACL
352359
*
@@ -479,7 +486,7 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
479486
* highest priority.
480487
*
481488
* @param {string} role
482-
* @param {(string|Array)} [parents=null] parents
489+
* @param {(string|Array.<string>)} [parents=null] parents
483490
* @return {AclService} Provides a fluent interface
484491
*/
485492
this.addRole = function (role, parents) {
@@ -502,6 +509,13 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
502509
return _roleRegistry.get(role);
503510
};
504511

512+
/**
513+
* @return {Array.<string>} of registered roles
514+
*/
515+
this.getRoles = function () {
516+
return Object.keys(_roleRegistry.getItems());
517+
};
518+
505519
/**
506520
* Returns true if and only if the Role exists in the registry
507521
*
@@ -1119,6 +1133,10 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
11191133
}
11201134
}
11211135
}]);
1136+
/**
1137+
* @ngdoc service
1138+
* @name AclRegistryService
1139+
*/
11221140
angular.module('stylet.acl').factory('AclRegistryService', function () {
11231141
'use strict';
11241142

src/acl-registry-service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @ngdoc service
3+
* @name AclRegistryService
4+
*/
15
angular.module('stylet.acl').factory('AclRegistryService', function () {
26
'use strict';
37

src/acl-service.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,13 @@ angular.module('stylet.acl').service('AclService', function (AclRegistryService)
346346
return _resources[resource].id;
347347
};
348348

349+
/**
350+
* @return {Array.<string>} of registered resources
351+
*/
352+
this.getResources = function () {
353+
return Object.keys(_resources);
354+
};
355+
349356
/**
350357
* Returns true if and only if the Resource exists in the ACL
351358
*
@@ -478,7 +485,7 @@ angular.module('stylet.acl').service('AclService', function (AclRegistryService)
478485
* highest priority.
479486
*
480487
* @param {string} role
481-
* @param {(string|Array)} [parents=null] parents
488+
* @param {(string|Array.<string>)} [parents=null] parents
482489
* @return {AclService} Provides a fluent interface
483490
*/
484491
this.addRole = function (role, parents) {
@@ -501,6 +508,13 @@ angular.module('stylet.acl').service('AclService', function (AclRegistryService)
501508
return _roleRegistry.get(role);
502509
};
503510

511+
/**
512+
* @return {Array.<string>} of registered roles
513+
*/
514+
this.getRoles = function () {
515+
return Object.keys(_roleRegistry.getItems());
516+
};
517+
504518
/**
505519
* Returns true if and only if the Role exists in the registry
506520
*

test/acl-service.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ describe('ncAclService', function () {
8585

8686
describe('Role management', function () {
8787

88+
it('ensures that getRoles() method works as expected', function () {
89+
expect(AclService.getRoles()).toEqual([]);
90+
91+
AclService
92+
.addRole('guest')
93+
.addRole('staff', 'guest')
94+
.addRole('editor', 'staff')
95+
.addRole('administrator');
96+
97+
expect(AclService.getRoles()).toEqual(['guest', 'staff', 'editor', 'administrator']);
98+
});
99+
88100
it('basic role adding/removal', function () {
89101
AclService.addRole('User');
90102
AclService.addRole('Manager', 'User');
@@ -126,6 +138,18 @@ describe('ncAclService', function () {
126138

127139
describe('Resource management', function () {
128140

141+
it('ensures that getResources() method works as expected', function () {
142+
expect(AclService.getResources()).toEqual([]);
143+
144+
AclService
145+
.addResource('Animal')
146+
.addResource('Cat', 'Animal')
147+
.addResource('Kitty', 'Cat')
148+
.addResource('Rock');
149+
150+
expect(AclService.getResources()).toEqual(['Animal', 'Cat', 'Kitty', 'Rock']);
151+
});
152+
129153
it('should remove single resource', function () {
130154
AclService
131155
.addResource('Animal')

0 commit comments

Comments
 (0)