mdmsoft / yii2-admin

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

problem with updateOwnPost #290

Closed fullflash closed 8 years ago

fullflash commented 8 years ago

Hi, i have created AuthorRule under backend\rules with namescape backend\rules with public $name="authorRule"; inside class and overriding execute as described in official guide.

in yii2 admin create a rule with name: authorRule and classname: backend\rules\AuthorRule

added this rule to permission updateOwnNews updateOwnNews is a parent of updateNews permission as described in official docs. updatePost permission has route /news/update

there is a role author with updateOwnNews permission

but user with this author role update post that not created by him. On debugmode breakpoint in execute method just don't triggered. Rule class just not executed. what is wrong ?

adminlte updatenews adminlte authorrule adminlte author adminlte updateownnews

fullflash commented 8 years ago

sorry my mistake. i have commented as access in config during some testing.

but i think this post with screens would be helpfull who has trouble with rules integration in yii2 admin.

Thanks for this excellent module by the way.

fullflash commented 8 years ago

how we can post a variable to $params attrbute ? manually as in yii2 official rbac docs or there is some options in yii2 admin setting to data field or bizrule module ?

public function execute($user, $item, $params)
    {
//        return false;
        return isset($params["news"]) ? $params["news"]->created_by==$user : false;
    }
fullflash commented 8 years ago

changed rule now it works model id passed by $params function argument is enough )

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;
    }
mutahirshah commented 8 years ago

Hi, @fullflash I have trouble in using RULE in this package can you give a clear demo example with code showing how to create a rule and after creating the rule then how to use it in coding. I need a complete example because I tried it very much but I am fail to implement it specially the $param and then calling the rule in code , I think you may be clear with my problem as from you posts it show that you have faced this problem and I think my problem is similar to yours. Thanks.