]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/mailshears/plugins/davical.rb
Factor out common code that can be used to mv (rename) accounts.
[mailshears.git] / lib / mailshears / plugins / davical.rb
index 8f6be66959da76d31d6a0e2b26db59ecd613a6f5..2091529f64ffd6e6cb6b57856b8c44922853f043 100644 (file)
@@ -1,8 +1,15 @@
 require 'pg'
 
-class DavicalDb
+require 'common/plugin'
+require 'mailshears/rm_plugin'
 
+class DavicalDb
+  #
+  # DAViCal only supports Postgres, so even if we ever are
+  # database-agnostic, this plugin can't be.
+  #
   include Plugin
+  include RmPlugin
 
   def initialize()
     cfg = Configuration.new()
@@ -23,12 +30,12 @@ class DavicalDb
 
 
   def describe_account(account)
-    user_id = self.get_principal_id(account)
+    principal_id = self.get_principal_id(account)
 
-    if user_id.nil?
+    if principal_id.nil?
       return 'User not found'
     else
-      return "Principal ID: #{user_id}"
+      return "Principal ID: #{principal_id}"
     end
   end
 
@@ -94,7 +101,10 @@ class DavicalDb
                                   @db_user,
                                   @db_pass)
 
-      sql_query = "SELECT principal_id FROM users WHERE username = $1;"
+      sql_query =  "SELECT principal.principal_id "
+      sql_query += "FROM (principal INNER JOIN usr "
+      sql_query += "      ON principal.user_no = usr.user_no) "
+      sql_query += "WHERE usr.username = $1;"
 
       connection.query(sql_query, [account]) do |result|
         if result.num_tuples > 0
@@ -116,7 +126,6 @@ class DavicalDb
   def get_davical_usernames()
     usernames = []
 
-    # Just assume PostgreSQL for now.
     begin
       connection = PGconn.connect(@db_host,
                                   @db_port,
@@ -126,7 +135,8 @@ class DavicalDb
                                   @db_user,
                                   @db_pass)
 
-      sql_query  = 'SELECT username FROM usr;'
+      # User #1 is the super-user, and not tied to an email address.
+      sql_query  = 'SELECT username FROM usr WHERE user_no > 1;'
 
       connection.query(sql_query) do |result|
         usernames = result.field_values('username')