diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 630967ecfc..d0c946c4f3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1323,6 +1323,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorProjectInterface', + 'PhabricatorSSHPublicKeyInterface', 'AlmanacPropertyInterface', ), 'AlmanacDeviceController' => 'AlmanacController', @@ -4396,6 +4398,7 @@ phutil_register_library_map(array( '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 index 799494963a..94b7c44b8a 100644 --- a/src/applications/almanac/controller/AlmanacDeviceViewController.php +++ b/src/applications/almanac/controller/AlmanacDeviceViewController.php @@ -57,6 +57,7 @@ final class AlmanacDeviceViewController $box, $interfaces, $this->buildAlmanacPropertiesTable($device), + $this->buildSSHKeysTable($device), $xaction_view, ), array( @@ -141,4 +142,65 @@ final class AlmanacDeviceViewController ->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 index b7163389ba..9c8aa260e6 100644 --- a/src/applications/almanac/storage/AlmanacDevice.php +++ b/src/applications/almanac/storage/AlmanacDevice.php @@ -7,6 +7,7 @@ final class AlmanacDevice PhabricatorCustomFieldInterface, PhabricatorApplicationTransactionInterface, PhabricatorProjectInterface, + PhabricatorSSHPublicKeyInterface, AlmanacPropertyInterface { protected $name; @@ -160,4 +161,13 @@ final class AlmanacDevice 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 index 0000000000..7dc3024d1c --- /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 index 257218a300..1d59071d87 100644 --- a/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php +++ b/src/applications/settings/panel/PhabricatorSettingsPanelSSHKeys.php @@ -32,51 +32,11 @@ final class PhabricatorSettingsPanelSSHKeys ->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();