public function renderView()
 {
     $data = $this->getStoryData();
     $author_phid = $data->getAuthorPHID();
     $commit_phid = $data->getValue('commitPHID');
     $view = new PhabricatorFeedStoryView();
     $action = $data->getValue('action');
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
     $view->setTitle($this->linkTo($author_phid) . " {$verb} commit " . $this->linkTo($commit_phid) . ".");
     $view->setEpoch($data->getEpoch());
     $comments = $data->getValue('content');
     if ($comments) {
         $full_size = true;
     } else {
         $full_size = false;
     }
     if ($full_size) {
         $view->setImage($this->getHandle($author_phid)->getImageURI());
         $content = $this->renderSummary($data->getValue('content'));
         $view->appendChild($content);
     } else {
         $view->setOneLineStory(true);
     }
     return $view;
 }
 public function renderForAsanaBridge($implied_context = false)
 {
     $data = $this->getStoryData();
     $comment = $data->getValue('content');
     $author_name = $this->getHandle($this->getAuthorPHID())->getName();
     $action = $this->getValue('action');
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
     $commit_phid = $this->getPrimaryObjectPHID();
     $commit_name = $this->getHandle($commit_phid)->getFullName();
     if ($implied_context) {
         $title = "{$author_name} {$verb} this commit.";
     } else {
         $title = "{$author_name} {$verb} commit {$commit_name}.";
     }
     if (strlen($comment)) {
         $engine = PhabricatorMarkupEngine::newMarkupEngine(array())->setConfig('viewer', new PhabricatorUser())->setMode(PhutilRemarkupEngine::MODE_TEXT);
         $comment = $engine->markupText($comment);
         $title .= "\n\n";
         $title .= $comment;
     }
     return $title;
 }
 /**
  * Return a map of available audit actions for rendering into a <select />.
  * This shows the user valid actions, and does not show nonsense/invalid
  * actions (like closing an already-closed commit, or resigning from a commit
  * you have no association with).
  */
 private function getAuditActions(PhabricatorRepositoryCommit $commit, array $audit_requests)
 {
     assert_instances_of($audit_requests, 'PhabricatorRepositoryAuditRequest');
     $user = $this->getRequest()->getUser();
     $user_is_author = $commit->getAuthorPHID() == $user->getPHID();
     $user_request = null;
     foreach ($audit_requests as $audit_request) {
         if ($audit_request->getAuditorPHID() == $user->getPHID()) {
             $user_request = $audit_request;
             break;
         }
     }
     $actions = array();
     $actions[PhabricatorAuditActionConstants::COMMENT] = true;
     $actions[PhabricatorAuditActionConstants::ADD_CCS] = true;
     $actions[PhabricatorAuditActionConstants::ADD_AUDITORS] = true;
     // We allow you to accept your own commits. A use case here is that you
     // notice an issue with your own commit and "Raise Concern" as an indicator
     // to other auditors that you're on top of the issue, then later resolve it
     // and "Accept". You can not accept on behalf of projects or packages,
     // however.
     $actions[PhabricatorAuditActionConstants::ACCEPT] = true;
     $actions[PhabricatorAuditActionConstants::CONCERN] = true;
     // To resign, a user must have authority on some request and not be the
     // commit's author.
     if (!$user_is_author) {
         $may_resign = false;
         $authority_map = array_fill_keys($this->auditAuthorityPHIDs, true);
         foreach ($audit_requests as $request) {
             if (empty($authority_map[$request->getAuditorPHID()])) {
                 continue;
             }
             $may_resign = true;
             break;
         }
         // If the user has already resigned, don't show "Resign...".
         $status_resigned = PhabricatorAuditStatusConstants::RESIGNED;
         if ($user_request) {
             if ($user_request->getAuditStatus() == $status_resigned) {
                 $may_resign = false;
             }
         }
         if ($may_resign) {
             $actions[PhabricatorAuditActionConstants::RESIGN] = true;
         }
     }
     $status_concern = PhabricatorAuditCommitStatusConstants::CONCERN_RAISED;
     $concern_raised = $commit->getAuditStatus() == $status_concern;
     $can_close_option = PhabricatorEnv::getEnvConfig('audit.can-author-close-audit');
     if ($can_close_option && $user_is_author && $concern_raised) {
         $actions[PhabricatorAuditActionConstants::CLOSE] = true;
     }
     foreach ($actions as $constant => $ignored) {
         $actions[$constant] = PhabricatorAuditActionConstants::getActionName($constant);
     }
     return $actions;
 }
