Add a user list view for administrators
This commit is contained in:
parent
5d3992daca
commit
ae8c0b3baf
6 changed files with 127 additions and 4 deletions
|
@ -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_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
|
||||
|
@ -328,14 +328,43 @@ class UserController < ApplicationController
|
|||
@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
|
||||
|
||||
##
|
||||
# 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')
|
||||
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
|
||||
|
||||
|
|
20
app/views/user/_user.html.erb
Normal file
20
app/views/user/_user.html.erb
Normal file
|
@ -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>
|
40
app/views/user/list.html.erb
Normal file
40
app/views/user/list.html.erb
Normal file
|
@ -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 %>
|
|
@ -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."
|
||||
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."
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
||||
# 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
|
||||
|
|
|
@ -562,6 +562,27 @@ hr {
|
|||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue