Exemplo n.º 1
0
 /** 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);
 }