]> git.openstreetmap.org Git - rails.git/commitdiff
Add a user list view for administrators
authorTom Hughes <tom@compton.nu>
Tue, 4 May 2010 13:44:28 +0000 (14:44 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 6 May 2010 19:55:02 +0000 (20:55 +0100)
app/controllers/user_controller.rb
app/views/user/_user.html.erb [new file with mode: 0644]
app/views/user/list.html.erb [new file with mode: 0644]
config/locales/en.yml
config/routes.rb
public/stylesheets/common.css

index af0ccba055eef8824a59b0441f5f3e5603ca4a33..e5db74f38ee9c019701fa7db53836d00cf94210b 100644 (file)
@@ -11,7 +11,7 @@ class UserController < ApplicationController
   before_filter :require_allow_read_prefs, :only => [:api_details]
   before_filter :require_allow_read_gpx, :only => [:api_gpx_files]
   before_filter :require_cookies, :only => [:login, :confirm]
   before_filter :require_allow_read_prefs, :only => [:api_details]
   before_filter :require_allow_read_gpx, :only => [:api_gpx_files]
   before_filter :require_cookies, :only => [:login, :confirm]
-  before_filter :require_administrator, :only => [:set_status, :delete]
+  before_filter :require_administrator, :only => [:set_status, :delete, :list]
   before_filter :lookup_this_user, :only => [:set_status, :delete]
 
   filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
   before_filter :lookup_this_user, :only => [:set_status, :delete]
 
   filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
@@ -328,14 +328,43 @@ class UserController < ApplicationController
     @this_user.delete
     redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
   end
     @this_user.delete
     redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
   end
+
+  ##
+  # display a list of users matching specified criteria
+  def list
+    if request.post?
+      ids = params[:user].keys.collect { |id| id.to_i }
+
+      User.update_all("status = 'confirmed'", :id => ids) if params[:confirm]
+      User.update_all("status = 'deleted'", :id => ids) if params[:hide]
+    end
+
+    conditions = Hash.new
+    conditions[:status] = params[:status] if params[:status]
+    conditions[:creation_ip] = params[:ip] if params[:ip]
+
+    @user_pages, @users = paginate(:users,
+                                   :conditions => conditions,
+                                   :order => :id,
+                                   :per_page => 50)
+  end
+
 private
 private
+
   ##
   # require that the user is a administrator, or fill out a helpful error message
   # and return them to the user page.
   def require_administrator
   ##
   # require that the user is a administrator, or fill out a helpful error message
   # and return them to the user page.
   def require_administrator
-    unless @user.administrator?
+    if @user and not @user.administrator?
       flash[:error] = t('user.filter.not_an_administrator')
       flash[:error] = t('user.filter.not_an_administrator')
-      redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
+
+      if params[:display_name]
+        redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name]
+      else
+        redirect_to :controller => 'user', :action => 'login', :referer => request.request_uri
+      end
+    elsif not @user
+      redirect_to :controller => 'user', :action => 'login', :referer => request.request_uri
     end
   end
 
     end
   end
 
