Example #1
0
 private static function getAllowedActionsArrayInternal($executiveUserId, array $arTaskData, $bmUserRoles)
 {
     $arBaseAllowedActions = self::getBaseAllowedActions();
     $arActualBaseAllowedActions = $arBaseAllowedActions[$arTaskData['REAL_STATUS']];
     // actions allowed on read-access
     $arAllowedActions = array(self::ACTION_TOGGLE_FAVORITE);
     if ($arTaskData['FAVORITE'] == 'Y') {
         $arAllowedActions[] = self::ACTION_DELETE_FAVORITE;
     } else {
         $arAllowedActions[] = self::ACTION_ADD_FAVORITE;
     }
     $mergesCount = 0;
     if (is_array($arActualBaseAllowedActions)) {
         foreach ($arActualBaseAllowedActions as $userRole => $arActions) {
             if ($userRole & $bmUserRoles) {
                 $arAllowedActions = array_merge($arAllowedActions, $arActions);
                 ++$mergesCount;
             }
         }
     }
     if ($mergesCount > 1) {
         $arAllowedActions = array_unique($arAllowedActions);
     }
     $isAdmin = CTasksTools::IsAdmin($executiveUserId) || CTasksTools::IsPortalB24Admin($executiveUserId);
     if (self::$bSocialNetworkModuleIncluded === null) {
         self::$bSocialNetworkModuleIncluded = CModule::IncludeModule('socialnetwork');
     }
     // Admin always can edit and remove, also implement rights from task group
     if (!in_array(self::ACTION_REMOVE, $arAllowedActions, true)) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         if ($isAdmin || $arTaskData['GROUP_ID'] > 0 && self::$bSocialNetworkModuleIncluded && CSocNetFeaturesPerms::CanPerformOperation($executiveUserId, SONET_ENTITY_GROUP, $arTaskData['GROUP_ID'], 'tasks', 'delete_tasks')) {
             $arAllowedActions[] = self::ACTION_REMOVE;
         }
     }
     if (!in_array(self::ACTION_EDIT, $arAllowedActions, true)) {
         /** @noinspection PhpDynamicAsStaticMethodCallInspection */
         if ($isAdmin || $arTaskData['GROUP_ID'] > 0 && self::$bSocialNetworkModuleIncluded && CSocNetFeaturesPerms::CanPerformOperation($executiveUserId, SONET_ENTITY_GROUP, $arTaskData['GROUP_ID'], 'tasks', 'edit_tasks')) {
             $arAllowedActions[] = self::ACTION_EDIT;
         }
     }
     // Precache result of slow 'in_array' function
     $bCanEdit = in_array(self::ACTION_EDIT, $arAllowedActions, true);
     // User can change deadline, if ...
     if ($isAdmin || $bCanEdit || $arTaskData['ALLOW_CHANGE_DEADLINE'] === 'Y' && self::ROLE_RESPONSIBLE & $bmUserRoles) {
         $arAllowedActions[] = self::ACTION_CHANGE_DEADLINE;
     }
     // If user can edit task, he can also add elapsed time and checklist items
     if ($isAdmin || $bCanEdit) {
         $arAllowedActions[] = self::ACTION_ELAPSED_TIME_ADD;
         $arAllowedActions[] = self::ACTION_CHECKLIST_ADD_ITEMS;
     }
     // Director can change director, and user who can edit can
     if ($isAdmin || $bCanEdit || self::ROLE_DIRECTOR & $bmUserRoles) {
         $arAllowedActions[] = self::ACTION_CHANGE_DIRECTOR;
     }
     if ($arTaskData['ALLOW_TIME_TRACKING'] === 'Y') {
         // User can do time tracking, if he is participant in the task
         if ($executiveUserId == $arTaskData['RESPONSIBLE_ID'] || !empty($arTaskData['ACCOMPLICES']) && in_array($executiveUserId, $arTaskData['ACCOMPLICES'])) {
             $arAllowedActions[] = self::ACTION_START_TIME_TRACKING;
         }
     }
     return array_values(array_unique($arAllowedActions));
 }