From a160b8a3b2d0e883af638d4a6252bf280bafc685 Mon Sep 17 00:00:00 2001
From: pwolanin <pwolanin@49851.no-reply.drupal.org>
Date: Mon, 2 May 2011 11:01:34 -0400
Subject: [PATCH] Issue #1128446 by pwolanin: add a view operation for keys

---
 sshkey.module    |    9 +++++++++
 sshkey.pages.inc |   12 ++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/sshkey.module b/sshkey.module
index 0c14d01..e2149d9 100644
--- a/sshkey.module
+++ b/sshkey.module
@@ -108,6 +108,15 @@ function sshkey_menu() {
     'file' => 'sshkey.pages.inc',
     'modal' => TRUE,
   );
+  $items['ssh-keys/%/%/%sshkey/view'] = array(
+    'title' => 'View SSH key',
+    'page callback' => 'sshkey_view_key',
+    'page arguments' => array(1, 2, 3),
+    'access callback' => 'sshkey_access',
+    'access arguments' => array('view', 1, 2, 3),
+    'file' => 'sshkey.pages.inc',
+    'modal' => FALSE,
+  );
   $items['ssh-keys/%/%/%sshkey/edit'] = array(
     'title' => 'Edit SSH key',
     'page callback' => 'drupal_get_form',
diff --git a/sshkey.pages.inc b/sshkey.pages.inc
index 3bed96b..f765f98 100644
--- a/sshkey.pages.inc
+++ b/sshkey.pages.inc
@@ -42,6 +42,11 @@ function sshkey_list_page($entity_type, $entity_id) {
     $rows[$key_id]['fingerprint'] = theme('sshkey_fingerprint', array('key' => $key));
 
     $operations = array();
+    $operations['view'] = array(
+      'title' => t('View'),
+      'href' => "ssh-keys/{$entity_type}/{$entity_id}/{$key_id}/view",
+      'modal' => FALSE,
+    );
     if (sshkey_access('edit', $entity_type, $entity_id, $key)) {
       $operations['edit'] = array(
         'title' => t('Edit'),
@@ -87,6 +92,13 @@ function sshkey_list_page($entity_type, $entity_id) {
   return $build;
 }
 
+function sshkey_view_key($entity_type, $entity_id, $key) {
+  // We are returning plain text, so tell the browser.
+  drupal_add_http_header('Content-Type', 'text/plain');
+  echo $key->value;
+  return NULL;
+}
+
 function sshkey_edit_form($form, $form_state, $entity_type, $entity_id, $key = NULL) {
   $entity = entity_load($entity_type, array($entity_id));
   $entity = reset($entity);
-- 
1.7.1.1

