Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[Package][DbAcl] Help needed to understand functionality.
  • Hello,
    I'm developing an application using the DbAcl Auth extension package authored by Vanitas( http://fuelphp.com/user/416 ) and even thou I have all the data set right, DbAcl::has_access() always returns false. Pasting code, database data and a method I think should be added to this package (committing soon).
    //main.php { Main//Main }
    <?php
    class Main extends Controller_Hybrid
    {
     static $_log;
     static $_resource = array();
     static $_user;
    
     function before ()
     {
      parent::before();
      (string)self::$_resource['controller'] = Request::main()->route->controller;
      (string)self::$_resource['method'] = Request::main()->action;
      self::$_user = \Auth::get_user_id();
      self::has_access();
     }
    
    public static function has_access ()
     { 
      if ( !DbAcl::has_access( self::$_resource['controller'], self::$_resource['method'], self::get_role_name() ) )
      {
       echo "Plop :D";
      }
     }
    
    // This should be added in the DbAcl package
    public static function get_role_name($id = null)
     {
      $user = \Auth::get_user_id();
      ($id) ? $id = $id : $id = $user[1];
      
      $user_role = \DB::select()
         ->from( \Config::get('dbacl.table.users_groups', 'dbacl_user_group') )
         ->where( 'user_id', $id )
         ->execute(\Config::get('dbacl.connection', null))->current();
         
      if (\DB::count_last_query() > 0)
      {
       $group_permission = \DB::select('role_id')
         ->from( \Config::get('dbacl.table.groups_permissions', 'dbacl_group_permission') )
         ->where('group_id', $user_role['group_id'])
         ->execute(\Config::get('dbacl.connection', null))->current();
      }
      
      if (\DB::count_last_query() > 0)
      {
       $role = \DB::select('name')
         ->from( \Config::get('dbacl.table.roles', 'dbacl_role') )
         ->where('id', $group_permission['role_id'])
         ->execute(\Config::get('dbacl.connection', null))->current();
      }
      
      if (\DB::count_last_query() > 0)
      {
       $result = $role['name'];
      }
      else
      {
       $result = false;
      }
      
      return $result;    
     }
    }
    

    dbacl_group:
    id: 1
    name: Administradores
    dbacl_group_permission:
    id: 1
    group_id: 1
    resource_id:1
    role_id:1 dbacl_resource:
    id:1
    namespace: Auth\\
    class: Controller_Auth
    method: index dbacl_role:
    id:1
    namespace: Auth\\
    name: Administrador dbacl_user_group:
    id:1
    user_id:1
    group_id:1 dbacl_user_permission:
    id:1
    user_id:1
    resource_id:1
    role_id:1 Any comments are appreciated =)
    PS: Sorry for the spanish :3
  • I didn't looked closely into get_role_name method but it seams it only searches for role that is assigned to user's group only. Roles that are assigned directly to user are not being searched. Can you explain the idea of searching roles by user ID? Roles are assigned to namespace not user - one user might be asigned to many roles with the same name but under different namespaces. Also you always use ->curent(), what if only "second" group has desired role not the first found? The idea of this package was:
    1) Developer knows current controller's name / namespace.
    2) Dev knows current method's name.
    3) Dev knows which roles are allowed under current namespace and which role he wants to test when he use has_access method. Maybe you wanted something like:
    get_roles('classname', 'methodname')
    which would return all roles assigned to this resource? I'll check this issue anyway.
  • The idea behind it was to make the validation dynamically, so one wouldn't have to write code over and over for each single controller. So you get the roles the user has and match them against what's on the database, and the validation is done.
    I figured out it would be better that way.
    In other regards, I'm trying really hard to get it to pass the validation. I made sure I passed all the right parameters and even then it won't validate. Take a look at the code please.
  • Moved to the 'code share' forum, this question is not related to FuelPHP's Auth package.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion