Changeset 11847

Show
Ignore:
Timestamp:
08/30/07 11:29:03 (1 year ago)
Author:
w_i
Message:

added privilege handling to uimessages. refs #102, refs #30

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.core/midcom/baseclasses/core/object.php

    r3766 r11847  
    2626{ 
    2727    function midcom_baseclasses_core_object() {} 
     28     
     29    function get_class_magic_default_privileges() 
     30    { 
     31        return array 
     32        ( 
     33            'EVERYONE' => array(), 
     34            'ANONYMOUS' => array(), 
     35            'USERS' => array() 
     36        ); 
     37    } 
    2838} 
    2939 
  • trunk/midcom/midcom.core/midcom/services/auth.php

    r11845 r11847  
    948948            if ($tmp_object !== null) 
    949949            { 
     950                if (!isset($tmp_object->__new_class_name__)) 
     951                { 
     952                    $tmp_class_name = get_class($tmp_object); 
     953                } 
     954                else 
     955                { 
     956                    $tmp_class_name = $tmp_object->__new_class_name__; 
     957                } 
     958                 
    950959                $default_magic_class_privileges = array_merge 
    951960                ( 
    952                     $this->_default_magic_class_privileges[$tmp_object->__new_class_name__]['EVERYONE'], 
    953                     $this->_default_magic_class_privileges[$tmp_object->__new_class_name__]['ANONYMOUS'] 
     961                    $this->_default_magic_class_privileges[$tmp_class_name]['EVERYONE'], 
     962                    $this->_default_magic_class_privileges[$tmp_class_name]['ANONYMOUS'] 
    954963                ); 
    955964            } 
     
    23862395    { 
    23872396        // Check if we have loaded these privileges already... 
    2388         if (array_key_exists($class->__new_class_name__, $this->_default_magic_class_privileges)) 
     2397        if (!isset($class->__new_class_name__)) 
     2398        { 
     2399            $loadable_class = get_class($class); 
     2400        } 
     2401        else 
     2402        { 
     2403            $loadable_class = $class->__new_class_name__; 
     2404        } 
     2405         
     2406        if (array_key_exists($loadable_class, $this->_default_magic_class_privileges)) 
    23892407        { 
    23902408            return; 
     
    23922410 
    23932411        $privs = $class->get_class_magic_default_privileges(); 
    2394         $this->_default_magic_class_privileges[$class->__new_class_name__] = $privs; 
     2412        $this->_default_magic_class_privileges[$loadable_class] = $privs; 
    23952413 
    23962414        return; 
  • trunk/midcom/midcom.core/midcom/services/uimessages.php

    r3911 r11847  
    9696        $this->_allowed_types[] = 'warning'; 
    9797        $this->_allowed_types[] = 'error'; 
    98          
    99         $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL."/Pearified/JavaScript/Prototype/prototype.js"); 
    100         $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL."/Pearified/JavaScript/Scriptaculous/scriptaculous.js"); 
    101         $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/midcom.services.uimessages/protoGrowl.js'); 
    102          
    103         $_MIDCOM->add_link_head( 
    104             array 
    105             ( 
    106                 'rel'   => 'stylesheet', 
    107                 'type'  => 'text/css', 
    108                 'media' => 'screen', 
    109                 'href'  => MIDCOM_STATIC_URL . '/midcom.services.uimessages/protoGrowl.css', 
    110             ) 
    111         ); 
     98        $this->_allowed_types[] = 'debug'; 
    11299    } 
    113100 
     
    118105    function initialize() 
    119106    { 
     107        if ($_MIDCOM->auth->can_user_do('midcom:ajax', null, 'midcom_services_uimessages')) 
     108        {         
     109            $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL."/Pearified/JavaScript/Prototype/prototype.js"); 
     110            $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL."/Pearified/JavaScript/Scriptaculous/scriptaculous.js"); 
     111            $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL . '/midcom.services.uimessages/protoGrowl.js'); 
     112         
     113            $_MIDCOM->add_link_head( 
     114                array 
     115                ( 
     116                    'rel'   => 'stylesheet', 
     117                    'type'  => 'text/css', 
     118                    'media' => 'screen', 
     119                    'href'  => MIDCOM_STATIC_URL . '/midcom.services.uimessages/protoGrowl.css', 
     120                ) 
     121            ); 
     122        } 
     123        else 
     124        { 
     125            $_MIDCOM->add_link_head( 
     126                array 
     127                ( 
     128                    'rel'   => 'stylesheet', 
     129                    'type'  => 'text/css', 
     130                    'media' => 'screen', 
     131                    'href'  => MIDCOM_STATIC_URL . '/midcom.services.uimessages/simple.css', 
     132                ) 
     133            );             
     134        } 
     135 
    120136        if (!$_MIDGARD['user']) 
    121137        { 
     
    143159            } 
    144160        } 
     161    } 
     162     
     163    function get_class_magic_default_privileges() 
     164    { 
     165        $privileges = parent::get_class_magic_default_privileges(); 
     166        //$privileges['EVERYONE']['midgard:read'] = MIDCOM_PRIVILEGE_DENY; 
     167        return $privileges; 
    145168    } 
    146169     
     
    219242     
    220243    /** 
    221      * Show the message stack via javascript calls 
     244     * Show the message stack via javascript calls or simple html 
    222245     */ 
    223246    function show() 
     
    225248        if (count($this->_message_stack) > 0) 
    226249        { 
    227             echo "<script language=\"javascript\">\n"; 
    228  
    229             foreach ($this->_message_stack as $id => $message) 
    230             { 
    231                 // TODO: Use our own JS call for this 
    232                 echo "    new protoGrowl({type: '{$message['type']}', title: '{$message['title']}', message: '{$message['message']}'});\n"; 
    233                 //echo "ooDisplayMessage('{$message['title']}: {$message['message']}', '{$message['type']}');\n"; 
     250            if ($_MIDCOM->auth->can_user_do('midcom:ajax', null, 'midcom_services_uimessages')) 
     251            { 
     252                echo "<script type=\"text/javascript\">\n"; 
     253 
     254                foreach ($this->_message_stack as $id => $message) 
     255                { 
     256                    // TODO: Use our own JS call for this 
     257                    echo "    new protoGrowl({type: '{$message['type']}', title: '{$message['title']}', message: '{$message['message']}'});\n"; 
     258                    //echo "ooDisplayMessage('{$message['title']}: {$message['message']}', '{$message['type']}');\n"; 
    234259                 
    235                 // Remove the message from stack 
    236                 unset($this->_message_stack[$id]); 
    237             } 
    238             echo "</script>\n";         
    239         } 
    240     } 
     260                    // Remove the message from stack 
     261                    unset($this->_message_stack[$id]); 
     262                } 
     263                echo "</script>\n"; 
     264            } 
     265            else 
     266            { 
     267                echo "<div class=\"midcom_services_uimessages_holder\">\n"; 
     268 
     269                foreach ($this->_message_stack as $id => $message) 
     270                { 
     271                    $this->_render_simple_message($message); 
     272 
     273                    // Remove the message from stack 
     274                    unset($this->_message_stack[$id]); 
     275                } 
     276 
     277                echo "</div>\n"; 
     278            } 
     279        } 
     280    } 
     281 
     282    /** 
     283     * Render the message via simple html 
     284     */     
     285    function _render_simple_message($message) 
     286    { 
     287        echo "<div class=\"midcom_services_uimessages_message {$message['type']}\">"; 
     288         
     289        echo "<div class=\"midcom_services_uimessages_message_title\">{$message['title']}</div>"; 
     290        echo "<div class=\"midcom_services_uimessages_message_msg\">{$message['message']}</div>"; 
     291         
     292        echo "</div>\n"; 
     293    } 
     294     
    241295} 
    242296