Path: blob/master/src/applications/audit/storage/PhabricatorAuditTransaction.php
12256 views
<?php12final class PhabricatorAuditTransaction3extends PhabricatorModularTransaction {45const TYPE_COMMIT = 'audit:commit';67const MAILTAG_ACTION_CONCERN = 'audit-action-concern';8const MAILTAG_ACTION_ACCEPT = 'audit-action-accept';9const MAILTAG_ACTION_RESIGN = 'audit-action-resign';10const MAILTAG_ACTION_CLOSE = 'audit-action-close';11const MAILTAG_ADD_AUDITORS = 'audit-add-auditors';12const MAILTAG_ADD_CCS = 'audit-add-ccs';13const MAILTAG_COMMENT = 'audit-comment';14const MAILTAG_COMMIT = 'audit-commit';15const MAILTAG_PROJECTS = 'audit-projects';16const MAILTAG_OTHER = 'audit-other';1718public function getApplicationName() {19return 'audit';20}2122public function getBaseTransactionClass() {23return 'DiffusionCommitTransactionType';24}2526public function getApplicationTransactionType() {27return PhabricatorRepositoryCommitPHIDType::TYPECONST;28}2930public function getApplicationTransactionCommentObject() {31return new PhabricatorAuditTransactionComment();32}3334public function getRemarkupBlocks() {35$blocks = parent::getRemarkupBlocks();3637switch ($this->getTransactionType()) {38case self::TYPE_COMMIT:39$data = $this->getNewValue();40$blocks[] = $data['description'];41break;42}4344return $blocks;45}4647public function getActionStrength() {48$type = $this->getTransactionType();4950switch ($type) {51case self::TYPE_COMMIT:52return 300;53}5455return parent::getActionStrength();56}5758public function getRequiredHandlePHIDs() {59$phids = parent::getRequiredHandlePHIDs();6061$type = $this->getTransactionType();6263switch ($type) {64case self::TYPE_COMMIT:65$phids[] = $this->getObjectPHID();66$data = $this->getNewValue();67if ($data['authorPHID']) {68$phids[] = $data['authorPHID'];69}70if ($data['committerPHID']) {71$phids[] = $data['committerPHID'];72}73break;74case PhabricatorAuditActionConstants::ADD_CCS:75case PhabricatorAuditActionConstants::ADD_AUDITORS:76$old = $this->getOldValue();77$new = $this->getNewValue();7879if (!is_array($old)) {80$old = array();81}82if (!is_array($new)) {83$new = array();84}8586foreach (array_keys($old + $new) as $phid) {87$phids[] = $phid;88}89break;90}9192return $phids;93}9495public function getActionName() {9697switch ($this->getTransactionType()) {98case PhabricatorAuditActionConstants::ACTION:99switch ($this->getNewValue()) {100case PhabricatorAuditActionConstants::CONCERN:101return pht('Raised Concern');102case PhabricatorAuditActionConstants::ACCEPT:103return pht('Accepted');104case PhabricatorAuditActionConstants::RESIGN:105return pht('Resigned');106case PhabricatorAuditActionConstants::CLOSE:107return pht('Closed');108}109break;110case PhabricatorAuditActionConstants::ADD_AUDITORS:111return pht('Added Auditors');112case self::TYPE_COMMIT:113return pht('Committed');114}115116return parent::getActionName();117}118119public function getColor() {120121$type = $this->getTransactionType();122123switch ($type) {124case PhabricatorAuditActionConstants::ACTION:125switch ($this->getNewValue()) {126case PhabricatorAuditActionConstants::CONCERN:127return 'red';128case PhabricatorAuditActionConstants::ACCEPT:129return 'green';130case PhabricatorAuditActionConstants::RESIGN:131return 'black';132case PhabricatorAuditActionConstants::CLOSE:133return 'indigo';134}135}136137return parent::getColor();138}139140public function getIcon() {141142$type = $this->getTransactionType();143144switch ($type) {145case PhabricatorAuditActionConstants::ACTION:146switch ($this->getNewValue()) {147case PhabricatorAuditActionConstants::CONCERN:148return 'fa-exclamation-circle';149case PhabricatorAuditActionConstants::ACCEPT:150return 'fa-check';151case PhabricatorAuditActionConstants::RESIGN:152return 'fa-plane';153case PhabricatorAuditActionConstants::CLOSE:154return 'fa-check';155}156}157158return parent::getIcon();159}160161public function getTitle() {162$old = $this->getOldValue();163$new = $this->getNewValue();164165$author_handle = $this->renderHandleLink($this->getAuthorPHID());166167$type = $this->getTransactionType();168169switch ($type) {170case PhabricatorAuditActionConstants::ADD_CCS:171case PhabricatorAuditActionConstants::ADD_AUDITORS:172if (!is_array($old)) {173$old = array();174}175if (!is_array($new)) {176$new = array();177}178$add = array_keys(array_diff_key($new, $old));179$rem = array_keys(array_diff_key($old, $new));180break;181}182183switch ($type) {184case self::TYPE_COMMIT:185$author = null;186if ($new['authorPHID']) {187$author = $this->renderHandleLink($new['authorPHID']);188} else {189$author = $new['authorName'];190}191192$committer = null;193if ($new['committerPHID']) {194$committer = $this->renderHandleLink($new['committerPHID']);195} else if ($new['committerName']) {196$committer = $new['committerName'];197}198199$commit = $this->renderHandleLink($this->getObjectPHID());200201if (!$committer) {202$committer = $author;203$author = null;204}205206if ($author) {207$title = pht(208'%s committed %s (authored by %s).',209$committer,210$commit,211$author);212} else {213$title = pht(214'%s committed %s.',215$committer,216$commit);217}218return $title;219220case PhabricatorAuditActionConstants::INLINE:221return pht(222'%s added inline comments.',223$author_handle);224225case PhabricatorAuditActionConstants::ADD_CCS:226if ($add && $rem) {227return pht(228'%s edited subscribers; added: %s, removed: %s.',229$author_handle,230$this->renderHandleList($add),231$this->renderHandleList($rem));232} else if ($add) {233return pht(234'%s added subscribers: %s.',235$author_handle,236$this->renderHandleList($add));237} else if ($rem) {238return pht(239'%s removed subscribers: %s.',240$author_handle,241$this->renderHandleList($rem));242} else {243return pht(244'%s added subscribers...',245$author_handle);246}247248case PhabricatorAuditActionConstants::ADD_AUDITORS:249if ($add && $rem) {250return pht(251'%s edited auditors; added: %s, removed: %s.',252$author_handle,253$this->renderHandleList($add),254$this->renderHandleList($rem));255} else if ($add) {256return pht(257'%s added auditors: %s.',258$author_handle,259$this->renderHandleList($add));260} else if ($rem) {261return pht(262'%s removed auditors: %s.',263$author_handle,264$this->renderHandleList($rem));265} else {266return pht(267'%s added auditors...',268$author_handle);269}270271case PhabricatorAuditActionConstants::ACTION:272switch ($new) {273case PhabricatorAuditActionConstants::ACCEPT:274return pht(275'%s accepted this commit.',276$author_handle);277case PhabricatorAuditActionConstants::CONCERN:278return pht(279'%s raised a concern with this commit.',280$author_handle);281case PhabricatorAuditActionConstants::RESIGN:282return pht(283'%s resigned from this audit.',284$author_handle);285case PhabricatorAuditActionConstants::CLOSE:286return pht(287'%s closed this audit.',288$author_handle);289}290291}292293return parent::getTitle();294}295296public function getTitleForFeed() {297$old = $this->getOldValue();298$new = $this->getNewValue();299300$author_handle = $this->renderHandleLink($this->getAuthorPHID());301$object_handle = $this->renderHandleLink($this->getObjectPHID());302303$type = $this->getTransactionType();304305switch ($type) {306case PhabricatorAuditActionConstants::ADD_CCS:307case PhabricatorAuditActionConstants::ADD_AUDITORS:308if (!is_array($old)) {309$old = array();310}311if (!is_array($new)) {312$new = array();313}314$add = array_keys(array_diff_key($new, $old));315$rem = array_keys(array_diff_key($old, $new));316break;317}318319switch ($type) {320case self::TYPE_COMMIT:321$author = null;322if ($new['authorPHID']) {323$author = $this->renderHandleLink($new['authorPHID']);324} else {325$author = $new['authorName'];326}327328$committer = null;329if ($new['committerPHID']) {330$committer = $this->renderHandleLink($new['committerPHID']);331} else if ($new['committerName']) {332$committer = $new['committerName'];333}334335if (!$committer) {336$committer = $author;337$author = null;338}339340if ($author) {341$title = pht(342'%s committed %s (authored by %s).',343$committer,344$object_handle,345$author);346} else {347$title = pht(348'%s committed %s.',349$committer,350$object_handle);351}352return $title;353354case PhabricatorAuditActionConstants::INLINE:355return pht(356'%s added inline comments to %s.',357$author_handle,358$object_handle);359360case PhabricatorAuditActionConstants::ADD_AUDITORS:361if ($add && $rem) {362return pht(363'%s edited auditors for %s; added: %s, removed: %s.',364$author_handle,365$object_handle,366$this->renderHandleList($add),367$this->renderHandleList($rem));368} else if ($add) {369return pht(370'%s added auditors to %s: %s.',371$author_handle,372$object_handle,373$this->renderHandleList($add));374} else if ($rem) {375return pht(376'%s removed auditors from %s: %s.',377$author_handle,378$object_handle,379$this->renderHandleList($rem));380} else {381return pht(382'%s added auditors to %s...',383$author_handle,384$object_handle);385}386387case PhabricatorAuditActionConstants::ACTION:388switch ($new) {389case PhabricatorAuditActionConstants::ACCEPT:390return pht(391'%s accepted %s.',392$author_handle,393$object_handle);394case PhabricatorAuditActionConstants::CONCERN:395return pht(396'%s raised a concern with %s.',397$author_handle,398$object_handle);399case PhabricatorAuditActionConstants::RESIGN:400return pht(401'%s resigned from auditing %s.',402$author_handle,403$object_handle);404case PhabricatorAuditActionConstants::CLOSE:405return pht(406'%s closed the audit of %s.',407$author_handle,408$object_handle);409}410411}412413return parent::getTitleForFeed();414}415416public function getBodyForFeed(PhabricatorFeedStory $story) {417switch ($this->getTransactionType()) {418case self::TYPE_COMMIT:419$data = $this->getNewValue();420return $story->renderSummary($data['summary']);421}422return parent::getBodyForFeed($story);423}424425public function isInlineCommentTransaction() {426switch ($this->getTransactionType()) {427case PhabricatorAuditActionConstants::INLINE:428return true;429}430431return parent::isInlineCommentTransaction();432}433434public function getBodyForMail() {435switch ($this->getTransactionType()) {436case self::TYPE_COMMIT:437$data = $this->getNewValue();438return $data['description'];439}440441return parent::getBodyForMail();442}443444public function getMailTags() {445$tags = array();446switch ($this->getTransactionType()) {447case DiffusionCommitAcceptTransaction::TRANSACTIONTYPE:448$tags[] = self::MAILTAG_ACTION_ACCEPT;449break;450case DiffusionCommitConcernTransaction::TRANSACTIONTYPE:451$tags[] = self::MAILTAG_ACTION_CONCERN;452break;453case DiffusionCommitResignTransaction::TRANSACTIONTYPE:454$tags[] = self::MAILTAG_ACTION_RESIGN;455break;456case DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE:457$tags[] = self::MAILTAG_ADD_AUDITORS;458break;459case PhabricatorAuditActionConstants::ACTION:460switch ($this->getNewValue()) {461case PhabricatorAuditActionConstants::CONCERN:462$tags[] = self::MAILTAG_ACTION_CONCERN;463break;464case PhabricatorAuditActionConstants::ACCEPT:465$tags[] = self::MAILTAG_ACTION_ACCEPT;466break;467case PhabricatorAuditActionConstants::RESIGN:468$tags[] = self::MAILTAG_ACTION_RESIGN;469break;470case PhabricatorAuditActionConstants::CLOSE:471$tags[] = self::MAILTAG_ACTION_CLOSE;472break;473}474break;475case PhabricatorAuditActionConstants::ADD_AUDITORS:476$tags[] = self::MAILTAG_ADD_AUDITORS;477break;478case PhabricatorAuditActionConstants::ADD_CCS:479$tags[] = self::MAILTAG_ADD_CCS;480break;481case PhabricatorAuditActionConstants::INLINE:482case PhabricatorTransactions::TYPE_COMMENT:483$tags[] = self::MAILTAG_COMMENT;484break;485case self::TYPE_COMMIT:486$tags[] = self::MAILTAG_COMMIT;487break;488case PhabricatorTransactions::TYPE_EDGE:489switch ($this->getMetadataValue('edge:type')) {490case PhabricatorProjectObjectHasProjectEdgeType::EDGECONST:491$tags[] = self::MAILTAG_PROJECTS;492break;493case PhabricatorObjectHasSubscriberEdgeType::EDGECONST:494$tags[] = self::MAILTAG_ADD_CCS;495break;496default:497$tags[] = self::MAILTAG_OTHER;498break;499}500break;501default:502$tags[] = self::MAILTAG_OTHER;503break;504}505return $tags;506}507508public function shouldDisplayGroupWith(array $group) {509// Make the "This commit now requires audit." state message stand alone.510$type_state = DiffusionCommitStateTransaction::TRANSACTIONTYPE;511512if ($this->getTransactionType() == $type_state) {513return false;514}515516foreach ($group as $xaction) {517if ($xaction->getTransactionType() == $type_state) {518return false;519}520}521522return parent::shouldDisplayGroupWith($group);523}524525}526527528