mdmsoft / yii2-admin

Auth manager for Yii2 (RBAC Manager)
GNU General Public License v3.0
1.16k stars 574 forks source link

Helper::filterActionColumn problem #291

Open fullflash opened 8 years ago

fullflash commented 8 years ago

i am trying to hide edit button for user with rule ownNews use should not see edit button on news that not created by him.

Helper::filterActionColumn('{view}{update}{delete}')

there are two post in news/index gridview but filterActionColumn triggers just once it should check for each row right ?

public function execute($user, $item, $params)
    {
        if(isset($params["id"])) {
            $news_id = $params["id"];
            $data = News::find()->select("created_by")->where(["id" => $news_id])->limit(1)->asArray()->one();
            return isset($data) ? $user == $data["created_by"] : false;
        }
        return false;
    }
fullflash commented 8 years ago

i got solution but wonder if it is any yii2-admin module inbuilt solution.

[
                'class' => 'yii\grid\ActionColumn',
//                "template"=>\mdm\admin\components\Helper::filterActionColumn('{view}{update}{delete}'),
                'visibleButtons'=>[
                    "update"=>function($model, $key, $index) {
                        return \mdm\admin\components\Helper::checkRoute("update",["id"=>$key]);
                //or passing news to parameter and implementing it in rules without getting model
                    },
                    "view"=>function($model, $key, $index) {
                        return \mdm\admin\components\Helper::checkRoute("view");
                    },
                    "delete"=>function($model, $key, $index) {
                        return \mdm\admin\components\Helper::checkRoute("delete");
                    }
                ]
            ]
mdmunir commented 8 years ago

No, filterActionColum only execute once.