]> gitweb.michael.orlitzky.com - mailshears.git/blobdiff - lib/mv/mv_runner.rb
Overhaul everything to get consistent error reports.
[mailshears.git] / lib / mv / mv_runner.rb
index c7dbc5e7497147c90f40dbfb696474e11f5f8619..6da6f6d3bb7fd6311d6e27915d5c10d230f981f1 100644 (file)
@@ -1,10 +1,56 @@
+require 'common/domain'
+require 'common/errors'
 require 'common/runner'
 
 class MvRunner
   include Runner
 
   def run(plugin, src, dst)
-    puts "Not implemented"
+
+    if src.is_a?(Domain) or dst.is_a?(Domain) then
+      msg = 'only users can be moved'
+      raise NotImplementedError.new(msg)
+    end
+
+    begin
+      src_description = plugin.describe(src)
+      plugin.mv_user(src, dst)
+      dst_description = plugin.describe(dst)
+
+      msg  = "Moved 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)
+
+    rescue NonexistentUserError => e
+      # This means that the SOURCE user didn't exist, since a
+      # nonexistent destination user is perfectly expected.
+      report(plugin, "Source user #{src.to_s()} not found.")
+    rescue NonexistentDomainError => e
+      # This could mean that the source domain doesn't exist, but in
+      # that case, we just report that the source user doesn't
+      # exist. So a nonexistent domain refers to a nonexistent
+      # DESTINATION domain.
+      report(plugin, "Destination domain #{dst.domainpart()} not found.")
+    rescue UserAlreadyExistsError => e
+      report(plugin, "Destination user #{dst.to_s()} already exists.")
+    end
   end
 
 end