@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update Passphrase for modular transactions

Summary: Updates Passphrase for modular transactions.

Test Plan: Create, edit, lock, view, lots of different types of Passphrases. Enable Conduit, Lock Passphrases, Destroy Secrets from the interface and verify from the DB it was eradicated.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17824

+489 -306
+19 -1
src/__phutil_library_map__.php
··· 1762 1762 'PassphraseCredential' => 'applications/passphrase/storage/PassphraseCredential.php', 1763 1763 'PassphraseCredentialAuthorPolicyRule' => 'applications/passphrase/policyrule/PassphraseCredentialAuthorPolicyRule.php', 1764 1764 'PassphraseCredentialConduitController' => 'applications/passphrase/controller/PassphraseCredentialConduitController.php', 1765 + 'PassphraseCredentialConduitTransaction' => 'applications/passphrase/xaction/PassphraseCredentialConduitTransaction.php', 1765 1766 'PassphraseCredentialControl' => 'applications/passphrase/view/PassphraseCredentialControl.php', 1766 1767 'PassphraseCredentialCreateController' => 'applications/passphrase/controller/PassphraseCredentialCreateController.php', 1768 + 'PassphraseCredentialDescriptionTransaction' => 'applications/passphrase/xaction/PassphraseCredentialDescriptionTransaction.php', 1767 1769 'PassphraseCredentialDestroyController' => 'applications/passphrase/controller/PassphraseCredentialDestroyController.php', 1770 + 'PassphraseCredentialDestroyTransaction' => 'applications/passphrase/xaction/PassphraseCredentialDestroyTransaction.php', 1768 1771 'PassphraseCredentialEditController' => 'applications/passphrase/controller/PassphraseCredentialEditController.php', 1769 1772 'PassphraseCredentialFulltextEngine' => 'applications/passphrase/search/PassphraseCredentialFulltextEngine.php', 1770 1773 'PassphraseCredentialListController' => 'applications/passphrase/controller/PassphraseCredentialListController.php', 1771 1774 'PassphraseCredentialLockController' => 'applications/passphrase/controller/PassphraseCredentialLockController.php', 1775 + 'PassphraseCredentialLockTransaction' => 'applications/passphrase/xaction/PassphraseCredentialLockTransaction.php', 1776 + 'PassphraseCredentialLookedAtTransaction' => 'applications/passphrase/xaction/PassphraseCredentialLookedAtTransaction.php', 1777 + 'PassphraseCredentialNameTransaction' => 'applications/passphrase/xaction/PassphraseCredentialNameTransaction.php', 1772 1778 'PassphraseCredentialPHIDType' => 'applications/passphrase/phid/PassphraseCredentialPHIDType.php', 1773 1779 'PassphraseCredentialPublicController' => 'applications/passphrase/controller/PassphraseCredentialPublicController.php', 1774 1780 'PassphraseCredentialQuery' => 'applications/passphrase/query/PassphraseCredentialQuery.php', 1775 1781 'PassphraseCredentialRevealController' => 'applications/passphrase/controller/PassphraseCredentialRevealController.php', 1776 1782 'PassphraseCredentialSearchEngine' => 'applications/passphrase/query/PassphraseCredentialSearchEngine.php', 1783 + 'PassphraseCredentialSecretIDTransaction' => 'applications/passphrase/xaction/PassphraseCredentialSecretIDTransaction.php', 1777 1784 'PassphraseCredentialTransaction' => 'applications/passphrase/storage/PassphraseCredentialTransaction.php', 1778 1785 'PassphraseCredentialTransactionEditor' => 'applications/passphrase/editor/PassphraseCredentialTransactionEditor.php', 1779 1786 'PassphraseCredentialTransactionQuery' => 'applications/passphrase/query/PassphraseCredentialTransactionQuery.php', 1787 + 'PassphraseCredentialTransactionType' => 'applications/passphrase/xaction/PassphraseCredentialTransactionType.php', 1780 1788 'PassphraseCredentialType' => 'applications/passphrase/credentialtype/PassphraseCredentialType.php', 1781 1789 'PassphraseCredentialTypeTestCase' => 'applications/passphrase/credentialtype/__tests__/PassphraseCredentialTypeTestCase.php', 1790 + 'PassphraseCredentialUsernameTransaction' => 'applications/passphrase/xaction/PassphraseCredentialUsernameTransaction.php', 1782 1791 'PassphraseCredentialViewController' => 'applications/passphrase/controller/PassphraseCredentialViewController.php', 1783 1792 'PassphraseDAO' => 'applications/passphrase/storage/PassphraseDAO.php', 1784 1793 'PassphraseDefaultEditCapability' => 'applications/passphrase/capability/PassphraseDefaultEditCapability.php', ··· 6801 6810 ), 6802 6811 'PassphraseCredentialAuthorPolicyRule' => 'PhabricatorPolicyRule', 6803 6812 'PassphraseCredentialConduitController' => 'PassphraseController', 6813 + 'PassphraseCredentialConduitTransaction' => 'PassphraseCredentialTransactionType', 6804 6814 'PassphraseCredentialControl' => 'AphrontFormControl', 6805 6815 'PassphraseCredentialCreateController' => 'PassphraseController', 6816 + 'PassphraseCredentialDescriptionTransaction' => 'PassphraseCredentialTransactionType', 6806 6817 'PassphraseCredentialDestroyController' => 'PassphraseController', 6818 + 'PassphraseCredentialDestroyTransaction' => 'PassphraseCredentialTransactionType', 6807 6819 'PassphraseCredentialEditController' => 'PassphraseController', 6808 6820 'PassphraseCredentialFulltextEngine' => 'PhabricatorFulltextEngine', 6809 6821 'PassphraseCredentialListController' => 'PassphraseController', 6810 6822 'PassphraseCredentialLockController' => 'PassphraseController', 6823 + 'PassphraseCredentialLockTransaction' => 'PassphraseCredentialTransactionType', 6824 + 'PassphraseCredentialLookedAtTransaction' => 'PassphraseCredentialTransactionType', 6825 + 'PassphraseCredentialNameTransaction' => 'PassphraseCredentialTransactionType', 6811 6826 'PassphraseCredentialPHIDType' => 'PhabricatorPHIDType', 6812 6827 'PassphraseCredentialPublicController' => 'PassphraseController', 6813 6828 'PassphraseCredentialQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 6814 6829 'PassphraseCredentialRevealController' => 'PassphraseController', 6815 6830 'PassphraseCredentialSearchEngine' => 'PhabricatorApplicationSearchEngine', 6816 - 'PassphraseCredentialTransaction' => 'PhabricatorApplicationTransaction', 6831 + 'PassphraseCredentialSecretIDTransaction' => 'PassphraseCredentialTransactionType', 6832 + 'PassphraseCredentialTransaction' => 'PhabricatorModularTransaction', 6817 6833 'PassphraseCredentialTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 6818 6834 'PassphraseCredentialTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 6835 + 'PassphraseCredentialTransactionType' => 'PhabricatorModularTransactionType', 6819 6836 'PassphraseCredentialType' => 'Phobject', 6820 6837 'PassphraseCredentialTypeTestCase' => 'PhabricatorTestCase', 6838 + 'PassphraseCredentialUsernameTransaction' => 'PassphraseCredentialTransactionType', 6821 6839 'PassphraseCredentialViewController' => 'PassphraseController', 6822 6840 'PassphraseDAO' => 'PhabricatorLiskDAO', 6823 6841 'PassphraseDefaultEditCapability' => 'PhabricatorPolicyCapability',
+2 -1
src/applications/passphrase/controller/PassphraseCredentialConduitController.php
··· 50 50 $xactions = array(); 51 51 52 52 $xactions[] = id(new PassphraseCredentialTransaction()) 53 - ->setTransactionType(PassphraseCredentialTransaction::TYPE_CONDUIT) 53 + ->setTransactionType( 54 + PassphraseCredentialConduitTransaction::TRANSACTIONTYPE) 54 55 ->setNewValue(!$credential->getAllowConduit()); 55 56 56 57 $editor = id(new PassphraseCredentialTransactionEditor())
+2 -1
src/applications/passphrase/controller/PassphraseCredentialDestroyController.php
··· 32 32 33 33 $xactions = array(); 34 34 $xactions[] = id(new PassphraseCredentialTransaction()) 35 - ->setTransactionType(PassphraseCredentialTransaction::TYPE_DESTROY) 35 + ->setTransactionType( 36 + PassphraseCredentialDestroyTransaction::TRANSACTIONTYPE) 36 37 ->setNewValue(1); 37 38 38 39 $editor = id(new PassphraseCredentialTransactionEditor())
+13 -6
src/applications/passphrase/controller/PassphraseCredentialEditController.php
··· 117 117 } 118 118 119 119 if (!$errors) { 120 - $type_name = PassphraseCredentialTransaction::TYPE_NAME; 121 - $type_desc = PassphraseCredentialTransaction::TYPE_DESCRIPTION; 122 - $type_username = PassphraseCredentialTransaction::TYPE_USERNAME; 123 - $type_destroy = PassphraseCredentialTransaction::TYPE_DESTROY; 124 - $type_secret_id = PassphraseCredentialTransaction::TYPE_SECRET_ID; 125 - $type_is_locked = PassphraseCredentialTransaction::TYPE_LOCK; 120 + $type_name = 121 + PassphraseCredentialNameTransaction::TRANSACTIONTYPE; 122 + $type_desc = 123 + PassphraseCredentialDescriptionTransaction::TRANSACTIONTYPE; 124 + $type_username = 125 + PassphraseCredentialUsernameTransaction::TRANSACTIONTYPE; 126 + $type_destroy = 127 + PassphraseCredentialDestroyTransaction::TRANSACTIONTYPE; 128 + $type_secret_id = 129 + PassphraseCredentialSecretIDTransaction::TRANSACTIONTYPE; 130 + $type_is_locked = 131 + PassphraseCredentialLockTransaction::TRANSACTIONTYPE; 132 + 126 133 $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; 127 134 $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; 128 135 $type_space = PhabricatorTransactions::TYPE_SPACE;
+4 -2
src/applications/passphrase/controller/PassphraseCredentialLockController.php
··· 40 40 $xactions = array(); 41 41 42 42 $xactions[] = id(new PassphraseCredentialTransaction()) 43 - ->setTransactionType(PassphraseCredentialTransaction::TYPE_CONDUIT) 43 + ->setTransactionType( 44 + PassphraseCredentialConduitTransaction::TRANSACTIONTYPE) 44 45 ->setNewValue(0); 45 46 46 47 $xactions[] = id(new PassphraseCredentialTransaction()) 47 - ->setTransactionType(PassphraseCredentialTransaction::TYPE_LOCK) 48 + ->setTransactionType( 49 + PassphraseCredentialLockTransaction::TRANSACTIONTYPE) 48 50 ->setNewValue(1); 49 51 50 52 $editor = id(new PassphraseCredentialTransactionEditor())
+1 -1
src/applications/passphrase/controller/PassphraseCredentialRevealController.php
··· 67 67 ->setDisableWorkflowOnCancel(true) 68 68 ->addCancelButton($view_uri, pht('Done')); 69 69 70 - $type_secret = PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET; 70 + $type_secret = PassphraseCredentialLookedAtTransaction::TRANSACTIONTYPE; 71 71 $xactions = array( 72 72 id(new PassphraseCredentialTransaction()) 73 73 ->setTransactionType($type_secret)
+4 -174
src/applications/passphrase/editor/PassphraseCredentialTransactionEditor.php
··· 17 17 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 18 18 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 19 19 20 - $types[] = PassphraseCredentialTransaction::TYPE_NAME; 21 - $types[] = PassphraseCredentialTransaction::TYPE_DESCRIPTION; 22 - $types[] = PassphraseCredentialTransaction::TYPE_USERNAME; 23 - $types[] = PassphraseCredentialTransaction::TYPE_SECRET_ID; 24 - $types[] = PassphraseCredentialTransaction::TYPE_DESTROY; 25 - $types[] = PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET; 26 - $types[] = PassphraseCredentialTransaction::TYPE_LOCK; 27 - $types[] = PassphraseCredentialTransaction::TYPE_CONDUIT; 28 - 29 20 return $types; 30 21 } 31 22 32 - protected function getCustomTransactionOldValue( 33 - PhabricatorLiskDAO $object, 34 - PhabricatorApplicationTransaction $xaction) { 35 - switch ($xaction->getTransactionType()) { 36 - case PassphraseCredentialTransaction::TYPE_NAME: 37 - if ($this->getIsNewObject()) { 38 - return null; 39 - } 40 - return $object->getName(); 41 - case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 42 - return $object->getDescription(); 43 - case PassphraseCredentialTransaction::TYPE_USERNAME: 44 - return $object->getUsername(); 45 - case PassphraseCredentialTransaction::TYPE_SECRET_ID: 46 - return $object->getSecretID(); 47 - case PassphraseCredentialTransaction::TYPE_DESTROY: 48 - return (int)$object->getIsDestroyed(); 49 - case PassphraseCredentialTransaction::TYPE_LOCK: 50 - return (int)$object->getIsLocked(); 51 - case PassphraseCredentialTransaction::TYPE_CONDUIT: 52 - return (int)$object->getAllowConduit(); 53 - case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 54 - return null; 55 - } 56 - 57 - return parent::getCustomTransactionOldValue($object, $xaction); 58 - } 59 - 60 - protected function getCustomTransactionNewValue( 61 - PhabricatorLiskDAO $object, 62 - PhabricatorApplicationTransaction $xaction) { 63 - switch ($xaction->getTransactionType()) { 64 - case PassphraseCredentialTransaction::TYPE_NAME: 65 - case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 66 - case PassphraseCredentialTransaction::TYPE_USERNAME: 67 - case PassphraseCredentialTransaction::TYPE_SECRET_ID: 68 - case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 69 - return $xaction->getNewValue(); 70 - case PassphraseCredentialTransaction::TYPE_DESTROY: 71 - case PassphraseCredentialTransaction::TYPE_LOCK: 72 - return (int)$xaction->getNewValue(); 73 - case PassphraseCredentialTransaction::TYPE_CONDUIT: 74 - return (int)$xaction->getNewValue(); 75 - } 76 - return parent::getCustomTransactionNewValue($object, $xaction); 77 - } 78 - 79 - protected function applyCustomInternalTransaction( 80 - PhabricatorLiskDAO $object, 81 - PhabricatorApplicationTransaction $xaction) { 82 - switch ($xaction->getTransactionType()) { 83 - case PassphraseCredentialTransaction::TYPE_NAME: 84 - $object->setName($xaction->getNewValue()); 85 - return; 86 - case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 87 - $object->setDescription($xaction->getNewValue()); 88 - return; 89 - case PassphraseCredentialTransaction::TYPE_USERNAME: 90 - $object->setUsername($xaction->getNewValue()); 91 - return; 92 - case PassphraseCredentialTransaction::TYPE_SECRET_ID: 93 - $old_id = $object->getSecretID(); 94 - if ($old_id) { 95 - $this->destroySecret($old_id); 96 - } 97 - $object->setSecretID($xaction->getNewValue()); 98 - return; 99 - case PassphraseCredentialTransaction::TYPE_DESTROY: 100 - // When destroying a credential, wipe out its secret. 101 - $is_destroyed = $xaction->getNewValue(); 102 - $object->setIsDestroyed($is_destroyed); 103 - if ($is_destroyed) { 104 - $secret_id = $object->getSecretID(); 105 - if ($secret_id) { 106 - $this->destroySecret($secret_id); 107 - $object->setSecretID(null); 108 - } 109 - } 110 - return; 111 - case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 112 - return; 113 - case PassphraseCredentialTransaction::TYPE_LOCK: 114 - $object->setIsLocked((int)$xaction->getNewValue()); 115 - return; 116 - case PassphraseCredentialTransaction::TYPE_CONDUIT: 117 - $object->setAllowConduit((int)$xaction->getNewValue()); 118 - return; 119 - } 120 - 121 - return parent::applyCustomInternalTransaction($object, $xaction); 23 + public function getCreateObjectTitle($author, $object) { 24 + return pht('%s created this credential.', $author); 122 25 } 123 26 124 - protected function applyCustomExternalTransaction( 125 - PhabricatorLiskDAO $object, 126 - PhabricatorApplicationTransaction $xaction) { 127 - 128 - switch ($xaction->getTransactionType()) { 129 - case PassphraseCredentialTransaction::TYPE_NAME: 130 - case PassphraseCredentialTransaction::TYPE_DESCRIPTION: 131 - case PassphraseCredentialTransaction::TYPE_USERNAME: 132 - case PassphraseCredentialTransaction::TYPE_SECRET_ID: 133 - case PassphraseCredentialTransaction::TYPE_DESTROY: 134 - case PassphraseCredentialTransaction::TYPE_LOOKEDATSECRET: 135 - case PassphraseCredentialTransaction::TYPE_LOCK: 136 - case PassphraseCredentialTransaction::TYPE_CONDUIT: 137 - return; 138 - } 139 - 140 - return parent::applyCustomExternalTransaction($object, $xaction); 141 - } 142 - 143 - private function destroySecret($secret_id) { 144 - $table = new PassphraseSecret(); 145 - queryfx( 146 - $table->establishConnection('w'), 147 - 'DELETE FROM %T WHERE id = %d', 148 - $table->getTableName(), 149 - $secret_id); 150 - } 151 - 152 - protected function validateTransaction( 153 - PhabricatorLiskDAO $object, 154 - $type, 155 - array $xactions) { 156 - 157 - $errors = parent::validateTransaction($object, $type, $xactions); 158 - 159 - switch ($type) { 160 - case PassphraseCredentialTransaction::TYPE_NAME: 161 - $missing = $this->validateIsEmptyTextField( 162 - $object->getName(), 163 - $xactions); 164 - 165 - if ($missing) { 166 - $error = new PhabricatorApplicationTransactionValidationError( 167 - $type, 168 - pht('Required'), 169 - pht('Credential name is required.'), 170 - nonempty(last($xactions), null)); 171 - 172 - $error->setIsMissingFieldError(true); 173 - $errors[] = $error; 174 - } 175 - break; 176 - case PassphraseCredentialTransaction::TYPE_USERNAME: 177 - $credential_type = $object->getImplementation(); 178 - if (!$credential_type->shouldRequireUsername()) { 179 - break; 180 - } 181 - $missing = $this->validateIsEmptyTextField( 182 - $object->getUsername(), 183 - $xactions); 184 - 185 - if ($missing) { 186 - $error = new PhabricatorApplicationTransactionValidationError( 187 - $type, 188 - pht('Required'), 189 - pht('Username is required.'), 190 - nonempty(last($xactions), null)); 191 - 192 - $error->setIsMissingFieldError(true); 193 - $errors[] = $error; 194 - } 195 - break; 196 - } 197 - 198 - return $errors; 27 + public function getCreateObjectTitleForFeed($author, $object) { 28 + return pht('%s created %s.', $author, $object); 199 29 } 200 30 201 31 protected function supportsSearch() {
+3 -120
src/applications/passphrase/storage/PassphraseCredentialTransaction.php
··· 1 1 <?php 2 2 3 3 final class PassphraseCredentialTransaction 4 - extends PhabricatorApplicationTransaction { 5 - 6 - const TYPE_NAME = 'passphrase:name'; 7 - const TYPE_DESCRIPTION = 'passphrase:description'; 8 - const TYPE_USERNAME = 'passphrase:username'; 9 - const TYPE_SECRET_ID = 'passphrase:secretID'; 10 - const TYPE_DESTROY = 'passphrase:destroy'; 11 - const TYPE_LOOKEDATSECRET = 'passphrase:lookedAtSecret'; 12 - const TYPE_LOCK = 'passphrase:lock'; 13 - const TYPE_CONDUIT = 'passphrase:conduit'; 4 + extends PhabricatorModularTransaction { 14 5 15 6 public function getApplicationName() { 16 7 return 'passphrase'; ··· 24 15 return null; 25 16 } 26 17 27 - public function shouldHide() { 28 - $old = $this->getOldValue(); 29 - $new = $this->getNewValue(); 30 - switch ($this->getTransactionType()) { 31 - case self::TYPE_DESCRIPTION: 32 - return ($old === null); 33 - case self::TYPE_LOCK: 34 - return ($old === null); 35 - case self::TYPE_USERNAME: 36 - return !strlen($old); 37 - case self::TYPE_LOOKEDATSECRET: 38 - return false; 39 - case self::TYPE_DESTROY: 40 - // Don't show "undestroy" transactions because they're a bit confusing 41 - // and redundant with restoring a secret. 42 - if (!$new) { 43 - return true; 44 - } 45 - } 46 - return parent::shouldHide(); 47 - } 48 - 49 - public function getTitle() { 50 - $old = $this->getOldValue(); 51 - $new = $this->getNewValue(); 52 - $author_phid = $this->getAuthorPHID(); 53 - 54 - switch ($this->getTransactionType()) { 55 - case self::TYPE_NAME: 56 - if ($old === null) { 57 - return pht( 58 - '%s created this credential.', 59 - $this->renderHandleLink($author_phid)); 60 - } else { 61 - return pht( 62 - '%s renamed this credential from "%s" to "%s".', 63 - $this->renderHandleLink($author_phid), 64 - $old, 65 - $new); 66 - } 67 - break; 68 - case self::TYPE_DESCRIPTION: 69 - return pht( 70 - '%s updated the description for this credential.', 71 - $this->renderHandleLink($author_phid)); 72 - case self::TYPE_USERNAME: 73 - if (strlen($old)) { 74 - return pht( 75 - '%s changed the username for this credential from "%s" to "%s".', 76 - $this->renderHandleLink($author_phid), 77 - $old, 78 - $new); 79 - } else { 80 - return pht( 81 - '%s set the username for this credential to "%s".', 82 - $this->renderHandleLink($author_phid), 83 - $new); 84 - } 85 - break; 86 - case self::TYPE_SECRET_ID: 87 - if ($old === null) { 88 - return pht( 89 - '%s attached a new secret to this credential.', 90 - $this->renderHandleLink($author_phid)); 91 - } else { 92 - return pht( 93 - '%s updated the secret for this credential.', 94 - $this->renderHandleLink($author_phid)); 95 - } 96 - case self::TYPE_DESTROY: 97 - return pht( 98 - '%s destroyed the secret for this credential.', 99 - $this->renderHandleLink($author_phid)); 100 - case self::TYPE_LOOKEDATSECRET: 101 - return pht( 102 - '%s examined the secret plaintext for this credential.', 103 - $this->renderHandleLink($author_phid)); 104 - case self::TYPE_LOCK: 105 - return pht( 106 - '%s locked this credential.', 107 - $this->renderHandleLink($author_phid)); 108 - case self::TYPE_CONDUIT: 109 - if ($old) { 110 - return pht( 111 - '%s disallowed Conduit API access to this credential.', 112 - $this->renderHandleLink($author_phid)); 113 - } else { 114 - return pht( 115 - '%s allowed Conduit API access to this credential.', 116 - $this->renderHandleLink($author_phid)); 117 - } 118 - break; 119 - } 120 - 121 - return parent::getTitle(); 122 - } 123 - 124 - public function hasChangeDetails() { 125 - switch ($this->getTransactionType()) { 126 - case self::TYPE_DESCRIPTION: 127 - return true; 128 - } 129 - return parent::hasChangeDetails(); 130 - } 131 - 132 - public function renderChangeDetails(PhabricatorUser $viewer) { 133 - return $this->renderTextCorpusChangeDetails( 134 - $viewer, 135 - json_encode($this->getOldValue()), 136 - json_encode($this->getNewValue())); 18 + public function getBaseTransactionClass() { 19 + return 'PassphraseCredentialTransactionType'; 137 20 } 138 21 139 22 }
+53
src/applications/passphrase/xaction/PassphraseCredentialConduitTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialConduitTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:conduit'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getAllowConduit(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setAllowConduit((int)$value); 14 + } 15 + 16 + public function getTitle() { 17 + $new = $this->getNewValue(); 18 + if ($new) { 19 + return pht( 20 + '%s allowed Conduit API access to this credential.', 21 + $this->renderAuthor()); 22 + } else { 23 + return pht( 24 + '%s disallowed Conduit API access to this credential.', 25 + $this->renderAuthor()); 26 + } 27 + } 28 + 29 + public function getTitleForFeed() { 30 + $new = $this->getNewValue(); 31 + if ($new) { 32 + return pht( 33 + '%s allowed Conduit API access to credential %s.', 34 + $this->renderAuthor(), 35 + $this->renderObject()); 36 + } else { 37 + return pht( 38 + '%s disallowed Conduit API access to credential %s.', 39 + $this->renderAuthor(), 40 + $this->renderObject()); 41 + } 42 + } 43 + 44 + public function getIcon() { 45 + $new = $this->getNewValue(); 46 + if ($new) { 47 + return 'fa-tty'; 48 + } else { 49 + return 'fa-ban'; 50 + } 51 + } 52 + 53 + }
+64
src/applications/passphrase/xaction/PassphraseCredentialDescriptionTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialDescriptionTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:description'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getDescription(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setDescription($value); 14 + } 15 + 16 + public function shouldHide() { 17 + $old = $this->getOldValue(); 18 + if (!strlen($old)) { 19 + return true; 20 + } 21 + return false; 22 + } 23 + 24 + public function getTitle() { 25 + return pht( 26 + '%s updated the description for this credential.', 27 + $this->renderAuthor()); 28 + } 29 + 30 + public function getTitleForFeed() { 31 + return pht( 32 + '%s updated the description for credential %s.', 33 + $this->renderAuthor(), 34 + $this->renderObject()); 35 + } 36 + 37 + public function hasChangeDetailView() { 38 + return true; 39 + } 40 + 41 + public function getMailDiffSectionHeader() { 42 + return pht('CHANGES TO CREDENTIAL DESCRIPTION'); 43 + } 44 + 45 + public function newChangeDetailView() { 46 + $viewer = $this->getViewer(); 47 + 48 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 49 + ->setViewer($viewer) 50 + ->setOldText($this->getOldValue()) 51 + ->setNewText($this->getNewValue()); 52 + } 53 + 54 + public function newRemarkupChanges() { 55 + $changes = array(); 56 + 57 + $changes[] = $this->newRemarkupChange() 58 + ->setOldValue($this->getOldValue()) 59 + ->setNewValue($this->getNewValue()); 60 + 61 + return $changes; 62 + } 63 + 64 + }
+52
src/applications/passphrase/xaction/PassphraseCredentialDestroyTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialDestroyTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:destroy'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getIsDestroyed(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $is_destroyed = $value; 14 + $object->setIsDestroyed($is_destroyed); 15 + if ($is_destroyed) { 16 + $secret_id = $object->getSecretID(); 17 + if ($secret_id) { 18 + $this->destroySecret($secret_id); 19 + $object->setSecretID(null); 20 + } 21 + } 22 + } 23 + 24 + public function shouldHide() { 25 + $new = $this->getNewValue(); 26 + if (!$new) { 27 + return true; 28 + } 29 + } 30 + 31 + public function getTitle() { 32 + return pht( 33 + '%s destroyed the secret for this credential.', 34 + $this->renderAuthor()); 35 + } 36 + 37 + public function getTitleForFeed() { 38 + return pht( 39 + '%s destroyed the secret for credential %s.', 40 + $this->renderAuthor(), 41 + $this->renderObject()); 42 + } 43 + 44 + public function getIcon() { 45 + return 'fa-ban'; 46 + } 47 + 48 + public function getColor() { 49 + return 'red'; 50 + } 51 + 52 + }
+41
src/applications/passphrase/xaction/PassphraseCredentialLockTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialLockTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:lock'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getIsLocked(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setIsLocked((int)$value); 14 + } 15 + 16 + public function shouldHide() { 17 + $new = $this->getNewValue(); 18 + if ($new === null) { 19 + return true; 20 + } 21 + return false; 22 + } 23 + 24 + public function getTitle() { 25 + return pht( 26 + '%s locked this credential.', 27 + $this->renderAuthor()); 28 + } 29 + 30 + public function getTitleForFeed() { 31 + return pht( 32 + '%s locked credential %s.', 33 + $this->renderAuthor(), 34 + $this->renderObject()); 35 + } 36 + 37 + public function getIcon() { 38 + return 'fa-lock'; 39 + } 40 + 41 + }
+33
src/applications/passphrase/xaction/PassphraseCredentialLookedAtTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialLookedAtTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:lookedAtSecret'; 7 + 8 + public function generateOldValue($object) { 9 + return null; 10 + } 11 + 12 + public function getTitle() { 13 + return pht( 14 + '%s examined the secret plaintext for this credential.', 15 + $this->renderAuthor()); 16 + } 17 + 18 + public function getTitleForFeed() { 19 + return pht( 20 + '%s examined the secret plaintext for credential %s.', 21 + $this->renderAuthor(), 22 + $this->renderObject()); 23 + } 24 + 25 + public function getIcon() { 26 + return 'fa-eye'; 27 + } 28 + 29 + public function getColor() { 30 + return 'blue'; 31 + } 32 + 33 + }
+71
src/applications/passphrase/xaction/PassphraseCredentialNameTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialNameTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + $old = $this->getOldValue(); 18 + if (!strlen($old)) { 19 + return pht( 20 + '%s created this credential.', 21 + $this->renderAuthor()); 22 + } else { 23 + return pht( 24 + '%s renamed this credential from %s to %s.', 25 + $this->renderAuthor(), 26 + $this->renderOldValue(), 27 + $this->renderNewValue()); 28 + } 29 + } 30 + 31 + public function getTitleForFeed() { 32 + $old = $this->getOldValue(); 33 + if (!strlen($old)) { 34 + return pht( 35 + '%s created %s.', 36 + $this->renderAuthor(), 37 + $this->renderObject()); 38 + } else { 39 + return pht( 40 + '%s renamed %s credential %s to %s.', 41 + $this->renderAuthor(), 42 + $this->renderObject(), 43 + $this->renderOldValue(), 44 + $this->renderNewValue()); 45 + } 46 + } 47 + 48 + public function validateTransactions($object, array $xactions) { 49 + $errors = array(); 50 + 51 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 52 + $errors[] = $this->newRequiredError( 53 + pht('Credentials must have a name.')); 54 + } 55 + 56 + $max_length = $object->getColumnMaximumByteLength('name'); 57 + foreach ($xactions as $xaction) { 58 + $new_value = $xaction->getNewValue(); 59 + 60 + $new_length = strlen($new_value); 61 + if ($new_length > $max_length) { 62 + $errors[] = $this->newInvalidError( 63 + pht('The name can be no longer than %s characters.', 64 + new PhutilNumber($max_length))); 65 + } 66 + } 67 + 68 + return $errors; 69 + } 70 + 71 + }
+56
src/applications/passphrase/xaction/PassphraseCredentialSecretIDTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialSecretIDTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:secretID'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getSecretID(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $old_id = $object->getSecretID(); 14 + if ($old_id) { 15 + $this->destroySecret($old_id); 16 + } 17 + $object->setSecretID($value); 18 + } 19 + 20 + public function shouldHide() { 21 + if (!$this->getOldValue()) { 22 + return true; 23 + } 24 + 25 + return false; 26 + } 27 + 28 + public function getTitle() { 29 + $old = $this->getOldValue(); 30 + if ($old === null) { 31 + return pht( 32 + '%s attached a new secret to this credential.', 33 + $this->renderAuthor()); 34 + } else { 35 + return pht( 36 + '%s updated the secret for this credential.', 37 + $this->renderAuthor()); 38 + } 39 + } 40 + 41 + public function getTitleForFeed() { 42 + $old = $this->getOldValue(); 43 + if ($old === null) { 44 + return pht( 45 + '%s attached a new secret to %s.', 46 + $this->renderAuthor(), 47 + $this->renderObject()); 48 + } else { 49 + return pht( 50 + '%s updated the secret for %s.', 51 + $this->renderAuthor(), 52 + $this->renderObject()); 53 + } 54 + } 55 + 56 + }
+15
src/applications/passphrase/xaction/PassphraseCredentialTransactionType.php
··· 1 + <?php 2 + 3 + abstract class PassphraseCredentialTransactionType 4 + extends PhabricatorModularTransactionType { 5 + 6 + public function destroySecret($secret_id) { 7 + $table = new PassphraseSecret(); 8 + queryfx( 9 + $table->establishConnection('w'), 10 + 'DELETE FROM %T WHERE id = %d', 11 + $table->getTableName(), 12 + $secret_id); 13 + } 14 + 15 + }
+56
src/applications/passphrase/xaction/PassphraseCredentialUsernameTransaction.php
··· 1 + <?php 2 + 3 + final class PassphraseCredentialUsernameTransaction 4 + extends PassphraseCredentialTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'passphrase:username'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getUsername(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setUsername($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s set the username for this credential to %s.', 19 + $this->renderAuthor(), 20 + $this->renderNewValue()); 21 + } 22 + 23 + public function getTitleForFeed() { 24 + return pht( 25 + '%s set the username for credential %s to %s.', 26 + $this->renderAuthor(), 27 + $this->renderObject(), 28 + $this->renderNewValue()); 29 + } 30 + 31 + public function validateTransactions($object, array $xactions) { 32 + $errors = array(); 33 + 34 + $credential_type = $object->getImplementation(); 35 + if ($credential_type->shouldRequireUsername()) { 36 + if ($this->isEmptyTextTransaction($object->getUsername(), $xactions)) { 37 + $errors[] = $this->newRequiredError( 38 + pht('This credential must have a username.')); 39 + } 40 + } 41 + 42 + $max_length = $object->getColumnMaximumByteLength('username'); 43 + foreach ($xactions as $xaction) { 44 + $new_value = $xaction->getNewValue(); 45 + $new_length = strlen($new_value); 46 + if ($new_length > $max_length) { 47 + $errors[] = $this->newInvalidError( 48 + pht('The username can be no longer than %s characters.', 49 + new PhutilNumber($max_length))); 50 + } 51 + } 52 + 53 + return $errors; 54 + } 55 + 56 + }