From bd2dabf89ab277fbe315b05e6dfa839afb5ce5ef Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 6 Oct 2013 15:43:45 -0400 Subject: [PATCH] Implement user_exists() everywhere and use it to correct the console output. --- lib/common/agendav_plugin.rb | 4 ---- lib/common/plugin.rb | 8 ++++++++ lib/rm/plugins/agendav.rb | 1 + lib/rm/plugins/davical.rb | 2 ++ lib/rm/plugins/dovecot_mailstore.rb | 2 ++ lib/rm/plugins/postfixadmin_db.rb | 2 ++ lib/rm/plugins/roundcube_db.rb | 2 ++ 7 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/common/agendav_plugin.rb b/lib/common/agendav_plugin.rb index cb445be..88de0d7 100644 --- a/lib/common/agendav_plugin.rb +++ b/lib/common/agendav_plugin.rb @@ -35,10 +35,6 @@ module AgendavPlugin protected; - def user_exists(account) - ad_users = list_users() - return ad_users.include?(account) - end def list_users() usernames = [] diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index 633c8fd..77d80c4 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -33,6 +33,14 @@ module Plugin 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 diff --git a/lib/rm/plugins/agendav.rb b/lib/rm/plugins/agendav.rb index 1366bd6..2b2952f 100644 --- a/lib/rm/plugins/agendav.rb +++ b/lib/rm/plugins/agendav.rb @@ -12,6 +12,7 @@ class AgendavRm 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;' diff --git a/lib/rm/plugins/davical.rb b/lib/rm/plugins/davical.rb index 02e8894..04d5fbf 100644 --- a/lib/rm/plugins/davical.rb +++ b/lib/rm/plugins/davical.rb @@ -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. + raise NonexistentAccountError.new(account) if not user_exists(account) + sql_queries = ['DELETE FROM usr WHERE username = $1'] begin diff --git a/lib/rm/plugins/dovecot_mailstore.rb b/lib/rm/plugins/dovecot_mailstore.rb index 72c80c8..8647b01 100644 --- a/lib/rm/plugins/dovecot_mailstore.rb +++ b/lib/rm/plugins/dovecot_mailstore.rb @@ -11,11 +11,13 @@ class DovecotMailstoreRm 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) + # Will raise an exception if the path doesn't exist. account_path = self.get_account_path(account) FileUtils.rm_r(account_path) end diff --git a/lib/rm/plugins/postfixadmin_db.rb b/lib/rm/plugins/postfixadmin_db.rb index 1928202..ca91b8b 100644 --- a/lib/rm/plugins/postfixadmin_db.rb +++ b/lib/rm/plugins/postfixadmin_db.rb @@ -10,6 +10,8 @@ class PostfixadminDbRm 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, '');" diff --git a/lib/rm/plugins/roundcube_db.rb b/lib/rm/plugins/roundcube_db.rb index 5687ce4..5cda273 100644 --- a/lib/rm/plugins/roundcube_db.rb +++ b/lib/rm/plugins/roundcube_db.rb @@ -11,6 +11,8 @@ class RoundcubeDbRm 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 -- 2.44.2