diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1323,6 +1323,7 @@ 'PhabricatorAuthSSHKeyEditController' => 'applications/auth/controller/PhabricatorAuthSSHKeyEditController.php', 'PhabricatorAuthSSHKeyGenerateController' => 'applications/auth/controller/PhabricatorAuthSSHKeyGenerateController.php', 'PhabricatorAuthSSHKeyQuery' => 'applications/auth/query/PhabricatorAuthSSHKeyQuery.php', + 'PhabricatorAuthSSHKeyTableView' => 'applications/auth/view/PhabricatorAuthSSHKeyTableView.php', 'PhabricatorAuthSSHPublicKey' => 'applications/auth/sshkey/PhabricatorAuthSSHPublicKey.php', 'PhabricatorAuthSession' => 'applications/auth/storage/PhabricatorAuthSession.php', 'PhabricatorAuthSessionEngine' => 'applications/auth/engine/PhabricatorAuthSessionEngine.php', @@ -3011,6 +3012,7 @@ 'PhabricatorCustomFieldInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorProjectInterface', + 'PhabricatorSSHPublicKeyInterface', 'AlmanacPropertyInterface', ), 'AlmanacDeviceController' => 'AlmanacController', @@ -4396,6 +4398,7 @@ 'PhabricatorAuthSSHKeyEditController' => 'PhabricatorAuthSSHKeyController', 'PhabricatorAuthSSHKeyGenerateController' => 'PhabricatorAuthSSHKeyController', 'PhabricatorAuthSSHKeyQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorAuthSSHKeyTableView' => 'AphrontView', 'PhabricatorAuthSSHPublicKey' => 'Phobject', 'PhabricatorAuthSession' => array( 'PhabricatorAuthDAO', diff --git a/src/applications/almanac/controller/AlmanacDeviceViewController.php b/src/applications/almanac/controller/AlmanacDeviceViewController.php --- a/src/applications/almanac/controller/AlmanacDeviceViewController.php +++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php @@ -57,6 +57,7 @@ $box, $interfaces, $this->buildAlmanacPropertiesTable($device), + $this->buildSSHKeysTable($device), $xaction_view, ), array( @@ -141,4 +142,65 @@ ->appendChild($table); } + private function buildSSHKeysTable(AlmanacDevice $device) { + $viewer = $this->getViewer(); + $id = $device->getID(); + $device_phid = $device->getPHID(); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $device, + PhabricatorPolicyCapability::CAN_EDIT); + + $keys = id(new PhabricatorAuthSSHKeyQuery()) + ->setViewer($viewer) + ->withObjectPHIDs(array($device_phid)) + ->execute(); + + $table = id(new PhabricatorAuthSSHKeyTableView()) + ->setUser($viewer) + ->setKeys($keys) + ->setCanEdit($can_edit) + ->setNoDataString(pht('This device has no associated SSH public keys.')); + + try { + PhabricatorSSHKeyGenerator::assertCanGenerateKeypair(); + $can_generate = true; + } catch (Exception $ex) { + $can_generate = false; + } + + $generate_uri = '/auth/sshkey/generate/?objectPHID='.$device_phid; + $upload_uri = '/auth/sshkey/upload/?objectPHID='.$device_phid; + + $header = id(new PHUIHeaderView()) + ->setHeader(pht('SSH Public Keys')) + ->addActionLink( + id(new PHUIButtonView()) + ->setTag('a') + ->setHref($generate_uri) + ->setWorkflow(true) + ->setDisabled(!$can_edit || !$can_generate) + ->setText(pht('Generate Keypair')) + ->setIcon( + id(new PHUIIconView()) + ->setIconFont('fa-lock'))) + ->addActionLink( + id(new PHUIButtonView()) + ->setTag('a') + ->setHref($upload_uri) + ->setWorkflow(true) + ->setDisabled(!$can_edit) + ->setText(pht('Upload Public Key')) + ->setIcon( + id(new PHUIIconView()) + ->setIconFont('fa-upload'))); + + return id(new PHUIObjectBoxView()) + ->setHeader($header) + ->appendChild($table); + + + } + } diff --git a/src/applications/almanac/storage/AlmanacDevice.php b/src/applications/almanac/storage/AlmanacDevice.php --- a/src/applications/almanac/storage/AlmanacDevice.php +++ b/src/applications/almanac/storage/AlmanacDevice.php @@ -7,6 +7,7 @@ PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, PhabricatorProjectInterface, + PhabricatorSSHPublicKeyInterface, AlmanacPropertyInterface { protected $name; @@ -160,4 +161,13 @@ return new AlmanacDeviceTransaction(); } + +/* -( PhabricatorSSHPublicKeyInterface )----------------------------------- */ + + + public function getSSHPublicKeyManagementURI(PhabricatorUser $viewer) { + return $this->getURI(); + } + + } diff --git a/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php b/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php new file mode 100644 --- /dev/null +++ b/src/applications/auth/view/PhabricatorAuthSSHKeyTableView.php @@ -0,0 +1,81 @@ +noDataString = $no_data_string; + return $this; + } + + public function setCanEdit($can_edit) { + $this->canEdit = $can_edit; + return $this; + } + + public function setKeys(array $keys) { + assert_instances_of($keys, 'PhabricatorAuthSSHKey'); + $this->keys = $keys; + return $this; + } + + public function render() { + $keys = $this->keys; + $viewer = $this->getUser(); + + if ($this->canEdit) { + $delete_class = 'small grey button'; + } else { + $delete_class = 'small grey button disabled'; + } + + $rows = array(); + foreach ($keys as $key) { + $rows[] = array( + javelin_tag( + 'a', + array( + 'href' => '/auth/sshkey/edit/'.$key->getID().'/', + 'sigil' => 'workflow', + ), + $key->getName()), + $key->getKeyComment(), + $key->getKeyType(), + phabricator_datetime($key->getDateCreated(), $viewer), + javelin_tag( + 'a', + array( + 'href' => '/auth/sshkey/delete/'.$key->getID().'/', + 'class' => $delete_class, + 'sigil' => 'workflow', + ), + pht('Delete')), + ); + } + + $table = id(new AphrontTableView($rows)) + ->setNoDataString($this->noDataString) + ->setHeaders( + array( + pht('Name'), + pht('Comment'), + pht('Type'), + pht('Added'), + null, + )) + ->setColumnClasses( + array( + 'wide pri', + '', + '', + 'right', + 'action', + )); + + return $table; + } + +} diff --git a/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php b/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php --- a/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php @@ -32,51 +32,11 @@ ->withObjectPHIDs(array($user->getPHID())) ->execute(); - $rows = array(); - foreach ($keys as $key) { - $rows[] = array( - javelin_tag( - 'a', - array( - 'href' => '/auth/sshkey/edit/'.$key->getID().'/', - 'sigil' => 'workflow', - ), - $key->getName()), - $key->getKeyComment(), - $key->getKeyType(), - phabricator_date($key->getDateCreated(), $viewer), - phabricator_time($key->getDateCreated(), $viewer), - javelin_tag( - 'a', - array( - 'href' => '/auth/sshkey/delete/'.$key->getID().'/', - 'class' => 'small grey button', - 'sigil' => 'workflow', - ), - pht('Delete')), - ); - } - - $table = new AphrontTableView($rows); - $table->setNoDataString(pht("You haven't added any SSH Public Keys.")); - $table->setHeaders( - array( - pht('Name'), - pht('Comment'), - pht('Type'), - pht('Created'), - pht('Time'), - '', - )); - $table->setColumnClasses( - array( - 'wide pri', - '', - '', - '', - 'right', - 'action', - )); + $table = id(new PhabricatorAuthSSHKeyTableView()) + ->setUser($viewer) + ->setKeys($keys) + ->setCanEdit(true) + ->setNoDataString("You haven't added any SSH Public Keys."); $panel = new PHUIObjectBoxView(); $header = new PHUIHeaderView();