Beispiel #1
0
 public function itDoesntAllowDuplicatedIds()
 {
     $order_representation = new OrderRepresentation();
     $order_representation->ids = array(115, 116, 115, 117);
     $order_representation->compared_to = 118;
     $this->expectException('Tuleap\\AgileDashboard\\REST\\v1\\IdsFromBodyAreNotUniqueException');
     $this->order_validator->validate($order_representation);
 }
Beispiel #2
0
 /**
  * Partial re-order of Kanban items
  *
  * Partial re-order of Kanban items
  *
  * <pre>
  * /!\ Kanban REST routes are under construction and subject to changes /!\
  * </pre>
  *
  * @url PATCH {id}/items
  *
  * @param int                                                    $id    Id of the Kanban
  * @param int                                                    $column_id Id of the column the item belongs to {@from query}
  * @param \Tuleap\AgileDashboard\REST\v1\OrderRepresentation     $order Order of the items {@from body}
  * @param \Tuleap\AgileDashboard\REST\v1\Kanban\KanbanAddRepresentation $add   Ids to add to the column {@from body}
  */
 protected function patchItems($id, $column_id, OrderRepresentation $order = null, KanbanAddRepresentation $add = null)
 {
     $current_user = UserManager::instance()->getCurrentUser();
     $kanban = $this->kanban_factory->getKanban($current_user, $id);
     if (!$this->columnIsInTracker($kanban, $current_user, $column_id)) {
         throw new RestException(404);
     }
     if ($add) {
         $add->checkFormat();
         $this->validateIdsInAddAreInKanbanTracker($kanban, $add);
         $this->resources_patcher->startTransaction();
         try {
             $this->moveArtifactsInColumn($kanban, $current_user, $add, $column_id);
             $this->resources_patcher->commit();
         } catch (Tracker_NoChangeException $exception) {
             $this->resources_patcher->rollback();
         } catch (Tracker_Workflow_GlobalRulesViolationException $exception) {
             $this->resources_patcher->rollback();
             throw new RestException(400, $exception->getMessage());
         } catch (Exception $exception) {
             $this->resources_patcher->rollback();
             throw new RestException(500, $exception->getMessage());
         }
     }
     if ($order) {
         $order->checkFormat();
         $kanban_column_items = $this->getItemsInColumn($kanban->getTrackerId(), $column_id);
         $order_validator = new OrderValidator($kanban_column_items);
         try {
             $order_validator->validate($order);
         } catch (IdsFromBodyAreNotUniqueException $exception) {
             throw new RestException(409, $exception->getMessage());
         } catch (OrderIdOutOfBoundException $exception) {
             throw new RestException(409, $exception->getMessage());
         } catch (Exception $exception) {
             throw new RestException(500, $exception->getMessage());
         }
         $this->resources_patcher->updateArtifactPriorities($order, Tracker_Artifact_PriorityHistoryChange::NO_CONTEXT, $this->getProjectIdForKanban($kanban));
     }
     if ($add || $order) {
         $this->statistics_aggregator->addCardDragAndDropHit($this->getProjectIdForKanban($kanban));
         $this->sendMessageForDroppingItem($current_user, $kanban, $order, $add, $column_id);
     }
 }
 /**
  * Partial re-order of backlog items plus update of children
  *
  * Define the priorities of some children of a given Backlog Item
  *
  * <br>
  * Example:
  * <pre>
  * "order": {
  *   "ids" : [123, 789, 1001],
  *   "direction": "before",
  *   "compared_to": 456
  * }
  * </pre>
  *
  * <br>
  * Resulting order will be: <pre>[…, 123, 789, 1001, 456, …]</pre>
  *
  * <br>
  * Add example:
  * <pre>
  * "add": [
  *   {
  *     "id": 34
  *     "remove_from": 56
  *   },
  *   ...
  * ]
  * </pre>
  *
  * <br>
  * Will remove element id 34 from 56 children and add it to current backlog_items children
  *
  * @url PATCH {id}/children
  *
  * @param int                                                   $id    Id of the Backlog Item
  * @param \Tuleap\AgileDashboard\REST\v1\OrderRepresentation    $order Order of the children {@from body}
  * @param array                                                 $add   Ids to add to backlog_items content  {@from body}
  *
  * @throws 400
  * @throws 404
  * @throws 409
  */
 protected function patch($id, OrderRepresentation $order = null, array $add = null)
 {
     $artifact = $this->getArtifact($id);
     $user = $this->getCurrentUser();
     try {
         $indexed_children_ids = $this->getChildrenArtifactIds($user, $artifact);
         if ($add) {
             $this->resources_patcher->startTransaction();
             $to_add = $this->resources_patcher->removeArtifactFromSource($user, $add);
             if (count($to_add)) {
                 $validator = new PatchAddRemoveValidator($indexed_children_ids, new PatchAddBacklogItemsValidator($this->artifact_factory, $this->tracker_factory->getPossibleChildren($artifact->getTracker()), $id));
                 $backlog_items_ids = $validator->validate($id, array(), $to_add);
                 $this->artifactlink_updater->updateArtifactLinks($user, $artifact, $backlog_items_ids, array());
                 $indexed_children_ids = array_flip($backlog_items_ids);
             }
             $this->resources_patcher->commit();
         }
         if ($order) {
             $order->checkFormat($order);
             $order_validator = new OrderValidator($indexed_children_ids);
             $order_validator->validate($order);
             $this->resources_patcher->updateArtifactPriorities($order, $id, null);
         }
     } catch (IdsFromBodyAreNotUniqueException $exception) {
         throw new RestException(409, $exception->getMessage());
     } catch (OrderIdOutOfBoundException $exception) {
         throw new RestException(409, $exception->getMessage());
     } catch (ArtifactCannotBeChildrenOfException $exception) {
         throw new RestException(409, $exception->getMessage());
     } catch (Tracker_Artifact_Exception_CannotRankWithMyself $exception) {
         throw new RestException(400, $exception->getMessage());
     } catch (\Exception $exception) {
         throw new RestException(400, $exception->getMessage());
     }
 }
 public function canOrderContent(PFUser $user, Planning_Milestone $milestone, OrderRepresentation $order)
 {
     $order_validator = new OrderValidator($this->getIndexedLinkedArtifactIds($user, $milestone));
     $order_validator->validate($order);
 }