]> gitweb.michael.orlitzky.com - mailshears.git/commitdiff
Clean up user/domain describing in the plugins.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 2 Nov 2015 03:00:37 +0000 (22:00 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 2 Nov 2015 03:00:37 +0000 (22:00 -0500)
lib/common/agendav_plugin.rb
lib/common/davical_plugin.rb
lib/common/dovecot_plugin.rb
lib/common/plugin.rb
lib/common/postfixadmin_plugin.rb
lib/common/roundcube_plugin.rb
lib/mv/mv_dummy_runner.rb

index fc19d3d60fd45fccfec195ca745de1c0d7b5b3b5..032d057c24d8e25c899ea672ae5fca50a711a8ff 100644 (file)
@@ -18,15 +18,6 @@ module AgendavPlugin
   end
 
 
-  def describe_domain(domain)
-    return domain.to_s()
-  end
-
-  def describe_user(user)
-    return user.to_s()
-  end
-
-
   def list_users()
     #
     # Produce a list of AgenDAV users. This is public because it's
index 557c1dd1b3bf18e012cdf234e6400b05d4de7925..cd34a982529f70c09e156567e34cbcab97b7fc8e 100644 (file)
@@ -17,20 +17,9 @@ module DavicalPlugin
   end
 
 
-  def describe_domain(domain)
-    # DAViCal doesn't have a concept of domains.
-    return domain.to_s()
-  end
-
-
   def describe_user(user)
     principal_id = self.get_principal_id(user)
-
-    if principal_id.nil?
-      return 'User not found'
-    else
-      return "Principal ID: #{principal_id}"
-    end
+    return "Principal ID: #{principal_id}"
   end
 
 
index 4718483bec420e0e11731502597069300c816cb4..bc6166d6a1716ee7954083fb10460ad00e54b30d 100644 (file)
@@ -14,27 +14,11 @@ module DovecotPlugin
   end
 
   def describe_domain(domain)
-    begin
-      domain_path = get_domain_path(domain)
-      return domain_path
-    rescue NonexistentDomainError => e
-      return "Doesn't exist: #{e.to_s}"
-    end
+    return get_domain_path(domain)
   end
 
   def describe_user(user)
-    begin
-      user_path = get_user_path(user)
-      return user_path
-    rescue NonexistentUserError => e
-      return "Doesn't exist: #{e.to_s}"
-    end
-  end
-
-
-  def domain_exists(domain)
-    domains = list_domains()
-    return domains.include?(domain)
+    return get_user_path(user)
   end
 
 
index c6f750bc3f4d4c2f20e1c11c31f372e849afd711..702b621ff5da9c1ee18ccbd0fd29352950a63386 100644 (file)
@@ -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
index 60880d9e7bad17cf2298b4b0c9498d1007258039..b984f6cf66a5b2e5d66155124577f8c6a2c6eaef 100644 (file)
@@ -19,18 +19,6 @@ module PostfixadminPlugin
   end
 
 
-  def describe_user(user)
-    # There's no other unique identifier in PostfixAdmin
-    return user.to_s()
-  end
-
-
-  def describe_domain(domain)
-    # There's no other unique identifier in PostfixAdmin
-    return domain.to_s()
-  end
-
-
   def list_domains()
     domains = []
 
@@ -59,14 +47,6 @@ module PostfixadminPlugin
   end
 
 
-  def domain_exists(domain)
-    # Does the given domain exist in Postfixadmin? We use a naive
-    # implementation here based on list_domains(). This isn't in our
-    # superclass because not all plugins have a concept of domains.
-    domains = list_domains()
-    return domains.include?(domain)
-  end
-
 
   def list_users()
     users = []
index b1c74a6d7494420ea9908389317c9d03e39d64f9..eb450f00059d038776046dc7604417e1de3c367e 100644 (file)
@@ -17,19 +17,9 @@ module RoundcubePlugin
   end
 
 
-  def describe_domain(domain)
-    # Roundcube doesn't have a concept of domains.
-    return domain.to_s()
-  end
-
   def describe_user(user)
     user_id = self.get_user_id(user)
-
-    if user_id.nil?
-      return 'User not found'
-    else
-      return "User ID: #{user_id}"
-    end
+    return "User ID: #{user_id}"
   end
 
 
index 662abff73e89d1b176a97b4cea8d780415eec3bf..52db27be6f0082051ee17565c7ee7b8b5c61b31a 100644 (file)
@@ -10,7 +10,32 @@ class MvDummyRunner
       raise NotImplementedError.new(msg)
     end
 
-    puts "Would move user #{src.to_s()} to #{dst.to_s()}."
+    # Since we're not actually moving anything, the destination
+    # description is really only useful for seeing whether or not we'd
+    # be trying to move in on top of an existing account.
+    src_description = plugin.describe(src)
+    dst_description = plugin.describe(dst)
+
+    msg  = "Would move user #{src} "
+
+    # Only append the extra description if it's useful.
+    if not src_description.nil? and
+       not src_description.empty? and
+       not src_description == src.to_s() then
+      msg += "(#{src_description}) "
+    end
+
+    msg += "to #{dst}"
+
+    # Only append the extra description if it's useful.
+    if not dst_description.nil? and
+       not dst_description.empty? and
+       not dst_description == dst.to_s() then
+      msg += " (#{dst_description})"
+    end
+
+    msg += "."
+    report(plugin, msg)
   end
 
 end