- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/classes/general/tasknotifications.php
- Класс: CTaskNotifications
- Вызов: CTaskNotifications::setSonetLogRights
static function setSonetLogRights(array $params, array $fields, array $task): void
{
$logId = (int)$params['LOG_ID'];
$effectiveUserId = (int)$params['EFFECTIVE_USER_ID'];
if ($logId <= 0 || $effectiveUserId <= 0)
{
return;
}
// Get current rights
$currentRights = [];
$rightsResult = CSocNetLogRights::getList([], ['LOG_ID' => $logId]);
while ($right = $rightsResult->fetch())
{
$currentRights[] = $right['GROUP_CODE'];
}
// If author changes the task and author doesn't have
// access to task yet, don't give access to him.
$authorId = (isset($fields['CREATED_BY']) ? (int)$fields['CREATED_BY'] : (int)$task['CREATED_BY']);
$authorHasAccess = in_array('U'.$authorId, $currentRights, true);
$authorMustBeExcluded = ($authorId === $effectiveUserId) && !$authorHasAccess;
$taskParticipants = CTaskNotifications::getRecipientsIDs(
$fields, // Only new tasks' participiants should view log event, fixed due to http://jabber.bx/view.php?id=34504
false, // don't exclude current user
true // exclude additional recipients (because there are previous members of task)
);
$logCanViewedBy = ($authorMustBeExcluded ? array_diff($taskParticipants, [$authorId]) : $taskParticipants);
$logCanViewedBy = array_unique(array_map('intval', array_filter($logCanViewedBy)));
$newRights = CTaskNotifications::__UserIDs2Rights($logCanViewedBy);
$oldGroupId = $task['GROUP_ID'];
$newGroupId = ($fields['GROUP_ID'] ?? null);
$groupChanged = (isset($newGroupId, $oldGroupId) && $newGroupId && (int)$newGroupId !== (int)$oldGroupId);
// If rights really changed, update them
if (
$groupChanged
|| !empty(array_diff($currentRights, $newRights))
|| !empty(array_diff($newRights, $currentRights))
)
{
$groupRights = [];
if (isset($newGroupId))
{
$groupRights = self::prepareRightsCodesForViewInGroupLiveFeed($logId, $newGroupId);
}
else if (isset($oldGroupId))
{
$groupRights = self::prepareRightsCodesForViewInGroupLiveFeed($logId, $oldGroupId);
}
CSocNetLogRights::deleteByLogID($logId);
foreach ($logCanViewedBy as $userId)
{
$code = CTaskNotifications::__UserIDs2Rights([$userId]);
$follow = !UserOption::isOptionSet($task['ID'], $userId, UserOptionOption::MUTED);
CSocNetLogRights::add($logId, $code, false, $follow);
}
if (!empty($groupRights))
{
CSocNetLogRights::add($logId, $groupRights);
}
}
}