diff --git a/app/views/user/_user.html.erb b/app/views/user/_user.html.erb
new file mode 100644 (file)
index 0000000..66f6cd3
--- /dev/null
@@ -0,0 +1,20 @@
+<% cl = cycle('table0', 'table1') %>
+
+<tr class="<%= cl %>">
+  <td>
+    <%= user_thumbnail(user) %>
+  </td>
+  <td>
+    <p>
+      <%= t 'user.list.summary',
+          :name => h(user.display_name),
+          :ip_address => link_to(user.creation_ip, :ip => user.creation_ip),
+          :date => l(user.creation_time, :format => :friendly)
+      %>
+    </p>
+    <%= htmlize(user.description) %>
+  </td>
+  <td>
+    <%= check_box_tag "user_#{user.id}", "", false, :name => "user[#{user.id}]" %>
+  </td>
+</tr>
diff --git a/app/views/user/list.html.erb b/app/views/user/list.html.erb
new file mode 100644 (file)
index 0000000..6f010e2
--- /dev/null
@@ -0,0 +1,40 @@
+<% @title = t('user.list.title') %>
+
+<h1><%= t('user.list.heading') %></h1>
+
+<% unless @users.empty? %>
+  <% form_tag :status => params[:status], :ip => params[:ip] do %>
+    <table id="user_list">
+      <tr>
+        <td colspan="2">
+          <%= t 'user.list.showing',
+              :page => @user_pages.current_page.number,
+              :first_item => @user_pages.current_page.first_item,
+              :last_item => @user_pages.current_page.last_item,
+              :count => @user_pages.current_page.last_item - @user_pages.current_page.first_item + 1
+          %>
+          <% if @user_pages.page_count > 1 %>
+          | <%= pagination_links_each(@user_pages, {}) { |n| link_to n, :page => n } %>
+          <% end %>
+        </td>
+        <td>
+          <%=
+            check_box_tag("user_all", "1", false, :onchange => update_page do |page|
+              @users.each do |user|
+                page << "$('user_#{user.id}').checked = $('user_all').checked;"
+              end
+            end)
+          %>
+        </td>
+      </tr>
+      <%= render :partial => 'user', :collection => @users %>
+    </table>
+
+    <div id="user_list_actions">
+      <%= submit_tag t('user.list.confirm'), :name => "confirm" %>
+      <%= submit_tag t('user.list.hide'), :name => "hide" %>
+    </div>
+  <% end %>
+<% else %>
+  <p><%= t "user.list.empty" %></p>
+<% end %>
index 21e5795cb8f5f90a0aea5af89370436403e9af13..e521299e722f332a81a974809c5bee4ceaab5266 100644 (file)
@@ -1644,6 +1644,16 @@ en:
       not_a_friend: "{{name}} is not one of your friends."
     filter:
       not_an_administrator: "You need to be an administrator to perform that action."
       not_a_friend: "{{name}} is not one of your friends."
     filter:
       not_an_administrator: "You need to be an administrator to perform that action."
+    list:
+      title: Users
+      heading: Users
+      showing:
+        one: Showing page {{page}} ({{first_item}} of {{count}})
+        other: Showing page {{page}} ({{first_item}}-{{last_item}} of {{count}})
+      summary: "{{name}} created from {{ip_address}} on {{date}}"
+      confirm: Confirm Selected Users
+      hide: Hide Selected Users
+      empty: No matching users found
   user_role:
     filter:
       not_an_administrator: "Only administrators can perform user role management, and you are not an administrator."
   user_role:
     filter:
       not_an_administrator: "Only administrators can perform user role management, and you are not an administrator."
index 82f4e3a9fb49391f8279cc2a85731abfa48a5d89..b15d77e31c20f803e2025334c2517a4cd1baf86d 100644 (file)
@@ -166,7 +166,10 @@ ActionController::Routing::Routes.draw do |map|
   map.connect '/diary/:language', :controller => 'diary_entry', :action => 'list'
   map.connect '/diary/:language/rss', :controller => 'diary_entry', :action => 'rss'
 
   map.connect '/diary/:language', :controller => 'diary_entry', :action => 'list'
   map.connect '/diary/:language/rss', :controller => 'diary_entry', :action => 'rss'
 
-  
+  # user lists
+  map.connect '/users', :controller => 'user', :action => 'list'
+  map.connect '/users/:status', :controller => 'user', :action => 'list'
+
   # test pages
   map.connect '/test/populate/:table/:from/:count', :controller => 'test', :action => 'populate'
   map.connect '/test/populate/:table/:count', :controller => 'test', :action => 'populate', :from => 1
   # test pages
   map.connect '/test/populate/:table/:from/:count', :controller => 'test', :action => 'populate'
   map.connect '/test/populate/:table/:count', :controller => 'test', :action => 'populate', :from => 1
index b6ee997125b7d98e04aa810ef81b756db7b41bcd..73f0fb788b1e4391c614c6ed4f78d28b702e2b79 100644 (file)
@@ -562,6 +562,27 @@ hr {
   color: gray;
 }
 
   color: gray;
 }
 
+/* Rules for the user list */
+
+#user_list {
+  width: 100%;
+  font-size: small;
+}
+
+#user_list tr {
+  vertical-align: center;
+}
+
+#user_list p {
+  margin-top: 0px;
+  margin-bottom: 0px;
+}
+
+#user_list_actions {
+  float: right;
+  margin-top: 10px;
+}
+
 /* Rules for the account settings page */
 
 #accountForm td {
 /* Rules for the account settings page */
 
 #accountForm td {