From: Michael Orlitzky Date: Tue, 3 Nov 2015 17:41:32 +0000 (-0500) Subject: Simplify prune plugins and fix array difference error. X-Git-Tag: 0.0.1~33 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=9c2503578bcb8141d13bf4a5af1ef460c70fd219;p=mailshears.git Simplify prune plugins and fix array difference error. --- diff --git a/lib/prune/plugins/agendav.rb b/lib/prune/plugins/agendav.rb index 43b5c99..86a437b 100644 --- a/lib/prune/plugins/agendav.rb +++ b/lib/prune/plugins/agendav.rb @@ -4,21 +4,5 @@ require 'prune/prune_plugin' require 'rm/plugins/agendav' class AgendavPrune < AgendavRm - include PrunePlugin - - def get_leftover_domains(db_domains) - # AgenDAV doesn't have a concept of domains. We could parse the - # usernames to see what domains are present, but the point is - # moot: all leftover users will be pruned anyway. - return [] - end - - - def get_leftover_users(db_users) - # Get a list of all users who have logged in to AgenDAV. - ad_users = self.list_users() - return ad_users - db_users - end - end diff --git a/lib/prune/plugins/davical.rb b/lib/prune/plugins/davical.rb index 3c5ff0e..f7f4b39 100644 --- a/lib/prune/plugins/davical.rb +++ b/lib/prune/plugins/davical.rb @@ -4,26 +4,5 @@ require 'prune/prune_plugin' require 'rm/plugins/davical' class DavicalPrune < DavicalRm - # - # DAViCal only supports Postgres, so even if we ever are - # database-agnostic, this plugin can't be. - # include PrunePlugin - - - def get_leftover_domains(db_domains) - # DAViCal doesn't have a concept of domains. We could parse the - # usernames to see what domains are present, but the point is - # moot: all leftover users will be pruned anyway. - return [] - end - - - def get_leftover_users(db_users) - # Get a list of all users who have logged in to DAViCal. - davical_users = self.list_users() - return davical_users - db_users - end - - end diff --git a/lib/prune/plugins/dovecot.rb b/lib/prune/plugins/dovecot.rb index bf96420..7d346ac 100644 --- a/lib/prune/plugins/dovecot.rb +++ b/lib/prune/plugins/dovecot.rb @@ -2,25 +2,5 @@ require 'prune/prune_plugin' require 'rm/plugins/dovecot' class DovecotPrune < DovecotRm - include PrunePlugin - - - def get_leftover_domains(db_domains) - # Get the list of domains according to the filesystem. - fs_domains = self.list_domains() - - # Return the list of domains on the filesystem that aren't in the DB. - return (fs_domains - db_domains) - end - - def get_leftover_users(db_users) - # Get the list of users according to the filesystem. - fs_domains = self.list_domains() - fs_users = self.list_domains_users(fs_domains) - - # And return the users on the filesystem that aren't in the DB. - return (fs_users - db_users) - end - end diff --git a/lib/prune/plugins/roundcube.rb b/lib/prune/plugins/roundcube.rb index 1bb7827..5869b02 100644 --- a/lib/prune/plugins/roundcube.rb +++ b/lib/prune/plugins/roundcube.rb @@ -4,22 +4,5 @@ require 'prune/prune_plugin' require 'rm/plugins/roundcube' class RoundcubePrune < RoundcubeRm - include PrunePlugin - - - def get_leftover_domains(db_domains) - # Roundcube doesn't have a concept of domains. We could parse the - # usernames to see what domains are present, but the point is - # moot: all leftover users will be pruned anyway. - return [] - end - - - def get_leftover_users(db_users) - # Get a list of all users who have logged in to Roundcube. - rc_users = self.list_users() - return rc_users - db_users - end - end diff --git a/lib/prune/prune_plugin.rb b/lib/prune/prune_plugin.rb index 44fd636..1046f2d 100644 --- a/lib/prune/prune_plugin.rb +++ b/lib/prune/prune_plugin.rb @@ -20,12 +20,16 @@ module PrunePlugin def get_leftover_domains(db_domains) # Given a list of domains, determine which domains belonging to # this plugin are not contained in the given list. - raise NotImplementedError + + # WARNING! Array difference doesn't work for some reason. + return list_domains().select{ |d| !db_domains.include?(d) } end def get_leftover_users(db_users) # Given a list of users, determine which users belonging to # this plugin are not contained in the given list. - raise NotImplementedError + + # WARNING! Array difference doesn't work for some reason. + return list_users().select{ |u| !db_users.include?(u) } end end