]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/rm/rm_plugin.rb
Clean up user/domain describing in the plugins.
[mailshears.git] / lib / rm / rm_plugin.rb
index e2f2cfe413278bba00a1f0a572451b32fd6936a7..fd0c541a44cb25ed7ffbe7e96db3c19b59426265 100644 (file)
@@ -1,39 +1,48 @@
+require 'common/plugin.rb'
+
 module RmPlugin
   #
-  # Plugins for the removal of accounts.
+  # Plugins for the removal of users.
   #
 
-  def RmPlugin.included(c)
-    # Callback, called whenever another class or module includes this
-    # one. The parameter given is the name of the class or module
-    # that included us.
-    @includers ||= []
-    @includers << c
-  end
+  extend Plugin::Run
 
-  def RmPlugin.includers
-    return @includers
+  def self.runner()
+    return RmRunner
   end
 
-  def delete_domain(domain)
-    # Delete the given domain.
-    raise NotImplementedError
+  def self.dummy_runner()
+    return RmDummyRunner
   end
 
-  def delete_account(account)
-    # Delete the given account.
-    raise NotImplementedError
+  def delete(target)
+    # A generic version of delete_user/delete_domain that
+    # dispatches base on the class of the target.
+    if target.is_a?(User)
+      return delete_user(target)
+    elsif target.is_a?(Domain)
+      return delete_domain(target)
+    else
+      raise NotImplementedError
+    end
   end
 
-  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
+  def delete_domain(domain)
+    # Delete the given domain. Some plugins don't have a concept of
+    # domains, so just delete all users with a username that looks
+    # like it's in the given domain.
+    users = list_domains_users([domain])
+
+    raise NonexistentDomainError.new(domain.to_s()) if users.empty?
+
+    users.each do |u|
+      delete_user(u)
+    end
   end
 
-  def get_leftover_accounts(db_accounts)
-    # Given a list of accounts, determine which accounts belonging to
-    # this plugin are not contained in the given list.
+  def delete_user(user)
+    # Delete the given user.
     raise NotImplementedError
   end
+
 end