--- /tmp/s080811/samizdat/lib/samizdat/plugins/role.rb	2008-05-11 16:41:34.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/plugins/role.rb	2008-08-29 00:39:15.000000000 +0200
@@ -50,6 +50,29 @@
     end
   end
 
+
+  # any moderator can set or unset moderator rights of any other
+  # member, independently of all other privilege settings
+  def set_moderator_status(subject,object,set=true)
+    return if not subject.kind_of? Member or
+        not object.kind_of? Member or
+      not subject.id.kind_of? Integer or
+      not object.id.kind_of? Integer
+
+    if subject.allowed_to? 'moderate' 
+      db.transaction do |db|
+        if (not object.allowed_to?('moderate')) and set
+          db.do(%{INSERT INTO Role VALUES (?, 'moderator') }, 
+                object.id)
+        elsif object.allowed_to?('moderate') and not set
+          db.do(%{DELETE FROM Role where member = ? and role = ?}, 
+                object.id,'moderator')
+        end
+      end 
+      object = Member.new(object.id)
+    end
+  end
+
   private
 
   def gettext_hack
--- /tmp/s080811/samizdat/lib/samizdat/components/resource.rb	2008-08-07 19:22:04.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/components/resource.rb	2008-08-28 23:42:14.000000000 +0200
@@ -387,13 +387,23 @@
   end
 
   def buttons
+    b='<div class="foot">'
     if @request.moderate? and not Member.cached(@id).allowed_to?('moderate')
       # show block/unblock button
-      %{<div class="foot"><a class="moderator_action" href="member/#{@id}/} <<
+      b += %{<a class="moderator_action" href="member/#{@id}/} <<
         (@blocked ? 'unblock' : 'block') << '">' <<
         (@blocked ? _('UNBLOCK') : _('BLOCK')) <<
-        %{</a></div>\n}
+        %{</a>\n}
     end
+    if @request.moderate? 
+      moderator = Member.cached(@id).allowed_to?('moderate')
+      log(sprintf("1. @id = %s, moderator = %s \n",@id.to_s,moderator.to_s)) # DEBUG ONLY #
+      b += %{<a class="moderator_action" href="member/#{@id}/} <<
+        (moderator ? 'unset_moderator' : 'set_moderator') << '">' <<
+        (moderator ? _('Disable moderator status') : _('Enable moderator status')) <<
+        %{</a>\n}
+    end
+    b << '</div>'
   end
 end
 
--- /tmp/s080811/samizdat/lib/samizdat/models/moderation.rb	2008-05-10 18:35:32.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/models/moderation.rb	2008-08-28 23:16:51.000000000 +0200
@@ -20,6 +20,8 @@
     'replace' => 'REPLACE',
     'block' => 'BLOCK',
     'unblock' => 'UNBLOCK',
+    'set_moderator' => 'Enable moderator status',
+    'unset_moderator' => 'Disable moderator status',
     'request' => 'Request Moderation',
     'acknowledge' => 'ACKNOWLEDGE'
   }
--- /tmp/s080811/samizdat/lib/samizdat/controllers/member_controller.rb	2008-08-07 16:43:41.000000000 +0200
+++ /usr/lib/ruby/1.8/samizdat/controllers/member_controller.rb	2008-08-29 00:16:12.000000000 +0200
@@ -276,6 +276,25 @@
     end
   end
 
+  def set_moderator
+    pre_moderate_generic('set_moderator')
+    log(sprintf("@session.member = %s, @id = %s\n",@session.member , @id )) # DEBUG ONLY #
+    config.plugins['access'].each do |plugin|
+      log(sprintf("plugin.class is: %s\n",plugin.class)) # DEBUG ONLY #
+      plugin.set_moderator_status(Member.cached(@session.member),Member.cached(@id),true)
+    end
+    log('got here.') # DEBUG ONLY #
+    post_moderate_generic('set_moderator')
+  end
+
+  def unset_moderator
+    pre_moderate_generic('unset_moderator')
+    config.plugins['access'].each do |plugin|
+      plugin.set_moderator_status(Member.cached(@session.member),Member.cached(@id),false)
+    end
+    post_moderate_generic('unset_moderator')
+  end
+
   private
 
   def assert_member
@@ -393,6 +412,19 @@
     end
   end
 
+  def pre_moderate_generic(action) # TODO: generalise moderate(action)
+    action = 'set_moderator'
+    assert_moderate
+    Resource.validate_id(@id) or raise ResourceNotFoundError, @id.to_s
+  end
+  
+  def post_moderate_generic(action) # TODO: generalise moderate(action)
+    log_moderation(action)
+    cache.flush
+    @request.redirect(@id)
+  end
+
+
   LOGIN_PATTERN = Regexp.new(/\A[a-z0-9]+\z/).freeze
   EMAIL_PATTERN = Regexp.new(/\A[[:alnum:]._-]+@[[:alnum:].-]+\z/).freeze
 
