Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 9
OrganizationUserRule
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 9
 execute
0.00% covered (danger)
0.00%
0 / 1
20.00
0.00% covered (danger)
0.00%
0 / 9
<?php
namespace common\rbac;
use common\models\Organization;
use common\models\Participant;
use yii\rbac\Rule;
/**
 * Checks if user have a supervisor entry
 */
class OrganizationUserRule extends Rule
{
    public $name = 'isMyOrganization';
    /**
     * @param string|integer $user the user ID.
     * @param Item $item the role or permission that this rule is associated with
     * @param array $params parameters passed to ManagerInterface::checkAccess().
     * @return boolean a value indicating whether the rule permits the role or permission it is associated with.
     */
    public function execute($user, $item, $params)
    {
        if(isset($params['organization']) && $params['organization'] instanceof Organization){
            $participant = Participant::find()->where(['user_id' => $user])->with('organization')->one();
            if($participant !== null){
                return $params['organization']->id === $participant->organization->id;
            }
        }
        return false;
    }
}