X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_runner.rb;h=6da6f6d3bb7fd6311d6e27915d5c10d230f981f1;hp=ee762e1e70cf4198c1630b3404973d20c75ac264;hb=f819b178c5c1cb8adda0182c610e5c52fad8bea7;hpb=1d7d65c9583a879358de36ab1ac26b35a2805ba8 diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index ee762e1..6da6f6d 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -1,3 +1,4 @@ +require 'common/domain' require 'common/errors' require 'common/runner' @@ -5,35 +6,50 @@ class MvRunner include Runner def run(plugin, src, dst) - # Why think too hard? An user has an @, a domain doesn't. - if not src.include?('@') then - # We only support moving users right now, and the destination - # domain must already exist. - raise NotImplementedError.new('Only users can be moved.') - end - # Handle this once so we don't have to do it in every plugin. - if not dst.include?('@') then - msg = "the destination user #{dst} is not valid" - raise InvalidUserError.new(msg) + 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_user(src) + src_description = plugin.describe(src) plugin.mv_user(src, dst) - msg = "Moved user #{src} (#{src_description}) " - msg += "to #{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 InvalidUserError => e - report(plugin, e.message) + rescue NonexistentUserError => e - report(plugin, e.message) + # 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 - report(plugin, e.message) - rescue StandardError => e - msg = "There was an error (#{e.to_s}) moving the user: #{e.message}" - report(plugin, msg) - Kernel.exit(ExitCodes::DATABASE_ERROR) + # 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