public function isActionAuthorizedForUser($userId, $groupName, $actionName = null, $ownerId = null) { $userId = (int) $userId; if (isset($this->groupCache[$groupName])) { $groupId = $this->groupCache[$groupName]; } else { return false; } // contains user's role ids $roles = array(); if ($userId > 0 || OW::getUser()->isAuthenticated()) { $userId = $userId > 0 ? $userId : OW::getUser()->getId(); if ($actionName === null) { if (isset($this->moderatorCache[$userId])) { $moderatorId = $this->moderatorCache[$userId]; $adminGroupId = $this->groupCache[self::ADMIN_GROUP_NAME]; return isset($this->moderatorPermissionCache[$moderatorId][$groupId]) || $this->isSuperModerator($userId); } else { return false; } } if ($ownerId !== null && (int) $ownerId !== $userId) { return false; } if (!array_key_exists($userId, $this->userRolesCache)) { $this->userRolesCache[$userId] = $this->userRoleDao->getRoleIdList($userId); } $roles = $this->userRolesCache[$userId]; } else { $roles[] = $this->guestRoleId; } if (isset($this->actionCache[$actionName][$groupId])) { $actionId = $this->actionCache[$actionName][$groupId]; } else { return false; } $permissionId = null; foreach ($roles as $role) { if (isset($this->permissionCache[$actionId][$role])) { $permissionId = $this->permissionCache[$actionId][$role]; break; } } return $permissionId !== null; }