X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fcommon%2Fplugin.rb;h=dba8becb2756c0324ecd252adb9b3602de218afb;hp=c6f750bc3f4d4c2f20e1c11c31f372e849afd711;hb=a731b98f97194b8882c42d3c2b27de75f60d6b05;hpb=f819b178c5c1cb8adda0182c610e5c52fad8bea7 diff --git a/lib/common/plugin.rb b/lib/common/plugin.rb index c6f750b..dba8bec 100644 --- a/lib/common/plugin.rb +++ b/lib/common/plugin.rb @@ -46,7 +46,7 @@ module Plugin # The splat passes the correct (we hope) number of arguments to the # appropriate runner. The Rm(Dummy)Runner have splats on their # *target arguments as well, to turn ARGV back into an array. - runner.run(plugin, *args) + runner.run(cfg, plugin, *args) end end end @@ -55,26 +55,36 @@ module Plugin # A generic version of describe_user/describe_domain that # dispatches base on the class of the target. if target.is_a?(User) - return describe_user(target) + if user_exists(target) then + return describe_user(target) + else + return 'User not found' + end elsif target.is_a?(Domain) - return describe_domain(target) + if domain_exists(target) then + return describe_domain(target) + else + return 'Domain not found' + end else raise NotImplementedError end end def describe_domain(domain) - # Provide a "description" of the domain. This is output along - # with the domain name and can be anything of use to the system - # administrator. - raise NotImplementedError + # Provide a "description" of the domain. This is output along with + # the domain name and can be anything of use to the system + # administrator. The default doesn't do anything useful and should + # be overridden. + return domain.to_s() end def describe_user(user) # Provide a "description" of the user. This is output along # with the domain name and can be anything of use to the system - # administrator. - raise NotImplementedError + # administrator. The default doesn't do anything useful and should + # be overridden. + return user.to_s() end def list_users() @@ -82,6 +92,14 @@ module Plugin raise NotImplementedError end + def list_domains() + # Compute the domains from a list of users. Obviously much worse + # than getting the domains the "smart" way, if such a way exists. + users = list_users() + domains = users.map{ |u| u.domain() } + return domains.uniq() + end + def user_exists(user) # Does the given username exist for this plugin? We use a naive # implementation here based on list_users() which is required to @@ -90,6 +108,14 @@ module Plugin return users.include?(user) end + def domain_exists(domain) + # Does the given domain exist for this plugin? We use a naive + # implementation here based on list_domains() which is required to + # exist above. Plugins can override this with something fast. + domains = list_domains() + return domains.include?(domain) + end + def list_domains_users(domains) # Get all users belonging to the given domains. If a user has # domainpart "example.com" then it belongs to the domain