2017-02-28 3 views
2

私のアプリケーションでユーザーの役割とアクセス許可をドキュメントに従って定義しました。これによりangle-permission:ユーザーがコントローラから役割または権限を持っているかどうかを確認する

https://github.com/Narzerus/angular-permission/wiki

私は、UIディレクティブまたはUI-ルータの処理を使用することができています。


Q:ユーザーがコントローラまたはサービス内で役割または権限を持っていることをテストするにはどうすればよいですか。

(function() { 
    'use strict'; 

    angular 
    .module('app') 
    .component('userDetail', component()); 

    /** @ngInject */ 
    function component() { 
    return { 
     restrict: 'E', 
     bindings: { 
     user: '<' 
     }, 
     templateUrl: 'app/components/users/user-detail/user-detail.html', 
     transclude: true, 
     controller: Controller 
    } 
    } 

    /** @ngInject */ 
    function Controller($log) { 
    var ctrl = this; 
    ctrl.$onInit = function() { 
     $log.log('How to test for user permission?') 
     // Something like... 
     // if(PermPermission.hasPermission('createUser')) { 
     // do something 
     // } 
    }; 
    } 
})(); 
+1

([、最小完全、かつ検証例]を提供することを検討してくださいHTTP可能であれば、少なくともあなたがこれまでに試したこと(コード)/あなたがやろうとしていること(より具体的)を投稿してください。これは広すぎますIMO – lealceldeiro

+0

@AsielLealCeldeiro、この場合は私は同意しません。そのデモのとおりhttps://cdn.rawgit.com/Narzerus/angular-permission/0d502cb4/test/e2e/permission-ui/assets/demo.html – Blowsie

答えて

2

@blowsieこれは私がそれを管理する方法ですが、それは非常に重い感じ:

export default { 
 
    template: '<div></div>', 
 
    controller: class test { 
 
    /* @ngInject */ 
 
    constructor(PermPermissionStore) { 
 
     PermPermissionStore.definePermission('truePermission',() => true); 
 
     PermPermissionStore.definePermission('falsePermission',() => false); 
 

 
     const truePerm = PermPermissionStore.getPermissionDefinition('truePermission'); 
 
     const falsePerm = PermPermissionStore.getPermissionDefinition('falsePermission'); 
 

 
     truePerm.validatePermission() 
 
     .then((res) => { /* you go there */ }) 
 
     .catch((e) => { /* never go there */ }); 
 
     falsePerm.validatePermission() 
 
     .then((res) => { /* never go there */ }) 
 
     .catch((e) => { /* you go there */ }); 
 
    } 
 
    }, 
 
};

関連する問題