X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Frm%2Frm_plugin.rb;h=ff165b4e8081c653c047276a5fb7045ba9a0d938;hp=0c155a18f9441521d1ee3a6c9445927c19bd022a;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=ec3c9099a29f40d95f055ea0f7fb25a99d913de3 diff --git a/lib/rm/rm_plugin.rb b/lib/rm/rm_plugin.rb index 0c155a1..ff165b4 100644 --- a/lib/rm/rm_plugin.rb +++ b/lib/rm/rm_plugin.rb @@ -1,27 +1,77 @@ +require 'common/plugin.rb' + +# +# Plugins for the removal of users and domains. +# module RmPlugin + + # Absorb the subclass run() magic from the Plugin::Run module. + extend Plugin::Run + + # The runner class associated with removal plugins. # - # Plugins for the removal of accounts. + # @return [Class] the {RmRunner} class. # + def self.runner() + return RmRunner + end - def delete_domain(domain) - # Delete the given domain. - raise NotImplementedError + + # The "dummy" runner class associated with removal plugins. + # + # @return [Class] the {RmDummyRunner} class. + # + def self.dummy_runner() + return RmDummyRunner end - def delete_account(account) - # Delete the given account. - raise NotImplementedError + + # Remove the *target* domain or user. This is a generic version of + # the {#remove_user} and {#remove_domain} operations that will + # dispatch based on the type of *target*. + # + # @param target [User,Domain] the user or domain to remove. + # + def remove(target) + # A generic version of remove_user/remove_domain that + # dispatches base on the class of the target. + if target.is_a?(User) + return remove_user(target) + elsif target.is_a?(Domain) + return remove_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 + + # Remove the given *domain*. Some plugins don't have a concept of + # domains, so the default implementation here removes all users that + # look like they belong to *domain*. Subclasses can be smarter. + # + # @param domain [Domain] the domain to remove. + # + def remove_domain(domain) + users = list_domains_users([domain]) + + # It's possible for a domain to exist with no users, but this + # default implementation is based on the assumption that it should + # work for plugins having no "domain" concept. + raise NonexistentDomainError.new(domain.to_s()) if users.empty? + + users.each do |u| + remove_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. + + # The interface for the "remove a user" operation. Subclasses + # need to implement this method so that it removes *user*. + # + # @param user [User] the user to remove. + # + def remove_user(user) raise NotImplementedError end + end