Поддержка серверов

BizprocDocument::CanUserOperateDocumentType: метод Битрикс

Постоянная ссылка: http://bxapi.ru/src/?id=272444

//    BizprocDocument::CanUserOperateDocumentType()
//    /bitrix/modules/lists/lib/bizprocdocument.php:1732

    function CanUserOperateDocumentType($operation, $userId, $documentType, $parameters = array())
    {
        $documentType = trim($documentType);
        if (strlen($documentType) <= 0)
            return false;

        if (self::isAdmin())
        {
            return true;
        }

        if(is_numeric($documentType))
            $parameters["IBlockId"] = intval($documentType);
        else
            $parameters["IBlockId"] = intval(substr($documentType, strlen("iblock_")));
        $parameters['sectionId'] = !empty($parameters['sectionId']) ? (int)$parameters['sectionId'] : 0;

        if (!array_key_exists("IBlockRightsMode", $parameters))
            $parameters["IBlockRightsMode"] = CIBlock::getArrayByID($parameters["IBlockId"], "RIGHTS_MODE");

        if ($parameters["IBlockRightsMode"] === "E")
        {
            if ($operation === CBPCanUserOperateOperation::CreateWorkflow)
                return CIBlockRights::userHasRightTo($parameters["IBlockId"], $parameters["IBlockId"], "iblock_rights_edit");
            elseif ($operation === CBPCanUserOperateOperation::WriteDocument)
                return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters["sectionId"], "section_element_bind");
            elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow
                || $operation === CBPCanUserOperateOperation::StartWorkflow)
            {
                if (!array_key_exists("WorkflowId", $parameters))
                    return false;

                if ($operation === CBPCanUserOperateOperation::ViewWorkflow)
                    return CIBlockRights::userHasRightTo($parameters["IBlockId"], 0, "element_read");

                if ($operation === CBPCanUserOperateOperation::StartWorkflow)
                    return CIBlockSectionRights::userHasRightTo($parameters["IBlockId"], $parameters['sectionId'], "section_element_bind");


                $userId = intval($userId);
                if (!array_key_exists("AllUserGroups", $parameters))
                {
                    if (!array_key_exists("UserGroups", $parameters))
                        $parameters["UserGroups"] = CUser::getUserGroup($userId);

                    $parameters["AllUserGroups"] = $parameters["UserGroups"];
                    $parameters["AllUserGroups"][] = "Author";
                }

                if (!array_key_exists("DocumentStates", $parameters))
                {
                    if ($operation === CBPCanUserOperateOperation::StartWorkflow)
                        $parameters["DocumentStates"] = CBPWorkflowTemplateLoader::getDocumentTypeStates(array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]));
                    else
                        $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
                            array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]),
                            null
                        );
                }

                if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
                    $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
                else
                    return false;

                $allowableOperations = CBPDocument::getAllowableOperations(
                    $userId,
                    $parameters["AllUserGroups"],
                    $parameters["DocumentStates"],
                    true
                );

                if (!is_array($allowableOperations))
                    return false;

                if (($operation === CBPCanUserOperateOperation::ViewWorkflow) && in_array("read", $allowableOperations)
                    || ($operation === CBPCanUserOperateOperation::StartWorkflow) && in_array("write", $allowableOperations))
                    return true;

                $chop = ($operation === CBPCanUserOperateOperation::ViewWorkflow) ? "element_read" : "section_element_bind";

                $tasks = self::getRightsTasks();
                foreach ($allowableOperations as $op)
                {
                    if (isset($tasks[$op]))
                        $op = $tasks[$op]['ID'];
                    $ar = CTask::getOperations($op, true);
                    if (in_array($chop, $ar))
                        return true;
                }
            }

            return false;
        }

        if (!array_key_exists("IBlockPermission", $parameters))
        {
            if(CModule::includeModule('lists'))
                $parameters["IBlockPermission"] = CLists::getIBlockPermission($parameters["IBlockId"], $userId);
            else
                $parameters["IBlockPermission"] = CIBlock::getPermission($parameters["IBlockId"], $userId);
        }

        if ($parameters["IBlockPermission"] <= "R")
            return false;
        elseif ($parameters["IBlockPermission"] >= "W")
            return true;

        $userId = intval($userId);
        if (!array_key_exists("AllUserGroups", $parameters))
        {
            if (!array_key_exists("UserGroups", $parameters))
                $parameters["UserGroups"] = CUser::getUserGroup($userId);

            $parameters["AllUserGroups"] = $parameters["UserGroups"];
            $parameters["AllUserGroups"][] = "Author";
        }

        if (!array_key_exists("DocumentStates", $parameters))
        {
            $parameters["DocumentStates"] = CBPDocument::getDocumentStates(
                array("lists", get_called_class(), "iblock_".$parameters["IBlockId"]),
                null
            );
        }

        if (array_key_exists("WorkflowId", $parameters))
        {
            if (array_key_exists($parameters["WorkflowId"], $parameters["DocumentStates"]))
                $parameters["DocumentStates"] = array($parameters["WorkflowId"] => $parameters["DocumentStates"][$parameters["WorkflowId"]]);
            else
                return false;
        }

        $allowableOperations = CBPDocument::getAllowableOperations(
            $userId,
            $parameters["AllUserGroups"],
            $parameters["DocumentStates"]
        );

        if (!is_array($allowableOperations))
            return false;

        $r = false;
        switch ($operation)
        {
            case CBPCanUserOperateOperation::ViewWorkflow:
                $r = in_array("read", $allowableOperations);
                break;
            case CBPCanUserOperateOperation::StartWorkflow:
                $r = in_array("write", $allowableOperations);
                break;
            case CBPCanUserOperateOperation::CreateWorkflow:
                $r = in_array("write", $allowableOperations);
                break;
            case CBPCanUserOperateOperation::WriteDocument:
                $r = in_array("write", $allowableOperations);
                break;
            case CBPCanUserOperateOperation::ReadDocument:
                $r = false;
                break;
            default:
                $r = false;
        }

        return $r;
    }

Блог разработчика

9 августа 2016 ResizeImageGet и простой водяной знак налету

Сегодня поговорим о том как проще всего воткнуть водяной знак на картинки в Битрикс. Например, на все изображения каталога.

21 июля 2016 Добавление вкладки в CRM коробки Битрикс24

В этом посте я покажу, как легко и просто добавить вкладку в сущность CRM. И не просто добавить, а вывести там свой контент.

21 июля 2016 Как просто обращаться из коробки Битрикс24 на сайт на базе Битрикс

К примеру вам хочется внутренним скриптом дернуть с сайта-магазина информацию, которая там, в свою очередь, закрыта некоторыми правами. Например, админскими. Можно конечно мутить свой REST, или иной формат общения, но проще всего воспользоваться штатным инструментом:

Текст сообщения*
Загрузить изображение