Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions lang/ru/lib/data/module/iblock/right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
$MESS['INTERVOLGA_MIGRATO.IBLOCK_RIGHTS'] = 'Расширенные права доступа';
$MESS['INTERVOLGA_MIGRATO.TASK_NOT_FOUND'] = 'Не найдено описание права доступа';
$MESS['INTERVOLGA_MIGRATO.IBLOCK_NOT_FOUND'] = 'Не найден инфоблок';
$MESS['INTERVOLGA_MIGRATO.GROUP_NOT_FOUND'] = 'Не найдена группа пользователя';
$MESS['INTERVOLGA_MIGRATO.INVALID_IBLOCK_ID'] = 'Неверный формат ID инфоблока. ID должен быть > 0';
1 change: 1 addition & 0 deletions lib/data/module/iblock/iblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function getList(array $filter = array())
"EDIT_FILE_AFTER" => $iblock["EDIT_FILE_AFTER"],
"SECTION_PROPERTY" => $iblock["SECTION_PROPERTY"],
"WF_TYPE" => $wfMode,
"RIGHTS_MODE" => $iblock["RIGHTS_MODE"],
));
$this->addLanguageStrings($record);
$this->addFieldsSettings($record);
Expand Down
212 changes: 212 additions & 0 deletions lib/data/module/iblock/right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?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()){
$this->initIblockRights($iblock['ID']);

foreach (static::$iblockRights[$iblock['ID']] as $right){
$record = new Record($this);
$id = $this->createId($right);

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

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;
}

$this->initIblockRights($iblockId);

$obIBlockRights = new \CIBlockRights($iblockId);
$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();

$this->initIblockRights($iblockId);

$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,
]
);

$issetRight = true;
break;
}
}

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

$obIBlockRights = new \CIBlockRights($iblockId);
$obIBlockRights->setRights(static::$iblockRights[$iblockId]);

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

protected function initIblockRights($iblockId): void
{
if (!is_numeric($iblockId) || $iblockId <= 0){
throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.INVALID_IBLOCK_ID'));
}

if (!static::$iblockRights[$iblockId]){
static::$iblockRights[$iblockId] = (new \CIBlockRights($iblockId))->getRights();

if (static::$iblockRights[$iblockId]){
foreach (static::$iblockRights[$iblockId] as $i => $right){
static::$iblockRights[$iblockId][$i]["IBLOCK_ID"] = $iblockId;
}
}
}
}
}
3 changes: 2 additions & 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 Expand Up @@ -57,6 +57,7 @@ public function getList(array $filter = array())
'TITLE' => $task['TITLE'],
'DESC' => $task['DESC'],
'OPERATION' => $operations,
'BINDING' => $task['BINDING'],
));
$result[] = $record;
}
Expand Down