[Xfce4-commits] <moka:master> Make administration easier.

Nick Schermer noreply at xfce.org
Sun Nov 20 14:30:30 CET 2011


Updating branch refs/heads/master
         to 1940bbc1366d6fd697c540b124e2477a97636e86 (commit)
       from bfa876ab3d6d23c883af53197c77675d49d1d82c (commit)

commit 1940bbc1366d6fd697c540b124e2477a97636e86
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 9 18:22:22 2011 +0200

    Make administration easier.

 lib/controllers/maintainers.rb    |   44 +++++++++++++++++--------
 lib/views/maintainer.haml         |    5 ++-
 lib/views/maintainer_profile.haml |   64 +++++++++++++++++++++++++------------
 lib/views/stylesheet.sass         |    3 ++
 4 files changed, 80 insertions(+), 36 deletions(-)

diff --git a/lib/controllers/maintainers.rb b/lib/controllers/maintainers.rb
index 2162a78..cc4e9eb 100755
--- a/lib/controllers/maintainers.rb
+++ b/lib/controllers/maintainers.rb
@@ -39,10 +39,6 @@ module Moka
               pubkeys.push(key) if not key.empty? and key.start_with? "ssh-"
             end
 
-            if authentication_user.is_admin
-              @maintainer.active = params[:active] ? true : false
-            end
-
             @maintainer.email = params[:email]
             @maintainer.realname = params[:realname]
             @maintainer.pubkeys = pubkeys.join("\n")
@@ -60,38 +56,58 @@ module Moka
           view :maintainer_profile
         end
 
-        app.post '/maintainer/:name/permissions' do
-          @maintainer = Maintainer.get(params[:name])
+        app.post '/maintainer/:name/activate' do
+          authentication_required
+
+          maintainer = Maintainer.get(params[:name])
+          if maintainer
+            maintainer.active = !maintainer.active
+            maintainer.save
+          end
+
+          redirect "/maintainer/#{params[:name]}"
+        end
+
+        app.post '/maintainer/:name/delete' do
+          authentication_required
+
+          maintainer = Maintainer.get(params[:name])
+          maintainer.destroy if maintainer and not maintainer.active
 
+          view :maintainer
+        end
+
+        app.post '/maintainer/:name/permissions' do
           authentication_required
 
-          @maintainer.roles.clear
+          maintainer = Maintainer.get(params[:name])
+          maintainer.roles.clear
           if params[:roles]
             for name in params[:roles].keys do
               role = Role.get(name)
-              @maintainer.roles << role
+              maintainer.roles << role
             end
           end
 
-          @maintainer.collections.clear
+          maintainer.collections.clear
           if params[:collections]
             for name in params[:collections].keys do
               collection = Collection.get(name)
-              @maintainer.collections << collection
+              maintainer.collections << collection
             end
           end
 
-          @maintainer.projects.clear
+          maintainer.projects.clear
           if params[:projects]
             for name in params[:projects].keys do
               project = Project.get(name)
-              @maintainer.projects << project
+              maintainer.projects << project
             end
           end
 
-          @maintainer.save
+          maintainer.save
 
-          redirect "/maintainer/#{@maintainer.username}"
+          redirect "/maintainer/#{maintainer.username}"
         end
       end
     end
diff --git a/lib/views/maintainer.haml b/lib/views/maintainer.haml
index fbc4679..7f599d2 100644
--- a/lib/views/maintainer.haml
+++ b/lib/views/maintainer.haml
@@ -14,7 +14,10 @@
       %td #{maintainer.email}
 
 %h2 Active Maintainers
-%p Accounts of the maintainers that are currently using the release manager.
+%p
+  Accounts of the maintainers that are currently using the release manager.
+  %b Bold
+  users have administration permission.
 
 %table
   %tr
