import { CommonUtil } from './../utils/' ; import { IQueryInfo } from '../core' ; /**
 *  Represents the inner `Permission` class that defines the granted or denied
 *  access permissions for the target resource and role.
 *
 *  You can check for a permission in two ways:
 *
 *  <ul>
 *  <li>
 *  You can first obtain a  {@link ?api=ac#AccessControl~Query|`Query` instance} *  via  {@link ?api=ac#AccessControl#can|`AccessControl#can`} which returns
 *  a `Permission` instance when an action method such as
 *   {@link ?api=ac#AccessControl~Query#createAny|`.createAny()`} is
 *  called.
 *  <p><pre><code> var permission = ac.can('user').createAny('video');
 *  console.log(permission.granted); // boolean</code></pre></p>
 *  </li>
 *  <li>
 *  Or you can call  {@link ?api=ac#AccessControl#permission|`AccessControl#permission`} *  by passing a fulfilled  {@link ?api=ac#AccessControl#IQueryInfo|`IQueryInfo` object} .
 *  <p><pre><code> var permission = ac.permission({
 *      role: 'user',
 *      resource: 'video',
 *      action: 'create'
 *  });
 *  console.log(permission.granted); // boolean</code></pre></p>
 *  </li>
 *  </ul>
 *
 *   class inner memberof class Permission { private private _ : any = { } ; private param { IQueryInfo } query constructor ( query , attributes ) { this . _ . role = query . role ; this . _ . resource = query . resource ; this . _ . context = query . context ; this . _ . attributes = attributes ; } name type { Array < String > } readonly get roles ( ) : string [ ] { return this . _ . role ; } name type { String } readonly get resource ( ) : string { return this . _ . resource ; } name type { Array < string > } readonly get attributes ( ) : string [ ] { return this . _ . attributes ; } name type { Boolean } readonly get granted ( ) { if ( ! this . attributes || this . attributes . length === 0 ) { return false ; } return this . attributes . some ( ( attr ) => { return attr . trim ( ) . slice ( 0 , 1 ) !== '!' ; } ) ; } param { Object | Array } data returns { Object | Array } filter ( data ) { return CommonUtil . filterAll ( data , this . attributes ) ; } } export { Permission } ;