kartik-v / yii2-tree-manager

An advanced tree management module using nested sets for Yii 2.
http://demos.krajee.com/tree-manager
Other
150 stars 107 forks source link

Yii2- Hide admin settings based on user role #273

Closed fasi1208 closed 3 years ago

fasi1208 commented 3 years ago

I have a tree in which I want to set isAdmin parameter true or false based on user_role. I have done the following

'isAdmin' => function(){ if (Yii::$app->user->identity->user_role == 1) { return true; } else { return false; } },

But I am getting an error

Operation Disallowed Invalid request signature detected during tree data manage action! Please refresh the page and retry. OLD HASH: 785a3cf9cbb1a90e862b718ed8ae3289944280448ae801de49d686aa5f70e951common\models\MdcNodehidebtn-default/mdc/backend/web/treemanager/node/save/mdc/backend/web/mdcnode/index@kvtree/views/_formw0-nodeselnodenodes

No valid nodes are available for display. Use toolbar buttons to add nodes.
111111{"id":"w0-nodeform"}{"1":"","2":"","3":"","4":"","5":""}{"submit":"<i class=\"glyphicon glyphicon-floppy-disk\">","reset":"<i class=\"glyphicon glyphicon-repeat\">"}a:0:{}[]list{"":"Default ( <span class=\"text-warning kv-node-icon kv-icon-parent\"><i class=\"fa fa-folder-close kv-node-closed\"> / <span class=\"text-warning kv-node-icon kv-icon-parent\"><i class=\"fa fa-folder-open kv-node-opened\"> / <span class=\"text-info kv-node-icon kv-icon-child\"><i class=\"fa fa-file\">)","building":"<span class=\"fa fa-building\"> Building","folder":"<span class=\"fa fa-folder\"> Floor","user":"<span class=\"fa fa-user\"> Customer"}{"depth":"","glue":" » ","activeCss":"kv-crumb-active","untitled":"Untitled"} NEW HASH: e3037c327c2ddec080a38ce50002f825a214352f833f2acfe972c3d7d0a2b9abcommon\models\MdcNodehidebtn-default/mdc/backend/web/treemanager/node/save/mdc/backend/web/mdcnode/index@kvtree/views/_formw0-nodeselnodenodes
No valid nodes are available for display. Use toolbar buttons to add nodes.
11111{"id":"w0-nodeform"}{"1":"","2":"","3":"","4":"","5":""}{"submit":"<i class=\"glyphicon glyphicon-floppy-disk\">","reset":"<i class=\"glyphicon glyphicon-repeat\">"}a:0:{}[]list{"":"Default ( <span class=\"text-warning kv-node-icon kv-icon-parent\"><i class=\"fa fa-folder-close kv-node-closed\"> / <span class=\"text-warning kv-node-icon kv-icon-parent\"><i class=\"fa fa-folder-open kv-node-opened\"> / <span class=\"text-info kv-node-icon kv-icon-child\"><i class=\"fa fa-file\">)","building":"<span class=\"fa fa-building\"> Building","folder":"<span class=\"fa fa-folder\"> Floor","user":"<span class=\"fa fa-user\"> Customer"}{"depth":"","glue":" » ","activeCss":"kv-crumb-active","untitled":"Untitled"}

I don't know what I am missing.

gilangsugihardiansah commented 3 years ago

try this 'isAdmin' => Yii::$app->user->identity->user_role == 1,

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

kartik-v commented 3 years ago

Yes - the isAdmin property should be a boolean value (and must not be a function as you have done).