Пример #4
0
 private function renderActions()
 {
     $comment = $this->comment;
     $author = $this->getHandle($comment->getActorPHID());
     $author_link = $author->renderLink();
     $action = $comment->getAction();
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
     $metadata = $comment->getMetadata();
     $added_auditors = idx($metadata, PhabricatorAuditComment::METADATA_ADDED_AUDITORS, array());
     $added_ccs = idx($metadata, PhabricatorAuditComment::METADATA_ADDED_CCS, array());
     $actions = array();
     if ($action == PhabricatorAuditActionConstants::ADD_CCS) {
         $rendered_ccs = $this->renderHandleList($added_ccs);
         $actions[] = "{$author_link} added CCs: {$rendered_ccs}.";
     } else {
         if ($action == PhabricatorAuditActionConstants::ADD_AUDITORS) {
             $rendered_auditors = $this->renderHandleList($added_auditors);
             $actions[] = "{$author_link} added auditors: " . "{$rendered_auditors}.";
         } else {
             $actions[] = "{$author_link} " . phutil_escape_html($verb) . " this commit.";
         }
     }
     foreach ($actions as $key => $action) {
         $actions[$key] = '<div>' . $action . '</div>';
     }
     return $actions;
 }
 private function renderMailBody(PhabricatorAuditComment $comment, $cname, PhabricatorObjectHandle $handle, PhabricatorMailReplyHandler $reply_handler, array $inline_comments)
 {
     assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
     $commit = $this->commit;
     $user = $this->user;
     $name = $user->getUsername();
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($comment->getAction());
     $body = array();
     $body[] = "{$name} {$verb} commit {$cname}.";
     if ($comment->getContent()) {
         $body[] = $comment->getContent();
     }
     if ($inline_comments) {
         $block = array();
         $path_map = id(new DiffusionPathQuery())->withPathIDs(mpull($inline_comments, 'getPathID'))->execute();
         $path_map = ipull($path_map, 'path', 'id');
         foreach ($inline_comments as $inline) {
             $path = idx($path_map, $inline->getPathID());
             if ($path === null) {
                 continue;
             }
             $start = $inline->getLineNumber();
             $len = $inline->getLineLength();
             if ($len) {
                 $range = $start . '-' . ($start + $len);
             } else {
                 $range = $start;
             }
             $content = $inline->getContent();
             $block[] = "{$path}:{$range} {$content}";
         }
         $body[] = "INLINE COMMENTS\n  " . implode("\n  ", $block);
     }
     $body[] = "COMMIT\n  " . PhabricatorEnv::getProductionURI($handle->getURI());
     $reply_instructions = $reply_handler->getReplyHandlerInstructions();
     if ($reply_instructions) {
         $body[] = "REPLY HANDLER ACTIONS\n  " . $reply_instructions;
     }
     return implode("\n\n", $body) . "\n";
 }
 private function saveAuditComments()
 {
     $action = $this->request->getStr('action');
     $status_map = PhabricatorAuditActionConstants::getStatusNameMap();
     $status = idx($status_map, $action, null);
     if ($status === null) {
         return $this->buildStandardPageResponse(id(new AphrontErrorView())->setSeverity(AphrontErrorView::SEVERITY_ERROR)->setTitle("Action {$action} is invalid."), array('title' => 'Audit a Commit'));
     }
     id(new PhabricatorAuditComment())->setActorPHID($this->user->getPHID())->setTargetPHID($this->commitPHID)->setAction($action)->setContent($this->request->getStr('comments'))->save();
     // Update the audit status for all the relationships <commit, package>
     // where the package is owned by the user. When a user owns several
     // packages and a commit touches all of them,It should be good enough for
     // the user to approve it once to get all the relationships automatically
     // updated.
     $owned_packages = id(new PhabricatorOwnersOwner())->loadAllWhere('userPHID = %s', $this->user->getPHID());
     $owned_package_ids = mpull($owned_packages, 'getPackageID');
     $conn_r = id(new PhabricatorOwnersPackage())->establishConnection('r');
     $owned_package_phids = queryfx_all($conn_r, 'SELECT `phid` FROM %T WHERE id IN (%Ld)', id(new PhabricatorOwnersPackage())->getTableName(), $owned_package_ids);
     $owned_package_phids = ipull($owned_package_phids, 'phid');
     $relationships = id(new PhabricatorOwnersPackageCommitRelationship())->loadAllWhere('commitPHID = %s AND packagePHID IN (%Ls)', $this->commitPHID, $owned_package_phids);
     foreach ($relationships as $relationship) {
         $relationship->setAuditStatus($status);
         $relationship->save();
     }
     return id(new AphrontRedirectResponse())->setURI(sprintf('/audit/edit/?c-phid=%s&p-phid=%s', $this->commitPHID, $this->packagePHID));
 }
Пример #7
0
 private function renderActions()
 {
     $comment = $this->comment;
     $author = $this->getHandle($comment->getActorPHID());
     $author_link = $author->renderLink();
     $action = $comment->getAction();
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($action);
     $actions = array();
     $actions[] = "{$author_link} " . phutil_escape_html($verb) . " this commit.";
     foreach ($actions as $key => $action) {
         $actions[$key] = '<div>' . $action . '</div>';
     }
     return $actions;
 }