public function can_be($method, \System\User $user) { $member = \Impro\Team\Member::get_first()->where(array('id_system_user' => $user->id, 'id_impro_team' => $this->team->id))->fetch(); if ($method == \System\Model\Perm::BROWSE) { return true; } return $user->is_root() || in_array(ID_MANAGER, $member->roles) || in_array(ID_TRAINER, $member->roles); }
/** Ask if user has right to do this * @param string $method One of created, browsed * @param System\User $user User to get perms for * @return bool */ public static function can_user($method, \System\User $user) { if ($user->is_root()) { return true; } $cname = get_called_class(); $conds = array(); if (isset($cname::$access) && isset($cname::$access[$method]) && !is_null($cname::$access[$method])) { return !!$cname::$access[$method]; } if ($user->is_guest()) { $conds['public'] = true; } else { $groups = $user->get_groups(); if (any($groups)) { $conds[] = 'id_group IN (' . implode(',', collect_ids($groups)) . ')'; } } $perm = \System\User\Perm::get_first()->add_filter(array('attr' => 'trigger', 'type' => 'in', 'in' => array('model-' . $method, '*')))->add_filter(array('attr' => 'name', 'type' => 'in', 'in' => array(\System\Loader::get_model_from_class($cname) . \System\Loader::SEP_MODEL . $method, '*')))->where($conds)->fetch(); return $perm ? $perm->allow : static::get_default_for($method); }