• Модуль: disk
  • Путь к файлу: ~/bitrix/modules/disk/lib/uf/forummessageconnector.php
  • Класс: BitrixDiskUfForumMessageConnector
  • Вызов: ForumMessageConnector::canRead
public function canRead($userId)
{
	if($this->canRead !== null)
	{
		return $this->canRead;
	}

	if(($res = $this->getDataToCheck($this->entityId)) && !empty($res))
	{
		list($message, $topic) = $res;

		$entityId = null;
		$entityType = null;
		if(!empty($topic["XML_ID"]))
		{
			$entityId = mb_substr($topic["XML_ID"], (mb_strrpos($topic["XML_ID"], "_") + 1));
			$entityType = mb_substr($topic["XML_ID"], 0, mb_strpos($topic["XML_ID"], "_"));

			if (mb_strpos($topic["XML_ID"], "EVENT_") !== false)
			{
				$XML_ID = explode('_', $topic["XML_ID"]);
				if (is_array($XML_ID) && count($XML_ID) > 1)
				{
					$entityType = $XML_ID[0];
					$entityId = $XML_ID[1];
				}
			}
		}

		switch($entityType)
		{
			case "TASK":
				if(Loader::includeModule("tasks"))
				{
					$connector = new BitrixTasksIntegrationDiskConnectorTask($entityId);
					$this->canRead = $connector->canRead($userId);

					return $this->canRead;
				}
				break;
			case "EVENT":
				if(Loader::includeModule("calendar"))
				{
					$connector = new CalendarEventConnector($entityId);
					$this->canRead = $connector->canRead($userId);

					return $this->canRead;
				}
				break;
			case "IBLOCK":
				if ((int)$topic["USER_ID"] > 0 && Loader::includeModule("socialnetwork"))
				{
					$codes = array();
					if (($res = CSocNetLog::getList(
						array(),
						array("SOURCE_ID" => $entityId, "EVENT_ID" => array("photo_photo", "news", "wiki")),
						false,
						false,
						array("ID")
					)->fetch()) && $res)
					{
						$db_res = CSocNetLogRights::getList(array(), array("LOG_ID" => $res["ID"]));
						while($res = $db_res->fetch())
							$codes[] = $res["GROUP_CODE"];
					}
					$this->canRead = $this->canAccess($userId, $codes);

					return $this->canRead;
				}
				$this->canRead = true;

				return $this->canRead;
			case "MEETING":
			case "MEETING_ITEM":
				$this->canRead = ((int)$message["FORUM_ID"] == (int)COption::getOptionInt('meeting', 'comments_forum_id', 0, SITE_ID));

				return $this->canRead;
			case "TIMEMAN_ENTRY":
				if(Loader::includeModule("timeman"))
				{
					$dbEntry = CTimeManEntry::getList(
						array(),
						array(
							"ID" => $entityId
						),
						false,
						false,
						array("ID", "USER_ID")
					);

					if ($arEntry = $dbEntry->fetch())
					{
						if ($arEntry["USER_ID"] == $userId)
						{
							$this->canRead = true;

							return $this->canRead;
						}
						else
						{
							$arManagers = CTimeMan::getUserManagers($arEntry["USER_ID"]);
							$this->canRead = in_array($userId, $arManagers);

							return $this->canRead;
						}
					}
				}
				$this->canRead = false;

				return $this->canRead;
			case "TIMEMAN_REPORT":
				if(Loader::includeModule("timeman"))
				{
					$dbReport = CTimeManReportFull::getList(
						array(),
						array(
							"ID" => $entityId
						),
						array("ID", "USER_ID")
					);

					if ($arReport = $dbReport->fetch())
					{
						if ($arReport["USER_ID"] == $userId)
						{
							$this->canRead = true;

							return $this->canRead;
						}
						else
						{
							$arManagers = CTimeMan::getUserManagers($arReport["USER_ID"]);
							$this->canRead = in_array($userId, $arManagers);

							return $this->canRead;
						}
					}
				}
				$this->canRead = false;

				return $this->canRead;
			case "WF":
				$this->canRead = false;
				if (Loader::includeModule("bizproc"))
				{
					if($this->getUser()->isAdmin() || $this->getUser()->canDoOperation('bitrix24_config'))
					{
						return true;
					}

					$currentUserId = (int) $this->getUser()->getId();
					$participants = CBPTaskService::getWorkflowParticipants($entityId);
					if (in_array($currentUserId, $participants))
					{
						$this->canRead = true;
					}
					else
					{
						$state = CBPStateService::getWorkflowStateInfo($entityId);
						if ($state && $currentUserId === (int) $state['STARTED_BY'])
							$this->canRead = true;
					}
					if (!$this->canRead && Loader::includeModule("iblock"))
					{
						$documentId = CBPStateService::GetStateDocumentId($entityId);
						$elementQuery = CIBlockElement::getList(array(), array("ID" => $documentId[2]),
							false, false, array("IBLOCK_ID"));
						$element = $elementQuery->fetch();
						if (!$element['IBLOCK_ID'])
						{
							$this->canRead = false;
						}

						$this->canRead = CIBlockElementRights::userHasRightTo($element["IBLOCK_ID"],
							$documentId[2], "element_read");
					}
				}
				return $this->canRead;
		}
		if ((!empty($topic["SOCNET_GROUP_ID"]) || !empty($topic["OWNER_ID"])) && Loader::includeModule("socialnetwork"))
		{
			if (!empty($topic["SOCNET_GROUP_ID"]))
			{
				$this->canRead = CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum") &&
					CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_GROUP, $topic["SOCNET_GROUP_ID"], "forum", "view");

				return $this->canRead;
			}
			else
			{
				$this->canRead = CSocNetFeatures::isActiveFeature(SONET_ENTITY_USER, $topic["OWNER_ID"], "forum") &&
					CSocNetFeaturesPerms::canPerformOperation($userId, SONET_ENTITY_USER, $topic["OWNER_ID"], "forum", "view");

				return $this->canRead;
			}
		}
		if($message)
		{
			$user = $this->getUser();
			if($user && $userId == $user->getId())
			{
				$userGroups = $user->getUserGroupArray();
			}
			else
			{
				$userGroups = array(2);
			}


			if(CForumUser::isAdmin($userId, $userGroups))
			{
				$this->canRead = true;

				return $this->canRead;
			}

			$perms = CForumNew::getUserPermission($message["FORUM_ID"], $userGroups);
			if($perms >= "Y")
			{
				$this->canRead = true;

				return $this->canRead;
			}
			if($perms < "E" || ($perms < "Q" && $message["APPROVED"] != "Y"))
			{
				$this->canRead = false;

				return $this->canRead;
			}

			$forum = CForumNew::getByID($message["FORUM_ID"]);
			$this->canRead = $forum["ACTIVE"] == "Y";

			return $this->canRead;
		}
	}

	$this->canRead = false;
	return $this->canRead;
}