Changeset 3416

Show
Ignore:
Timestamp:
06/09/07 04:44:45 (18 months ago)
Author:
coolengineer
Message:

#408
Add adjusting acl in plugins.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/components/Textcube.Core.php

    r3413 r3416  
    2929    } 
    3030 
    31 } 
    32  
    33 /* Access Control Object: i.e. uri, component, function */ 
     31    function adjust( $aco, $aco_action ) 
     32    { 
     33        global $owner; 
     34        if( !Acl::isAvailable() ) { 
     35            Acl::setCurrentAro( $owner ); 
     36        } 
     37 
     38        $aro = Acl::getCurrentAro(); 
     39        foreach( $aco as $obj ) { 
     40            if( $obj == "group.members" && !empty($_SESSION['userid']) && $_SESSION['userid'] != $owner ) { 
     41                $aro[] = "group.members"; 
     42            } 
     43            if( function_exists("fireEvent") ) { 
     44                $aro = call_user_func( "fireEvent", "AclAdjustAro", $aro, $obj ); 
     45            } 
     46        } 
     47        return $aro; 
     48    } 
     49} 
     50 
     51/* Access Control Object: i.e. uri, components, functions */ 
    3452class Aco { 
    35     function Aco() { 
     53    var $predefiend; 
     54 
     55    function Aco( $predefined = null ) { 
     56        $this->predefined = $predefined; 
     57    } 
     58 
     59    function adjust( $aco, $aco_action ) { 
     60        // $aco is an string array 
     61        if( function_exists("fireEvent") ) { 
     62            $aco = call_user_func("fireEvent", "AclAdjustAco", $aco ); 
     63        } 
     64        return $aco; 
    3665    } 
    3766} 
     
    3968class Acl { 
    4069    function check($aco = null, $aco_action = '*') { 
    41         global $owner; 
    42  
    43         if( $aco == null ) { 
    44             if (empty($_SESSION['userid']) || ($_SESSION['userid'] != $owner)) 
    45                 return false; 
    46             return true; 
    47         } 
    48  
    49         if( !Acl::isAvailable() )  { 
    50             return false; 
    51         } 
     70        global $owner; /*blogid*/ 
    5271 
    5372        if( !is_array( $aco ) ) { 
     
    5574        } 
    5675 
     76        /* Adujsting access controll object from plugins */ 
     77        $aco = Aco::adjust($aco, $aco_action); 
     78 
     79        /* Adujsting required object from plugins by aco*/ 
     80        $aro = Aro::adjust($aco, $aco_action); 
     81 
     82        /* We need one of aco elements is in aro array */ 
     83 
    5784        foreach( $aco as $obj ) { 
    58             /*owner = blogid*/ 
    59             if( in_array( $obj, $_SESSION['acl'][$owner] ) ) { 
     85            if(in_array($obj, $aro)) { 
    6086                return true; 
    6187            } 
    6288        } 
     89 
    6390        return false; 
    6491    } 
    6592 
    66     function setCurrentAro( $blogid, $group, $user, $add = false ) { 
     93    function setCurrentAro( $blogid, $group = null, $user = null, $add = false ) { 
    6794        if( !isset( $_SESSION['acl'] ) ) { 
    6895            $_SESSION['acl'] = array(); 
    6996        } 
     97 
     98        if( !isset( $_SESSION['acl'][$blogid] ) ) { 
     99            $_SESSION['acl'][$blogid] = array(); 
     100        } 
     101 
     102        if( $group === null ) { 
     103            return; 
     104        } 
     105 
    70106        if( $add ) { 
    71107            $_SESSION['acl'][$blogid] = array_merge( $_SESSION['acl'][$blogid], array( $group, $user ) ); 
     
    73109            $_SESSION['acl'][$blogid] = array( $group, $user ); 
    74110        } 
     111    } 
     112 
     113    function getCurrentAro() { 
     114        global $owner; /*blogid*/ 
     115        if( Acl::isAvailable() ) { 
     116            return $_SESSION['acl'][$owner]; 
     117        } 
     118        return array(); 
    75119    } 
    76120 
  • trunk/lib/auth.php

    r3414 r3416  
    6868 
    6969function doesHaveMembership() { 
    70     return empty($_SESSION['userid']) ? false : true; 
    71     /* return Acl::check( "group.members" ); */ 
     70    return Acl::check( "group.members" ); 
    7271} 
    7372