@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
at recaptime-dev/main 138 lines 3.7 kB view raw
1<?php 2 3final class PassphraseCredentialSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Passphrase Credentials'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorPassphraseApplication::class; 12 } 13 14 public function newQuery() { 15 return new PassphraseCredentialQuery(); 16 } 17 18 protected function buildCustomSearchFields() { 19 return array( 20 id(new PhabricatorSearchThreeStateField()) 21 ->setLabel(pht('Status')) 22 ->setKey('isDestroyed') 23 ->setOptions( 24 pht('Show All'), 25 pht('Show Only Destroyed Credentials'), 26 pht('Show Only Active Credentials')), 27 id(new PhabricatorSearchTextField()) 28 ->setLabel(pht('Name Contains')) 29 ->setKey('name'), 30 ); 31 } 32 33 protected function buildQueryFromParameters(array $map) { 34 $query = $this->newQuery(); 35 36 if ($map['isDestroyed'] !== null) { 37 $query->withIsDestroyed($map['isDestroyed']); 38 } 39 40 if (strlen($map['name'])) { 41 $query->withNameContains($map['name']); 42 } 43 44 return $query; 45 } 46 47 protected function getURI($path) { 48 return '/passphrase/'.$path; 49 } 50 51 protected function getBuiltinQueryNames() { 52 return array( 53 'active' => pht('Active Credentials'), 54 'all' => pht('All Credentials'), 55 ); 56 } 57 58 public function buildSavedQueryFromBuiltin($query_key) { 59 $query = $this->newSavedQuery(); 60 $query->setQueryKey($query_key); 61 62 switch ($query_key) { 63 case 'all': 64 return $query; 65 case 'active': 66 return $query->setParameter('isDestroyed', false); 67 } 68 69 return parent::buildSavedQueryFromBuiltin($query_key); 70 } 71 72 /** 73 * @param array<PassphraseCredential> $credentials 74 * @param PhabricatorSavedQuery $query 75 * @param array<PhabricatorObjectHandle> $handles 76 */ 77 protected function renderResultList( 78 array $credentials, 79 PhabricatorSavedQuery $query, 80 array $handles) { 81 assert_instances_of($credentials, PassphraseCredential::class); 82 83 $viewer = $this->requireViewer(); 84 85 $list = new PHUIObjectItemListView(); 86 $list->setUser($viewer); 87 foreach ($credentials as $credential) { 88 89 $item = id(new PHUIObjectItemView()) 90 ->setObjectName('K'.$credential->getID()) 91 ->setHeader($credential->getName()) 92 ->setHref('/K'.$credential->getID()) 93 ->setObject($credential); 94 95 $item->addAttribute( 96 pht('Login: %s', $credential->getUsername())); 97 98 if ($credential->getIsDestroyed()) { 99 $item->addIcon('fa-ban', pht('Destroyed')); 100 $item->setDisabled(true); 101 } 102 103 $type = PassphraseCredentialType::getTypeByConstant( 104 $credential->getCredentialType()); 105 if ($type) { 106 $item->addIcon('fa-wrench', $type->getCredentialTypeName()); 107 } 108 109 $list->addItem($item); 110 } 111 112 $result = new PhabricatorApplicationSearchResultView(); 113 $result->setObjectList($list); 114 $result->setNoDataString(pht('No credentials found.')); 115 116 return $result; 117 } 118 119 protected function getNewUserBody() { 120 $create_button = id(new PHUIButtonView()) 121 ->setTag('a') 122 ->setText(pht('Create a Credential')) 123 ->setHref('/passphrase/create/') 124 ->setColor(PHUIButtonView::GREEN); 125 126 $icon = $this->getApplication()->getIcon(); 127 $app_name = $this->getApplication()->getName(); 128 $view = id(new PHUIBigInfoView()) 129 ->setIcon($icon) 130 ->setTitle(pht('Welcome to %s', $app_name)) 131 ->setDescription( 132 pht('Credential management and general storage of shared secrets.')) 133 ->addAction($create_button); 134 135 return $view; 136 } 137 138}