+require 'common/domain'
+require 'common/user'
+
# All plugins should include this module. It defines the basic
# operations that all plugins are supposed to support.
module Plugin
end
def dummy_runner()
- # The RummyRunner associated with this plugin.
+ # The DummyRunner associated with this plugin.
raise NotImplementedError
end
end
end
+ def describe(target)
+ # 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)
+ elsif target.is_a?(Domain)
+ return describe_domain(target)
+ 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
raise NotImplementedError
end
- def user_exists(username)
+ 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
# exist above. Plugins can override this with something fast.
users = list_users()
- return users.include?(username)
+ return users.include?(user)
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
+ # Get all users belonging to the given domains. If a user has
+ # domainpart "example.com" then it belongs to the domain
+ # "example.com".
#
# This uses a naive loop, but relies only on the existence of a
# list_users() method which is guaranteed above. More efficient
# implementations can usually be made within the plugin.
domains_users = []
- usernames = list_users();
+ users = list_users();
domains.each do |d|
- matches = usernames.select do |username|
- username =~ /@#{d}$/
+ matches = users.select do |user|
+ user.domainpart() == d.to_s()
end
domains_users += matches