* Make sure removing a domain updates the aliases table correctly.
-* Factor out all of the msg-building in e.g. MvRunner.
-
* Implement moving of domains.
end
+ # When we're describing a user or domain, we often want to output
+ # some additional description of it. But then, sometimes that
+ # additional description is pointless, like when it's exactly the
+ # same as the username that we're already outputting. This function
+ # determines whether or not *desc* is pointless for *target*.
+ #
+ # @param target [User,Domain] the user or domain described by *desc*.
+ #
+ # @param desc [String] a string description of *target*.
+ #
+ # @return [Boolean] true if *desc* is a pointless description of
+ # *target* and false otherwise.
+ #
+ def pointless?(target, desc)
+ return (desc.nil? or desc.empty? or desc == target.to_s())
+ end
+
+
+ # If *desc* is not a pointless description of *target*, return the
+ # string representation of *target* followed by *desc* in
+ # parentheses. If *desc* is pointless, we return only the string
+ # representation of *target*
+ #
+ # @param target [User,Domain] the user or domain we want to describe
+ # as a string.
+ #
+ # @param desc [String] a string description of *target*.
+ #
+ # @return [String] the string representation of *target*, possibly
+ # followed by the non-pointless description *desc*.
+ #
+ def add_description(target, desc)
+ if pointless?(target, desc)
+ return target.to_s()
+ else
+ return target.to_s() + " (#{desc})"
+ end
+ end
+
+
# Report a message from the given *plugin*. All this does is prefix
# the message with the plugin name and then print it to stdout.
#
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 = "Would move user "
+ msg += add_description(src, src_description)
+ msg += " to "
+ add_description(dst, dst_description)
msg += "."
report(plugin, msg)
end
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 = "Moved user "
+ msg += add_description(src, src_description)
+ msg += " to "
+ msg += add_description(dst, dst_description)
msg += "."
report(plugin, msg)
def run(cfg, plugin, *targets)
targets.each do |target|
target_description = plugin.describe(target)
- msg = "Would remove #{target.class.to_s().downcase()} #{target}"
-
- # Only append the extra description if it's useful.
- if not target_description.nil? and
- not target_description.empty? and
- not target_description == target.to_s() then
- msg += " (#{target_description})"
- end
+ msg = "Would remove #{target.class.to_s().downcase()} "
+ msg += add_description(target, target_description)
msg += '.'
report(plugin, msg)
begin
plugin.remove(target)
- msg = "Removed #{target.class.to_s().downcase()} #{target}"
-
- # Only append the extra description if it's useful.
- if not target_description.nil? and
- not target_description.empty? and
- not target_description == target.to_s() then
- msg += " (#{target_description})"
- end
+ msg = "Removed #{target.class.to_s().downcase()} "
+ msg += add_description(target, target_description)
msg += '.'
report(plugin, msg)