- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/group_features_perms.php
- Класс: CAllSocNetFeaturesPerms
- Вызов: CAllSocNetFeaturesPerms::CanPerformOperation
static function CanPerformOperation($userID, $type, $id, $feature, $operation, $bCurrentUserIsAdmin = false)
{
global $APPLICATION, $arSocNetAllowedEntityTypes;
$arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
$userID = (int)$userID;
if ((is_array($id) && count($id) <= 0) || (!is_array($id) && $id <= 0))
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_EMPTY_ENTITY_ID"), "ERROR_EMPTY_ENTITY_ID");
return false;
}
$type = Trim($type);
if (($type == '') || !in_array($type, $arSocNetAllowedEntityTypes))
{
$APPLICATION->ThrowException(GetMessage("SONET_GF_ERROR_NO_ENTITY_TYPE"), "ERROR_EMPTY_TYPE");
return false;
}
$featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm($type, $id, $feature, $operation);
if ($type === SONET_ENTITY_GROUP)
{
$bWorkWithClosedGroups = (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") === "Y");
if (is_array($id))
{
$arGroupToGet = array();
foreach($id as $group_id)
{
if ($featureOperationPerms[$group_id] == false)
{
$arReturn[$group_id] = false;
}
else
{
$arGroupToGet[] = $group_id;
}
}
$arGroupToGet = array_unique($arGroupToGet);
$userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $arGroupToGet);
$arGroupToGet = array();
if (is_array($userRoleInGroup))
{
foreach($userRoleInGroup as $group_id => $role)
{
if ($userRoleInGroup[$group_id] == SONET_ROLES_BAN)
{
$arReturn[$group_id] = false;
}
else
{
$arGroupToGet[] = $group_id;
}
}
}
$arGroupToGet = array_unique($arGroupToGet);
if (
(is_array($arGroupToGet) && count($arGroupToGet) <= 0)
|| (!is_array($arGroupToGet) && intval($arGroupToGet) <= 0)
)
{
$arReturn = array();
foreach($id as $group_id)
{
$arReturn[$group_id] = false;
}
return $arReturn;
}
$resGroupTmp = CSocNetGroup::GetList(
array("ID" => "ASC"),
array("@ID" => $arGroupToGet),
false,
false,
array('ID', 'VISIBLE', 'CLOSED')
);
while ($arGroupTmp = $resGroupTmp->Fetch())
{
if (
$arGroupTmp["CLOSED"] === "Y"
&& !in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
)
{
if (!$bWorkWithClosedGroups)
{
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
$featureOperationPerms[$arGroupTmp["ID"]] = SONET_ROLES_OWNER;
}
if ($bCurrentUserIsAdmin)
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_ALL)
{
if ($arGroupTmp["VISIBLE"] === "N")
{
$featureOperationPerms[$arGroupTmp["ID"]] = SONET_ROLES_USER;
}
else
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
}
if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_AUTHORIZED)
{
if ($userID > 0)
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
if ($userRoleInGroup[$arGroupTmp["ID"]] == false)
{
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_MODERATOR)
{
if (in_array($userRoleInGroup[$arGroupTmp["ID"]], [SONET_ROLES_MODERATOR, SONET_ROLES_OWNER], true))
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_USER)
{
if (in_array($userRoleInGroup[$arGroupTmp["ID"]], UserToGroupTable::getRolesMember(), true))
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
if ($featureOperationPerms[$arGroupTmp["ID"]] === SONET_ROLES_OWNER)
{
if ($userRoleInGroup[$arGroupTmp["ID"]] === SONET_ROLES_OWNER)
{
$arReturn[$arGroupTmp["ID"]] = true;
continue;
}
$arReturn[$arGroupTmp["ID"]] = false;
continue;
}
}
return $arReturn ?? false;
}
// not array of groups
$id = (int)$id;
if ($featureOperationPerms == false)
{
return false;
}
$userRoleInGroup = CSocNetUserToGroup::GetUserRole($userID, $id);
if ($userRoleInGroup === SONET_ROLES_BAN)
{
return false;
}
$arGroupTmp = CSocNetGroup::GetByID($id);
if (
$arGroupTmp["CLOSED"] === "Y"
&& !in_array($operation, $arSocNetFeaturesSettings[$feature]["minoperation"])
)
{
if (!$bWorkWithClosedGroups)
{
return false;
}
$featureOperationPerms = SONET_ROLES_OWNER;
}
if ($bCurrentUserIsAdmin)
{
return true;
}
if ($featureOperationPerms === SONET_ROLES_ALL)
{
if ($arGroupTmp["VISIBLE"] === "N")
{
$featureOperationPerms = SONET_ROLES_USER;
}
else
{
return true;
}
}
if ($featureOperationPerms === SONET_ROLES_AUTHORIZED)
{
return ($userID > 0);
}
if ($userRoleInGroup == false)
{
return false;
}
if ($featureOperationPerms === SONET_ROLES_MODERATOR)
{
return (in_array($userRoleInGroup, array(SONET_ROLES_MODERATOR, SONET_ROLES_OWNER)));
}
if ($featureOperationPerms === SONET_ROLES_USER)
{
return (in_array($userRoleInGroup, UserToGroupTable::getRolesMember()));
}
if ($featureOperationPerms === SONET_ROLES_OWNER)
{
return ($userRoleInGroup === SONET_ROLES_OWNER);
}
}
else // user
{
if (is_array($id))
{
foreach($id as $entity_id)
{
if ($featureOperationPerms[$entity_id] == false)
{
$arReturn[$entity_id] = false;
continue;
}
$usersRelation = CSocNetUserRelations::GetRelation($userID, $entity_id);
if ($type == SONET_ENTITY_USER && $userID == $entity_id)
{
$arReturn[$entity_id] = true;
continue;
}
if ($bCurrentUserIsAdmin)
{
$arReturn[$entity_id] = true;
continue;
}
if ($userID == $entity_id)
{
$arReturn[$entity_id] = true;
continue;
}
if ($usersRelation == SONET_RELATIONS_BAN)
{
if (!IsModuleInstalled("im"))
{
$arReturn[$entity_id] = false;
continue;
}
}
if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_NONE)
{
$arReturn[$entity_id] = false;
continue;
}
if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_ALL)
{
$arReturn[$entity_id] = true;
continue;
}
if ($featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_AUTHORIZED)
{
$arReturn[$entity_id] = ($userID > 0);
continue;
}
if (
$featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_FRIENDS
|| $featureOperationPerms[$entity_id] == SONET_RELATIONS_TYPE_FRIENDS2
)
{
$arReturn[$entity_id] = CSocNetUserRelations::IsFriends($userID, $entity_id);
continue;
}
}
return $arReturn;
}
// not array
if ($featureOperationPerms == false)
{
return false;
}
if ($type === SONET_ENTITY_USER && $userID == $id)
{
return true;
}
if ($bCurrentUserIsAdmin)
{
return true;
}
$usersRelation = CSocNetUserRelations::GetRelation($userID, $id);
if ($usersRelation == SONET_RELATIONS_BAN && !IsModuleInstalled("im"))
{
return false;
}
if ($featureOperationPerms == SONET_RELATIONS_TYPE_NONE)
{
return false;
}
if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL)
{
return true;
}
if ($featureOperationPerms === SONET_RELATIONS_TYPE_AUTHORIZED)
{
return ($userID > 0);
}
if (
$featureOperationPerms === SONET_RELATIONS_TYPE_FRIENDS
|| $featureOperationPerms === SONET_RELATIONS_TYPE_FRIENDS2
)
{
return CSocNetUserRelations::IsFriends($userID, $id);
}
}
return false;
}