diff --git a/lib/views/maintainer_profile.haml b/lib/views/maintainer_profile.haml
index 7726a1d..d716a24 100644
--- a/lib/views/maintainer_profile.haml
+++ b/lib/views/maintainer_profile.haml
@@ -1,4 +1,26 @@
-%h2 Account data
+:javascript
+  function info_submit()
+  {
+    var field = document.getElementById('infopass');
+    document.getElementById('infosubmit').disabled = !(field.value.length > 0);
+  }
+  function admin_delete()
+  {
+    var result = confirm ("Are you sure you want to delete #{@maintainer.username}?");
+    return result
+  }
+
+- if authentication_user.is_admin
+  %h2 Administrator
+  %form{:method => "post", :class => "admintasks", :action => "/maintainer/#{@maintainer.username}/activate" }
+    %input{:type => "submit",
+           :value => @maintainer.active ? "Deactivate" : "Activate" }
+  %form{:method => "post", :class => "admintasks", :action => "/maintainer/#{@maintainer.username}/delete" }
+    %input{:type => "submit", :value => "Delete",
+           :disabled => @maintainer.active,
+           :onclick => "return admin_delete()" }
+
+%h2 Account Information
 %form{:method => "post"}
   %p
     %label{:for => "username"} Login Name:
@@ -7,10 +29,6 @@
   %p
     %label{:for => "email"} Email address:
     %input{:type => "text", :name => "email", :value => @maintainer.email}
-  - if authentication_user.is_admin
-    %p
-      %label{:for => "active"} Account active:
-      %input{:type => "checkbox", :name => "active", :checked => @maintainer.active}
   %p
     %label{:for => "realname"} Real Name:
     %input{:type => "text", :name => "realname", :value => @maintainer.realname}
@@ -18,29 +36,33 @@
     %label{:for => "pubkeys"} SSH public-keys:
     %textarea{:name => "pubkeys", :rows => "5", :wrap => "off"}
       #{@maintainer.pubkeys}
-    %br
-    Each line of the public keys should start with ssh-dsa or ssh-rsa else the key is not saved.
-  %hr
-  %p 
-    Leave the password fields empty if you don't want to set a new password. 
-    The password needs to be at least 6 characters long.
-  - if env[:error][:newpassword]
-    %p.error.quote #{env[:error][:newpassword]}
-  %p
-    %label{:for => "new_password"} New password:
-    %input{:type => "password", :name => "newpassword"}
-  %p
-    %label{:for => "new_password2"} Confirm new password:
-    %input{:type => "password", :name => "newpassword2"}
+  %p.info
+    Each line of the public keys should start with ssh-dsa or ssh-rsa else
+    the key is not saved. Updating the keys on the server can take up to 1
+    hour, so please be patient after updating the keys.
+
+  - if authentication_user.eql? @maintainer
+    %hr
+    %p
+      Leave the password fields empty if you don't want to set a new password.
+      The password needs to be at least 6 characters long.
+    - if env[:error][:newpassword]
+      %p.error.quote #{env[:error][:newpassword]}
+    %p
+      %label{:for => "new_password"} New password:
+      %input{:type => "password", :name => "newpassword" }
+    %p
+      %label{:for => "new_password2"} Confirm new password:
+      %input{:type => "password", :name => "newpassword2"}
   %hr
   %p Please enter your existing password to confirm account changes.
   - if env[:error][:password]
     %p.error.quote #{env[:error][:password]}
   %p
     %label{:for => "password"} Password:
-    %input{:type => "password", :name => "password"}
+    %input{:type => "password", :name => "password", :id => "infopass", :onkeyup => "info_submit()" }
   %p
-    %input{:type => "submit", :value => "Save"}
+    %input{:type => "submit", :value => "Save", :id => "infosubmit", :disabled => true }
 
 %h2 Permissions
 %form{:method => "post", :action => "/maintainer/#{@maintainer.username}/permissions" }
diff --git a/lib/views/stylesheet.sass b/lib/views/stylesheet.sass
index b24112c..2d7920a 100755
--- a/lib/views/stylesheet.sass
+++ b/lib/views/stylesheet.sass
@@ -94,6 +94,9 @@ form
   p
     padding: 0.25em
 
+form.admintasks
+  display: inline
+
 fieldset
   border: 0em
   padding: 0em


More information about the Xfce4-commits mailing list