/**
  * Process the artifact functions
  *
  * @param Tracker_IDisplayTrackerLayout  $layout          Displays the page header and footer
  * @param Codendi_Request                $request         The data from the user
  * @param PFUser                           $current_user    The current user
  *
  * @return void
  */
 public function process(Tracker_IDisplayTrackerLayout $layout, $request, $current_user)
 {
     switch ($request->get('func')) {
         case 'get-children':
             $children = $this->getChildPresenterCollection($current_user);
             $GLOBALS['Response']->sendJSON($children);
             exit;
             break;
         case 'update-comment':
             if ((int) $request->get('changeset_id') && $request->exist('content')) {
                 if ($changeset = $this->getChangeset($request->get('changeset_id'))) {
                     $comment_format = $this->validateCommentFormat($request, 'comment_format');
                     $changeset->updateComment($request->get('content'), $current_user, $comment_format, $_SERVER['REQUEST_TIME']);
                     if ($request->isAjax()) {
                         //We assume that we can only change a comment from a followUp
                         echo $changeset->getComment()->fetchFollowUp();
                     }
                 }
             }
             break;
         case 'preview-attachment':
         case 'show-attachment':
             if ((int) $request->get('field') && (int) $request->get('attachment')) {
                 $ff = Tracker_FormElementFactory::instance();
                 //TODO: check that the user can read the field
                 if ($field = $ff->getFormElementByid($request->get('field'))) {
                     $method = explode('-', $request->get('func'));
                     $method = $method[0];
                     $method .= 'Attachment';
                     if (method_exists($field, $method)) {
                         $field->{$method}($request->get('attachment'));
                     }
                 }
             }
             break;
         case 'artifact-delete-changeset':
             // @see comment in Tracker_Artifact_Changeset::fetchFollowUp()
             //if ($changeset = $this->getChangeset($request->get('changeset'))) {
             //    $changeset->delete($current_user);
             //}
             $GLOBALS['Response']->redirect('?aid=' . $this->id);
             break;
         case 'artifact-update':
             $action = new Tracker_Action_UpdateArtifact($this, $this->getFormElementFactory(), $this->getEventManager());
             $action->process($layout, $request, $current_user);
             break;
         case 'check-user-can-link-and-unlink':
             $source_artifact = (int) $request->get('from-artifact');
             $destination_artifact = (int) $request->get('to-artifact');
             if (!($this->userHasRankingPermissions($source_artifact) && $this->userHasRankingPermissions($destination_artifact))) {
                 $this->sendUserDoesNotHavePermissionsErrorCode();
             }
             break;
         case 'unassociate-artifact-to':
             $artlink_fields = $this->getFormElementFactory()->getUsedArtifactLinkFields($this->getTracker());
             $linked_artifact_id = $request->get('linked-artifact-id');
             if (!$this->userHasRankingPermissions($this->getId())) {
                 $this->sendUserDoesNotHavePermissionsErrorCode();
                 break;
             }
             if (count($artlink_fields)) {
                 $this->unlinkArtifact($artlink_fields, $linked_artifact_id, $current_user);
                 $this->summonArtifactAssociators($request, $current_user, $linked_artifact_id);
             } else {
                 $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker', 'must_have_artifact_link_field'));
                 $GLOBALS['Response']->sendStatusCode(400);
             }
             break;
         case 'associate-artifact-to':
             $linked_artifact_id = $request->get('linked-artifact-id');
             if (!$this->userHasRankingPermissions($this->getId())) {
                 $this->sendUserDoesNotHavePermissionsErrorCode();
                 break;
             }
             if (!$this->linkArtifact($linked_artifact_id, $current_user)) {
                 $GLOBALS['Response']->sendStatusCode(400);
             } else {
                 $this->summonArtifactAssociators($request, $current_user, $linked_artifact_id);
             }
             break;
         case 'higher-priority-than':
             $target_id = (int) $request->get('target-id');
             $milestone_id = (int) $request->get('milestone-id');
             $project_id = $this->getProjectId();
             $user_is_authorized = $this->userHasRankingPermissions($milestone_id);
             if (!$this->userHasRankingPermissions($milestone_id)) {
                 $this->sendUserDoesNotHavePermissionsErrorCode();
                 break;
             }
             $this->getPriorityManager()->moveArtifactBeforeWithHistoryChangeLogging($this->getId(), $target_id, $milestone_id, $project_id);
             break;
         case 'lesser-priority-than':
             $target_id = (int) $request->get('target-id');
             $milestone_id = (int) $request->get('milestone-id');
             $project_id = $this->getProjectId();
             if (!$this->userHasRankingPermissions($milestone_id)) {
                 $this->sendUserDoesNotHavePermissionsErrorCode();
                 break;
             }
             $this->getPriorityManager()->moveArtifactAfterWithHistoryChangeLogging($this->getId(), $target_id, $milestone_id, $project_id);
             break;
         case 'show-in-overlay':
             $renderer = new Tracker_Artifact_EditOverlayRenderer($this, $this->getEventManager());
             $renderer->display($request, $current_user);
             break;
         case 'get-new-changesets':
             $changeset_id = $request->getValidated('changeset_id', 'uint', 0);
             $changeset_factory = $this->getChangesetFactory();
             $GLOBALS['Response']->sendJSON($changeset_factory->getNewChangesetsFormattedForJson($this, $changeset_id));
             break;
         case 'edit':
             $GLOBALS['Response']->redirect($this->getUri());
             break;
         case 'get-edit-in-place':
             $renderer = new Tracker_Artifact_Renderer_EditInPlaceRenderer($this, $this->getMustacheRenderer());
             $renderer->display($current_user, $request);
             break;
         case 'update-in-place':
             $renderer = new Tracker_Artifact_Renderer_EditInPlaceRenderer($this, $this->getMustacheRenderer());
             $renderer->updateArtifact($request, $current_user);
             break;
         case 'copy-artifact':
             $art_link = $this->fetchDirectLinkToArtifact();
             $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_tracker_artifact', 'copy_mode_info', array($art_link)), CODENDI_PURIFIER_LIGHT);
             $renderer = new Tracker_Artifact_CopyRenderer($this->getEventManager(), $this, $this->getFormElementFactory(), $layout);
             $renderer->display($request, $current_user);
             break;
         case 'manage-subscription':
             $artifact_subscriber = new Tracker_ArtifactNotificationSubscriber($this, $this->getDao());
             if ($this->doesUserHaveUnsubscribedFromNotification($current_user)) {
                 $artifact_subscriber->subscribeUser($current_user, $request);
                 break;
             }
             $artifact_subscriber->unsubscribeUser($current_user, $request);
             break;
         default:
             if ($request->isAjax()) {
                 echo $this->fetchTooltip($current_user);
             } else {
                 $renderer = new Tracker_Artifact_ReadOnlyRenderer($this->getEventManager(), $this, $this->getFormElementFactory(), $layout);
                 $renderer->display($request, $current_user);
             }
             break;
     }
 }
 public function itUnsubscribeUser()
 {
     stub($this->artifact)->userCanView($this->user)->returns(true);
     expect($this->artifact_dao)->createUnsubscribeNotification(201, 101)->once();
     $this->artifact_subscriber->unsubscribeUser($this->user, $this->request);
 }