]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Implement user_exists() everywhere and use it to correct the console output.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 19:43:45 +0000 (15:43 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 6 Oct 2013 19:43:45 +0000 (15:43 -0400)
lib/common/agendav_plugin.rb
lib/common/plugin.rb
lib/rm/plugins/agendav.rb
lib/rm/plugins/davical.rb
lib/rm/plugins/dovecot_mailstore.rb
lib/rm/plugins/postfixadmin_db.rb
lib/rm/plugins/roundcube_db.rb

index cb445bed817d853c3b91c3e3c75c2735330614cc..88de0d79ded0ca11897f1fbf4a60bf0162db2d92 100644 (file)
@@ -35,10 +35,6 @@ module AgendavPlugin
 
   protected;
 
 
   protected;
 
-  def user_exists(account)
-    ad_users = list_users()
-    return ad_users.include?(account)
-  end
 
   def list_users()
     usernames = []
 
   def list_users()
     usernames = []
index 633c8fd26d0c2f4bd467ff3d33aa3a48cc1a93fc..77d80c469e7b1e94f794b84b0c532f632765f77e 100644 (file)
@@ -33,6 +33,14 @@ module Plugin
     raise NotImplementedError
   end
 
     raise NotImplementedError
   end
 
+  def user_exists(username)
+    # Does the given username exist for this plugin? We use a naive
+    # implementation here based on list_users() which is required to
+    # exist above. Plugins can override this with something fast.
+    users = list_users()
+    return users.include?(username)
+  end
+
   def list_domains_users(domains)
     # Get all usernames belonging to the given domains. If a username
     # ends in @example.com, it belongs to the domain example.com
   def list_domains_users(domains)
     # Get all usernames belonging to the given domains. If a username
     # ends in @example.com, it belongs to the domain example.com
index 1366bd6db69a15452a0b777dd3b131e65b90d54a..2b2952f01a9254e01331b7a663d632762b8eb0ea 100644 (file)
@@ -12,6 +12,7 @@ class AgendavRm
   def delete_account(account)
     # Delete the given username and any records in other tables
     # belonging to it.
   def delete_account(account)
     # Delete the given username and any records in other tables
     # belonging to it.
+    raise NonexistentAccountError.new(account) if not user_exists(account)
 
     sql_queries = ['DELETE FROM prefs WHERE username = $1;']
     sql_queries << 'DELETE FROM shared WHERE user_from = $1;'
 
     sql_queries = ['DELETE FROM prefs WHERE username = $1;']
     sql_queries << 'DELETE FROM shared WHERE user_from = $1;'
index 02e889466849fb7c67aad15e0812afce1e23e33e..04d5fbf024dde17e47375afa486d4359c897c9dd 100644 (file)
@@ -16,6 +16,8 @@ class DavicalRm
     # Delete the given username. DAViCal uses foreign keys properly
     # and only supports postgres, so we let the ON DELETE CASCADE
     # trigger handle most of the work.
     # Delete the given username. DAViCal uses foreign keys properly
     # and only supports postgres, so we let the ON DELETE CASCADE
     # trigger handle most of the work.
+    raise NonexistentAccountError.new(account) if not user_exists(account)
+
     sql_queries = ['DELETE FROM usr WHERE username = $1']
 
     begin
     sql_queries = ['DELETE FROM usr WHERE username = $1']
 
     begin
index 72c80c83537559bef358868dc9fc57c0dc905890..8647b01a1685e0e4382f865900bdb26bd9d7a73a 100644 (file)
@@ -11,11 +11,13 @@ class DovecotMailstoreRm
 
 
   def delete_domain(domain)
 
 
   def delete_domain(domain)
+    # Will raise an exception if the path doesn't exist.
     domain_path = self.get_domain_path(domain)
     FileUtils.rm_r(domain_path)
   end
 
   def delete_account(account)
     domain_path = self.get_domain_path(domain)
     FileUtils.rm_r(domain_path)
   end
 
   def delete_account(account)
+    # Will raise an exception if the path doesn't exist.
     account_path = self.get_account_path(account)
     FileUtils.rm_r(account_path)
   end
     account_path = self.get_account_path(account)
     FileUtils.rm_r(account_path)
   end
index 1928202123e1b0316157f67552513ef796b325f4..ca91b8beb553f545b00f8de85c5cc475bef594fa 100644 (file)
@@ -10,6 +10,8 @@ class PostfixadminDbRm
 
 
   def delete_account(account)
 
 
   def delete_account(account)
+    raise NonexistentAccountError.new(account) if not user_exists(account)
+
     sql_queries = ['DELETE FROM alias WHERE address = $1;']
     # Wipe out any aliases pointed at our account.
     sql_queries << "UPDATE alias SET goto=REPLACE(goto, $1, '');"
     sql_queries = ['DELETE FROM alias WHERE address = $1;']
     # Wipe out any aliases pointed at our account.
     sql_queries << "UPDATE alias SET goto=REPLACE(goto, $1, '');"
index 5687ce436ea76cca659f66cd00b6825499ae43b1..5cda273643029ef808c9b184621017779f92806e 100644 (file)
@@ -11,6 +11,8 @@ class RoundcubeDbRm
   def delete_account(account)
     # Delete the given username and any records in other tables
     # belonging to it.
   def delete_account(account)
     # Delete the given username and any records in other tables
     # belonging to it.
+    raise NonexistentAccountError.new(account) if not user_exists(account)
+
     user_id = self.get_user_id(account)
 
     # The Roundcube developers were nice enough to include
     user_id = self.get_user_id(account)
 
     # The Roundcube developers were nice enough to include