X-Git-Url: http://gitweb.michael.orlitzky.com/?p=mailshears.git;a=blobdiff_plain;f=lib%2Fmv%2Fmv_runner.rb;h=fe44e5c244d3fe4cff66f140bb4d684ca903364a;hp=a0fa8e7ae6089e9899a7910b0355b3b12c7a14df;hb=df4e02ebf6a4e28a58abcb298a4442a245ad0b15;hpb=e3826d8926e11763837a591986d453e9ef5d9dec diff --git a/lib/mv/mv_runner.rb b/lib/mv/mv_runner.rb index a0fa8e7..fe44e5c 100644 --- a/lib/mv/mv_runner.rb +++ b/lib/mv/mv_runner.rb @@ -1,8 +1,70 @@ +require 'common/domain' +require 'common/errors' +require 'common/runner' + +# Perform the moving (renaming) of users/domains using {MvPlugin}s. +# class MvRunner include Runner - def run(plugin, src, dst) - puts "Not implemented" + # Run *plugin* to move the user *src* to *dst*. The method + # signature includes the unused *cfg* for consistency with the + # runners that do need a {Configuration}. + # + # @param cfg [Configuration] unused. + # + # @param plugin [Class] plugin class that will perform the move. + # + # @param src [User] the source user to be moved. + # + # @param dst [User] the destination user being moved to. + # + def run(cfg, plugin, src, dst) + + 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