@@ -297,10 +297,10 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
297297 * the existing Resource from which the newly added Resource will inherit.
298298 *
299299 * @param {string } resource
300- * @param {string } parent
300+ * @param {string } [parent=null] parent
301301 * @return {AclService } Provides a fluent interface
302302 */
303- this . addResource = function ( resource , parent /*null*/ ) {
303+ this . addResource = function ( resource , parent ) {
304304 parent = typeof parent === 'undefined' ? null : parent ;
305305
306306 var resourceId = resource ;
@@ -363,6 +363,47 @@ angular.module('stylet.acl').service('AclService', ["AclRegistryService", functi
363363 return _resources [ resource ] !== undefined ;
364364 } ;
365365
366+ /**
367+ * Returns true if and only if $resource inherits from $inherit
368+ *
369+ * Both parameters may be either a Resource or a Resource identifier. If
370+ * $onlyParent is true, then $resource must inherit directly from
371+ * $inherit in order to return true. By default, this method looks
372+ * through the entire inheritance tree to determine whether $resource
373+ * inherits from $inherit through its ancestor Resources.
374+ *
375+ * @param {(AclResourceInterface|string) } resource
376+ * @param {(AclResourceInterface|string) } inherit
377+ * @param {boolean } [onlyParent=false] onlyParent
378+ * @return {boolean }
379+ */
380+ this . inheritsResource = function ( resource , inherit , onlyParent ) {
381+ resource = self . getResource ( resource ) ;
382+ inherit = self . getResource ( inherit ) ;
383+
384+ var parentId = null ;
385+
386+ if ( _resources [ resource ] . parent !== null ) {
387+ parentId = _resources [ resource ] . parent ;
388+ if ( parentId === inherit ) {
389+ return true ;
390+ } else if ( onlyParent ) {
391+ return false ;
392+ }
393+ } else {
394+ return false ;
395+ }
396+
397+ while ( _resources [ parentId ] . parent !== null ) {
398+ parentId = _resources [ parentId ] . parent ;
399+ if ( inherit === parentId ) {
400+ return true ;
401+ }
402+ }
403+
404+ return false ;
405+ } ;
406+
366407 /**
367408 * Removes a Resource and all of its children
368409 *
0 commit comments