V
V
Vyacheslav Peregudov2014-08-12 16:25:04
API
Vyacheslav Peregudov, 2014-08-12 16:25:04

Bitrix API: does advanced management of rights to elements and sections of infoblocks through the API exist?

Due to the large number of users and sections of infoblocks to which rights must be divided among them, it became necessary to create a separate interface in the form of a matrix that allows you to switch the access mode to the corresponding section with one click. Searches on the Internet led only to the CIBlockRights, CIBlockSectionRights and CIBlockElementRights classes, the description of which was not found anywhere. Understanding these by no means independent classes seems to me a rather costly task. Please help me figure out how to add / remove the rights of a specific user to a specific section using the API?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Peregudov, 2014-08-13
@nilsrus

Found a solution. Thanks vtyrtov .
I threw a function that changes the user's rights to the section:

function chmodSectionAccess($bid, $sid, $uid, $tid, $mod){
  $bid = intval($bid); // идентификатор инфоблока
  $sid = intval($sid);  // идентификатор раздела
  $uid = intval($uid); // идентификатор пользователя
  $tid = intval($tid); // идентификатор уровня доступа
  $mod = ($mod === "Y"); // дать/убрать (Y|N) права на раздел 
  
  if ($bid > 0 && $sid > 0 && $uid > 0 && $tid > 0) {
    
// получаем текущий массив прав
    $ob = new CIBlockSectionRights($bid, $sid);
    $ar = $ob->GetRights(); 
    
    if ($mod) { 
// дополняем в массив новый элемент
      $ar["n0"] = array(
        "GROUP_CODE" =>"U" . $uid,
        "TASK_ID" => $tid,
        "XML_ID" => "API"
      );
    } else {
      // находим совпадающее со входными данными и исключаем из массива
      foreach($ar as $i => $r) {
        if ($r["GROUP_CODE"] === "U" . $uid && 
          $r["TASK_ID"] === $tid) unset($ar[$i]);
      }
    }
// записываем новые права из массива (другие не наследуемые будут удалены)
    $ob->SetRights($ar); 
    
    return true;
  } else {
    return false;
  }
}

Hope this solution helps someone.
I will be glad if you tell me an even easier way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question