From 6d531c8c72531067b01072834666301659745722 Mon Sep 17 00:00:00 2001
From: pwolanin <pwolanin@49851.no-reply.drupal.org>
Date: Fri, 15 Apr 2011 17:23:42 -0400
Subject: [PATCH] Issue #1128876 by pwolanin: add Views2 API integration for key listings per user

---
 sshkey.module    |   10 +++++
 sshkey.views.inc |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 0 deletions(-)
 create mode 100644 sshkey.views.inc

diff --git a/sshkey.module b/sshkey.module
index 291c5e9..a74017e 100644
--- a/sshkey.module
+++ b/sshkey.module
@@ -132,6 +132,16 @@ function sshkey_user($op, $edit, $account, $category = NULL) {
 }
 
 /**
+ * Implementation of hook_views_api().
+ */
+function sshkey_views_api() {
+  return array(
+    'api' => 2.0,
+    'path' => drupal_get_path('module', 'sshkey'),
+  );
+}
+
+/**
  * Access callback for SSH public key operations.
  */
 function sshkey_access($op, $entity_type = NULL, $entity_id = NULL, $key = NULL, $account = NULL) {
diff --git a/sshkey.views.inc b/sshkey.views.inc
new file mode 100644
index 0000000..52bbd7a
--- /dev/null
+++ b/sshkey.views.inc
@@ -0,0 +1,98 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provides support for the Views module.
+ */
+
+
+/**
+ * Implementation of hook_views_data().
+ */
+function sshkey_views_data() {
+  $data = array();
+
+  $data['sshkey']['table']['group'] = t('User SSH keys');
+  $data['sshkey']['table']['join']['users'] = array(
+    'left_table' => 'users',
+    'left_field' => 'uid',
+    // Note the 6.x module only supports users, but has a generic backported 7.x schema.
+    'field' => 'entity_id',
+  );
+
+  $data['sshkey']['entity_id'] = array(
+    'title' => t('User SSH keys'),
+    'help' => t('The SSH keys and releated data.'),
+    'relationship' => array(
+      'base' => 'users',
+      'base field' => 'uid',
+      'handler' => 'views_handler_relationship',
+      'label' => t('User SSH keys'),
+    ),
+  );
+
+  $data['sshkey']['value'] = array(
+    'title' => t('SSH key value'),
+    'help' => t('The actual public key.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => FALSE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+  $data['sshkey']['title'] = array(
+    'title' => t('SSH key title (comment)'),
+    'help' => t('title or comment for this key.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+  $data['sshkey']['fingerprint'] = array(
+    'title' => t('SSH key fingerprint'),
+    'help' => t('The unique fingerprint (MD5 hash) of the key.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => FALSE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  $data['sshkey']['changed'] = array(
+    'title' => t('Key last changed'),
+    'help' => t('Display the time a key was last changed.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort_date',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_date',
+    ),
+  );
+
+
+  return $data;
+}
-- 
1.7.1.1

