]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
auth core module: improve user destroy semantics
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 4 Dec 2007 20:27:49 +0000 (20:27 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 4 Dec 2007 20:27:49 +0000 (20:27 +0000)
lib/rbot/core/auth.rb

index d54e8177495c962f6b4aa38185ee12395692ba88..d321ad071c68615baa095227fd7305dd7df33c46 100644 (file)
@@ -295,7 +295,7 @@ class AuthModule < CoreBotModule
       when "list"\r
         return _("user list : lists all the botusers")\r
       when "destroy"\r
-        return _("user destroy <botuser> <password> : destroys <botuser>; this function %{highlight}must%{highlight} be called in two steps. On the first call, no password must be specified: <botuser> is then queued for destruction. On the second call, you must specify the correct password for <botuser>, and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy <botuser>+") % {:highlight => Bold}\r
+        return _("user destroy <botuser> : destroys <botuser>. This function %{highlight}must%{highlight} be called in two steps. On the first call <botuser> is queued for destruction. On the second call, which must be in the form 'user confirm destroy <botuser>', the botuser will be destroyed. If you want to cancel the destruction, issue the command 'user cancel destroy <botuser>'") % {:highlight => Bold}\r
       else\r
         return _("user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy")\r
       end\r
@@ -604,8 +604,7 @@ class AuthModule < CoreBotModule
     buname = params[:name]\r
     return m.reply(_("You can't destroy %{user}") % {:user => buname}) if\r
            ["everyone", "owner"].include?(buname)\r
-    cancel = m.message.split[1] == 'cancel'\r
-    password = params[:password]\r
+    mod = params[:modifier].to_sym rescue nil\r
 \r
     buser_array = @bot.auth.save_array\r
     buser_hash = buser_array.inject({}) { |h, u|\r
@@ -616,7 +615,8 @@ class AuthModule < CoreBotModule
     return m.reply(_("no such botuser %{user}") % {:user=>buname}) unless\r
            buser_hash.keys.include?(buname)\r
 \r
-    if cancel\r
+    case mod\r
+    when :cancel\r
       if @destroy_q.include?(buname)\r
         @destroy_q.delete(buname)\r
         m.reply(_("%{user} removed from the destruction queue") % {:user=>buname})\r
@@ -624,21 +624,17 @@ class AuthModule < CoreBotModule
         m.reply(_("%{user} was not queued for destruction") % {:user=>buname})\r
       end\r
       return\r
-    end\r
-\r
-    if password.nil?\r
+    when nil\r
       if @destroy_q.include?(buname)\r
-        return m.reply(_("%{user} already queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
+        return m.reply(_("%{user} already queued for destruction, use %{highlight}user confirm destroy %{user}%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
       else\r
         @destroy_q << buname\r
-        return m.reply(_("%{user} queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
+        return m.reply(_("%{user} queued for destruction, use %{highlight}user confirm destroy %{user}%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
       end\r
-    else\r
+    when :confirm\r
       begin\r
         return m.reply(_("%{user} is not queued for destruction yet") %\r
                {:user=>buname}) unless @destroy_q.include?(buname)\r
-        return m.reply(_("wrong password for %{user}") %\r
-               {:user=>buname}) unless buser_hash[buname][:password] == password\r
         buser_array.delete_if { |u|\r
           u[:username] == buname\r
         }\r
@@ -650,7 +646,6 @@ class AuthModule < CoreBotModule
       end\r
       return m.reply(_("botuser %{user} destroyed") % {:user => buname})\r
     end\r
-\r
   end\r
 \r
   def auth_copy_ren_user(m, params)\r
@@ -867,10 +862,11 @@ auth.map "user create :name :password",
   :defaults => {:password => nil},\r
   :auth_path => ':manage:'\r
 \r
-auth.map "user [cancel] destroy :name :password",\r
+auth.map "user [:modifier] destroy :name",\r
   :action => 'auth_destroy_user',\r
-  :defaults => { :password => nil },\r
-  :auth_path => ':manage::destroy:'\r
+  :requirements => { :modifier => /^(cancel|confirm)?$/ },\r
+  :defaults => { :modifier => '' },\r
+  :auth_path => ':manage::destroy!'\r
 \r
 auth.map "user copy :source [to] :dest",\r
   :action => 'auth_copy_ren_user',\r