Ejemplo n.º 1
0
 public function call($pathChunks = array(), $permissionFlag = true)
 {
     $arg = array_shift($pathChunks);
     try {
         $subController = self::loadController($arg, get_class($this), true);
     } catch (Scalr_UI_Exception_NotFound $e) {
         $subController = null;
     }
     if ($subController) {
         $this->addUiCacheKeyPatternChunk($arg);
         $subController->uiCacheKeyPattern = $this->uiCacheKeyPattern;
         $subController->call($pathChunks, $permissionFlag);
     } else {
         if (($action = $arg . 'Action') && method_exists($this, $action)) {
             $this->addUiCacheKeyPatternChunk($arg);
             $this->response->setHeader('X-Scalr-Cache-Id', $this->uiCacheKeyPattern);
             if (!$permissionFlag) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
             $this->unusedPathChunks = $pathChunks;
             $this->callActionMethod($action);
         } else {
             if (count($pathChunks) > 0) {
                 $constName = get_class($this) . '::CALL_PARAM_NAME';
                 if (defined($constName)) {
                     $const = constant($constName);
                     $this->request->setParams(array($const => $arg));
                     $this->addUiCacheKeyPatternChunk('{' . $const . '}');
                 } else {
                     // Invar: notice
                 }
                 $this->call($pathChunks, $permissionFlag);
             } else {
                 if (method_exists($this, 'defaultAction') && $arg == '') {
                     $this->response->setHeader('X-Scalr-Cache-Id', $this->uiCacheKeyPattern);
                     if (!$permissionFlag) {
                         throw new Scalr_Exception_InsufficientPermissions();
                     }
                     $this->callActionMethod('defaultAction');
                 } else {
                     throw new Scalr_UI_Exception_NotFound();
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function call($pathChunks, $permissionFlag = true)
 {
     $arg = array_shift($pathChunks);
     if ($this->user) {
         if ($this->user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
             if (!$this->user->isTeamUserInEnvironment($this->getEnvironmentId(), Scalr_Account_Team::PERMISSIONS_OWNER) && !$this->user->isTeamUserInEnvironment($this->getEnvironmentId(), Scalr_Account_Team::PERMISSIONS_FULL)) {
                 if (method_exists($this, 'getPermissionDefinitions')) {
                     // rules defined for this controller
                     $cls = get_class($this);
                     $clsShort = str_replace('Scalr_UI_Controller_', '', $cls);
                     $methodShort = str_replace('Action', '', $method);
                     $clsPermissions = $cls::getPermissionDefinitions();
                     $permissions = $this->user->getGroupPermissions($this->getEnvironmentId());
                     if (array_key_exists($clsShort, $permissions)) {
                         $perm = $permissions[$clsShort];
                         if (in_array('VIEW', $perm, true) || in_array('FULL', $perm, true)) {
                             $permissionFlag = true;
                         } else {
                             $permissionFlag = false;
                         }
                     } else {
                         $permissionFlag = false;
                     }
                 }
             }
         }
     }
     try {
         $subController = self::loadController($arg, get_class($this), true);
     } catch (Scalr_UI_Exception_NotFound $e) {
         $subController = null;
     }
     if ($subController) {
         $this->addUiCacheKeyPatternChunk($arg);
         $subController->uiCacheKeyPattern = $this->uiCacheKeyPattern;
         $subController->call($pathChunks, $permissionFlag);
     } else {
         if (($action = $arg . 'Action') && method_exists($this, $action)) {
             $this->addUiCacheKeyPatternChunk($arg);
             $this->response->setHeader('X-Scalr-Cache-Id', $this->uiCacheKeyPattern);
             if (!$permissionFlag) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
             $this->callActionMethod($action);
         } else {
             if (count($pathChunks) > 0) {
                 $const = constant(get_class($this) . '::CALL_PARAM_NAME');
                 if ($const) {
                     $this->request->setParams(array($const => $arg));
                     $this->addUiCacheKeyPatternChunk('{' . $const . '}');
                 } else {
                     // TODO notice
                 }
                 $this->call($pathChunks, $permissionFlag);
             } else {
                 if (method_exists($this, 'defaultAction') && $arg == '') {
                     $this->response->setHeader('X-Scalr-Cache-Id', $this->uiCacheKeyPattern);
                     if (!$permissionFlag) {
                         throw new Scalr_Exception_InsufficientPermissions();
                     }
                     $this->callActionMethod('defaultAction');
                 } else {
                     throw new Scalr_UI_Exception_NotFound();
                 }
             }
         }
     }
 }