Changeset 415 for trunk/user.php


Ignore:
Timestamp:
Oct 7, 2012, 8:37:15 PM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Optimalizace kontroly oprávnění operací.
  • Upraveno: Načítání skupin odkazů na hlavní stránce.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        66postfixadmin
        77backup
         8.project
         9.buildpath
         10.settings
  • trunk/user.php

    r410 r415  
    3434  var $AnonymousUserId = 98;
    3535  var $OnlineStateTimeout = 600; // in seconds
     36  var $PermissionCache = array();
    3637
    3738  function Check()
     
    5253    if($Row['User'] != $this->AnonymousUserId)
    5354    {
    54       $Query = $this->Database->query('SELECT *, UserCustomerRel.Customer AS Member FROM User JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);     
     55      $Query = $this->Database->query('SELECT User.*, UserCustomerRel.Customer AS Member FROM User JOIN UserCustomerRel ON UserCustomerRel.User=User.Id WHERE User.Id='.$Row['User']);     
    5556      $this->User = $Query->fetch_assoc();
    5657      $Result = USER_LOGGED;
     
    208209  function CheckPermission($Module, $Operation, $ItemType = '', $ItemIndex = 0)
    209210  {
    210         $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
    211     if($DbResult->num_rows > 0)
    212     {
    213       $DbRow = $DbResult->fetch_array();
    214       $OperationId = $DbRow['Id'];
    215 
     211    // First try to check cache
     212    if(in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
     213    {
     214      $OperationId = array_search(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache);
     215      $PermissionExists = is_numeric($OperationId);
     216    } else
     217    {   
     218      // If no permission combination exists in cache, do new check of database items
     219      $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$Module.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
     220      if($DbResult->num_rows > 0)
     221      {
     222        $DbRow = $DbResult->fetch_array();
     223        $OperationId = $DbRow['Id'];
     224        $this->PermissionCache[$DbRow['Id']] = array($Module, $Operation, $ItemType, $ItemType);       
     225        $PermissionExists = true;
     226      } else
     227      {         
     228        $this->PermissionCache[$DbRow['Id'].'_'] = array($Module, $Operation, $ItemType, $ItemType);       
     229        $PermissionExists = false;
     230      }
     231    }
     232
     233    if($PermissionExists)
     234    {
    216235      // Check user-operation relation
    217236      $DbResult = $this->Database->select('PermissionUserAssignment', '*', '`User`="'.$this->User['Id'].'" AND `AssignedOperation`="'.$OperationId.'"');
     
    219238
    220239      // Check user-group relation
    221       $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', '`User`="'.$this->User['Id'].'" AND `AssignedGroup` IS NOT NULL');
     240      $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', '`User`="'.$this->User['Id'].'"');
    222241      while($DbRow = $DbResult->fetch_array())
    223242      {
    224          if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
     243       if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
    225244      }
    226245      return(false);
Note: See TracChangeset for help on using the changeset viewer.