portal.mkgtu.ru/common/rbac/rule/OwnModel.php

30 lines
420 B
PHP
Raw Permalink Normal View History

2024-03-28 09:51:45 +03:00
<?php
namespace common\rbac\rule;
use yii\rbac\Item;
use yii\rbac\Rule;
class OwnModel extends Rule
{
public $name = 'ownModelRule';
public function execute($user, $item, $params)
{
$attribute = isset($params['attribute']) ? $params['attribute'] : 'created_by';
return $user && isset($params['model']) && $user === $params['model']->getAttribute($attribute);
}
}