Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions install/public/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
<entity>
<name>adminlistoption</name>
</entity>
<entity>
<name>right</name>
</entity>
</module>
<module>
<name>highloadblock</name>
Expand Down
5 changes: 5 additions & 0 deletions lang/ru/lib/data/module/iblock/right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$MESS['INTERVOLGA_MIGRATO.IBLOCK_RIGHTS'] = 'Расширенные права доступа';
$MESS['INTERVOLGA_MIGRATO.TASK_NOT_FOUND'] = 'Не найдено описание права доступа ';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пробел в конце строки убрать

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ок

$MESS['INTERVOLGA_MIGRATO.IBLOCK_NOT_FOUND'] = 'Не найден инфоблок';
$MESS['INTERVOLGA_MIGRATO.GROUP_NOT_FOUND'] = 'Не найдена группа пользователя';
216 changes: 216 additions & 0 deletions lib/data/module/iblock/right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php namespace Intervolga\Migrato\Data\Module\Iblock;

use Bitrix\Iblock\IblockTable;
use Bitrix\Main\Loader;
use Bitrix\Main\Localization\Loc;
use Intervolga\Migrato\Data\BaseData;
use Intervolga\Migrato\Data\Link;
use Intervolga\Migrato\Data\Module\Main\Group;
use Intervolga\Migrato\Data\Module\Main\Task;
use Intervolga\Migrato\Data\Record;
use Intervolga\Migrato\Data\RecordId;
use Intervolga\Migrato\Tool\XmlIdProvider\BaseXmlIdProvider;

Loc::loadMessages(__FILE__);

class Right extends BaseData
{
const PREFIX_GROUP_CODE = 'G';

protected static array $iblockRights = [];

protected function configure()
{
Loader::includeModule('iblock');
$this->setVirtualXmlId(true); // Есть XML_ID, но при создании вручную поле NULL
$this->setEntityNameLoc(Loc::getMessage('INTERVOLGA_MIGRATO.IBLOCK_RIGHTS'));
$this->setFilesSubdir('/type/iblock/');
$this->setDependencies([
'IBLOCK' => new Link(IblocK::getInstance()),
'TASK' => new Link(Task::getInstance()),
'GROUP' => new Link(Group::getInstance()),
]);
}

public function createId($id)
{
return RecordId::createComplexId([
'IBLOCK_ID' => intval($id['IBLOCK_ID']),
'GROUP_ID' => intval(trim($id['GROUP_CODE'], static::PREFIX_GROUP_CODE)),
'ENTITY_ID' => intval($id['ENTITY_ID']),
]);
}

public function getXmlId($id)
{
$array = $id->getValue();
$iblockData = Iblock::getInstance();
$groupData = Group::getInstance();

$iblockXmlId = $iblockData->getXmlId($iblockData->createId($array['IBLOCK_ID']));
$groupId = $groupData->getXmlId($groupData->createId($array['GROUP_ID']));

$md5 = md5(serialize([
$iblockXmlId,
$groupId,
]));

return BaseXmlIdProvider::formatXmlId($md5);
}

public function getList(array $filter = [])
{
$result = [];
Loader::includeModule( 'iblock' );

$iblockIterator = IblockTable::getList([
'select' => ['ID']
]);

while ($iblock = $iblockIterator->fetch()){
$obRights = new \CIBlockRights($iblock['ID']);
$rights = $obRights->GetRights();

if (!static::$iblockRights[$iblock['ID']]){
static::$iblockRights[$iblock['ID']] = $rights;
}

foreach ($rights as $right){
$record = new \Intervolga\Migrato\Data\Record($this);
$id = $this->createId($right);

$record->setId($id);
$record->setXmlId($this->getXmlId($id));
$record->addFieldsRaw($right);

foreach ([
'IBLOCK' => [
'CLASS' => IblocK::class,
'ID' => RecordId::createNumericId($iblock['ID'])
],
'TASK' => [
'CLASS' => Task::class,
'ID' => $right['TASK_ID']
],
'GROUP' => [
'CLASS' => Group::class,
'ID' => RecordId::createNumericId(trim($right['GROUP_CODE'], static::PREFIX_GROUP_CODE))
]
] as $field => $desc)
{
$dependency = clone $this->getDependency($field);
$dependency->setValue(
$desc['CLASS']::getInstance()->getXmlId($desc['ID'])
);
$record->setDependency($field, $dependency);
}

$result[] = $record;
}
}

return $result;
}

protected function createInner(Record $record)
{
return $this->setRights($record);
}

public function update(Record $record)
{
$this->setRights($record);
}

protected function deleteInner(RecordId $id)
{
$array = $id->getValue();
$iblockId = $array['IBLOCK_ID'];

if (!$iblockId){
return;
}

$obIBlockRights = new \CIBlockRights($iblockId);

if (!static::$iblockRights[$iblockId]){
static::$iblockRights[$iblockId] = $obIBlockRights->GetRights();
}

$obIBlockRights->SetRights(static::$iblockRights[$iblockId]);
}

protected function setRights(Record $record)
{
$iblockLinkId = Iblock::getInstance()->findRecord($record->getDependency('IBLOCK')->getValue());
$groupLinkId = Group::getInstance()->findRecord($record->getDependency('GROUP')->getValue());
$taskLinkId = Task::getInstance()->findRecord($record->getDependency('TASK')->getValue());

if (!$taskLinkId){
throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.TASK_NOT_FOUND'));
}

if (!$iblockLinkId) {
throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.IBLOCK_NOT_FOUND'));
}

if (!$groupLinkId) {
throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.GROUP_NOT_FOUND'));
}

$groupId = $groupLinkId->getValue();
$taskId = $taskLinkId->getValue();
$iblockId = $iblockLinkId->getValue();

$xmlId = $this->getXmlId($this->createId([
'IBLOCK_ID' => $iblockId,
'TASK_ID' => $taskId,
'GROUP_CODE' => static::PREFIX_GROUP_CODE.$groupId,
'ENTITY_ID' => $iblockId,
]));

$obIBlockRights = new \CIBlockRights($iblockId);

if (!static::$iblockRights[$iblockId]){
static::$iblockRights[$iblockId] = $obIBlockRights->GetRights();
}

$issetRight = false;

foreach (static::$iblockRights[$iblockId] as $i => $right){
if (
$right['ENTITY_TYPE'] == 'iblock'
&& $right['GROUP_CODE'] == static::PREFIX_GROUP_CODE.$groupId
&& $right['ENTITY_ID'] == $iblockId
){
static::$iblockRights[$iblockId][$i] = array_merge(
$right,
[
'TASK_ID' => $taskId,
'XML_ID' => $xmlId,
]
);

$issetRight = true;
break;
}
}

if (!$issetRight){
static::$iblockRights[$iblockId]['n0'] = [
'TASK_ID' => $taskId,
'GROUP_CODE' => static::PREFIX_GROUP_CODE.$groupId,
'XML_ID' => $xmlId,
];
}

$obIBlockRights->SetRights(static::$iblockRights[$iblockId]);

return $this->createId([
'IBLOCK_ID' => $iblockId,
'TASK_ID' => $taskId,
'GROUP_CODE' => static::PREFIX_GROUP_CODE.$groupId,
'ENTITY_ID' => $iblockId,
]);
}
}
2 changes: 1 addition & 1 deletion lib/data/module/main/task.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function configure()

public function getList(array $filter = array())
{
$dbRes = \CTask::GetList(array(), array("BINDING" => "module"));
$dbRes = \CTask::GetList(array(), array("BINDING" => ["module", "iblock"]));

$result = array();
while ($task = $dbRes->fetch())
Expand Down