Changeset 2859

Show
Ignore:
Timestamp:
11/24/08 03:10:34 (7 weeks ago)
Author:
bjohnson
Message:

Fixing bugs in ACL and Bitmask classes such that we now pass the ACL tests again.

Location:
trunk/htdocs/system/classes
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/classes/acl.php

    r2850 r2859  
    2929     * Check the permission bitmask for a particular access type. 
    3030     * @param mixed $permission The permission bitmask 
    31      * @param mixed $access The name of the access to check against (read, write, delete) 
     31     * @param mixed $access The name of the access to check against (read, write, full) 
    3232     * @return bool Returns true if the given access meets exceeds the access to check against 
    3333     */ 
    34     public static function access_check( $permission_flag, $access ) 
     34    public static function access_check( $permission, $access ) 
    3535    {        
    3636        $bitmask = new Bitmask( self::$access_names, $permission ); 
    3737         
     38        if ( $access == 'full' ) { 
     39            return $bitmask->read && $bitmask->write; 
     40        } 
    3841        return $bitmask->$access; 
    3942    } 
     
    277280  AND ug.user_id = :user_id 
    278281  AND gp.token_id = :token_id 
    279   ORDER BY gp.permission_id 
     282  ORDER BY permission_id ASC 
    280283  LIMIT 1; 
    281284SQL; 
     
    376379    public static function grant_user( $user_id, $token_id, $access = 'full' ) 
    377380    { 
    378         $permission_id = DB::get_value( 'SELECT permission_id FROM {user_token_permissions} WHERE group_id=? AND token_id=?', 
     381        $permission_id = DB::get_value( 'SELECT permission_id FROM {user_token_permissions} WHERE user_id=? AND token_id=?', 
    379382            array( $user_id, $token_id ) ); 
    380383        if ( $permission_id ===  false ) { 
  • trunk/htdocs/system/classes/bitmask.php

    r2850 r2859  
    6464     */ 
    6565    public function __get( $bit ) { 
    66         if ( is_int( $bit ) ) { 
    67             $flags = array_values( $this->flags ); 
     66        if ( is_string( $bit ) ) { 
     67            $bit = array_search( $bit, $this->flags ); 
    6868        } 
    69         else { 
    70             $flags = $this->flags; 
    71         } 
    72         if ( ! isset( $flags[$bit] ) ) { 
     69        if ( $bit === false ) 
    7370            return false; 
    74         } 
    75         return ( ( $this->value & $this->flags[$bit] ) == $this->flags[$bit] ); 
     71        return $this->value & pow(2, $bit); 
    7672    } 
    7773 
    7874} 
    7975?> 
     76