static function CanUserOperateDocumentType($operation, $userId, $documentType, $arParameters = array())
{
$documentType = trim($documentType);
if ($documentType == '')
return false;
$arParameters["IBlockId"] = intval(mb_substr($documentType, mb_strlen("iblock_")));
$arParameters['sectionId'] = !empty($arParameters['sectionId']) ? (int)$arParameters['sectionId'] : 0;
if (!array_key_exists("IBlockRightsMode", $arParameters))
$arParameters["IBlockRightsMode"] = CIBlock::GetArrayByID($arParameters["IBlockId"], "RIGHTS_MODE");
if ($arParameters["IBlockRightsMode"] === "E")
{
if ($operation === CBPCanUserOperateOperation::CreateWorkflow)
return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "iblock_rights_edit");
elseif ($operation === CBPCanUserOperateOperation::WriteDocument)
return CIBlockSectionRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["sectionId"], "section_element_bind");
elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow
|| $operation === CBPCanUserOperateOperation::StartWorkflow)
{
if (!array_key_exists("WorkflowId", $arParameters))
return false;
if ($operation === CBPCanUserOperateOperation::ViewWorkflow)
return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], 0, "element_read");
if ($operation === CBPCanUserOperateOperation::StartWorkflow)
return CIBlockSectionRights::UserHasRightTo($arParameters["IBlockId"], $arParameters['sectionId'], "section_element_bind");
$userId = intval($userId);
if (!array_key_exists("AllUserGroups", $arParameters))
{
if (!array_key_exists("UserGroups", $arParameters))
$arParameters["UserGroups"] = CUser::GetUserGroup($userId);
$arParameters["AllUserGroups"] = $arParameters["UserGroups"];
$arParameters["AllUserGroups"][] = "Author";
}
if (!array_key_exists("DocumentStates", $arParameters))
{
if ($operation === CBPCanUserOperateOperation::StartWorkflow)
$arParameters["DocumentStates"] = CBPWorkflowTemplateLoader::GetDocumentTypeStates(array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]));
else
$arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
null
);
}
if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
$arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
else
return false;
$arAllowableOperations = CBPDocument::GetAllowableOperations(
$userId,
$arParameters["AllUserGroups"],
$arParameters["DocumentStates"],
true
);
if (!is_array($arAllowableOperations))
return false;
if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $arAllowableOperations)
|| ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $arAllowableOperations))
return true;
$chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "section_element_bind";
foreach ($arAllowableOperations as $op)
{
$ar = CTask::GetOperations($op, true);
if (in_array($chop, $ar))
return true;
}
}
return false;
}
if (!array_key_exists("IBlockPermission", $arParameters))
{
if(CModule::IncludeModule('lists'))
$arParameters["IBlockPermission"] = CLists::GetIBlockPermission($arParameters["IBlockId"], $userId);
else
$arParameters["IBlockPermission"] = CIBlock::GetPermission($arParameters["IBlockId"], $userId);
}
if ($arParameters["IBlockPermission"] <= "R")
return false;
elseif ($arParameters["IBlockPermission"] >= "W")
return true;
$userId = intval($userId);
if (!array_key_exists("AllUserGroups", $arParameters))
{
if (!array_key_exists("UserGroups", $arParameters))
$arParameters["UserGroups"] = CUser::GetUserGroup($userId);
$arParameters["AllUserGroups"] = $arParameters["UserGroups"];
$arParameters["AllUserGroups"][] = "Author";
}
if (!array_key_exists("DocumentStates", $arParameters))
{
$arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(
array("iblock", "CIBlockDocument", "iblock_".$arParameters["IBlockId"]),
null
);
}
if (array_key_exists("WorkflowId", $arParameters))
{
if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"]))
$arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
else
return false;
}
$arAllowableOperations = CBPDocument::GetAllowableOperations(
$userId,
$arParameters["AllUserGroups"],
$arParameters["DocumentStates"]
);
if (!is_array($arAllowableOperations))
return false;
$r = false;
switch ($operation)
{
case CBPCanUserOperateOperation::ViewWorkflow:
$r = in_array("read", $arAllowableOperations);
break;
case CBPCanUserOperateOperation::StartWorkflow:
$r = in_array("write", $arAllowableOperations);
break;
case CBPCanUserOperateOperation::CreateWorkflow:
$r = in_array("write", $arAllowableOperations);
break;
case CBPCanUserOperateOperation::WriteDocument:
$r = in_array("write", $arAllowableOperations);
break;
case CBPCanUserOperateOperation::ReadDocument:
$r = false;
break;
default:
$r = false;
}
return $r;
}