Merge pull request #55 from warpc/user_search_extending

Add nickname in user list
Add search by email
This commit is contained in:
Vladimir Sharshov 2011-12-15 13:44:47 -08:00
commit 9fa3d534b8
6 changed files with 85 additions and 2 deletions

View File

@ -7,7 +7,13 @@ class UsersController < ApplicationController
autocomplete :user, :uname
def index
@users = User.paginate(:page => params[:user_page])
@user = User.scoped
if !params[:filter].blank? && !params[:filter][:email].blank?
@users = @users.where(:email => params[:filter][:email])
@email = params[:filter][:email]
end
@users = @users.paginate(:page => params[:user_page])
@action_url = users_path
end
def show

View File

@ -0,0 +1,14 @@
%h2.title= t("layout.users.filter_header")
= form_for :filter, :url => @action_url, :html => { :method => :get, :class => :form } do |f|
.columns.wat-cf
.column.left
.group
= f.label :status, t("activerecord.attributes.users.email"), :class => :label
= f.text_field :email, :class => :text_field, :value => @email
.group.navform.wat-cf
%button.button{ :type => "submit" }
= image_tag("web-app-theme/icons/tick.png", :alt => "Save")
= t("layout.search")

View File

@ -6,11 +6,14 @@
.content
%h2.title
= t("layout.users.list_header")
.inner
= render :partial => "users/filter", :action_url => @action_url
.inner
%table.table
%tr
%th.first ID
%th= t("activerecord.attributes.user.name")
%th= t("activerecord.attributes.user.uname")
%th= t("activerecord.attributes.user.email")
%th= t("activerecord.attributes.user.role")
%th.last &nbsp;
@ -18,6 +21,7 @@
%tr{:class => cycle("odd", "even")}
%td= user.id
%td= link_to user.name, user_path(user)
%td= link_to user.uname, user_path(user)
%td= user.email
%td= user.role
%td.last

View File

@ -16,6 +16,11 @@
= t("activerecord.attributes.user.name")
\:
= @user.name
%p
%b
= t("activerecord.attributes.user.uname")
\:
= @user.uname
%p
%b
= t("activerecord.attributes.user.email")

View File

@ -259,6 +259,7 @@ ru:
confirm_delete: Вы уверены, что хотите удалить этого пользователя?
own_projects: Мои проекты
part_projects: Участвую в проектах
filter_header: Фильтр
git:
repositories:

View File

@ -1,5 +1,58 @@
require 'spec_helper'
describe UsersController do
shared_examples_for 'user with users list viewer rights' do
it 'should be able to perform index action' do
get :index
response.should render_template(:index)
end
it 'should assigns 5 users without filter params' do
get :index
assigns[:users].count.should == 5
end
it 'should find one user' do
get :index, :filter => {:email => "user1@nonexistanceserver.com"}
assigns[:users].size == 1
end
it 'should find user with searchable email' do
get :index, :filter => {:email => "user1@nonexistanceserver.com"}
assigns[:users].first.email.should == "user1@nonexistanceserver.com"
end
end
describe UsersController do
before(:each) do
stub_rsync_methods
@simple_user = Factory(:user)
@admin = Factory(:admin)
%w[user1 user2 user3].each do |uname|
Factory(:user, :uname => uname, :email => "#{ uname }@nonexistanceserver.com")
end
end
context 'for global admin' do
before(:each) do
set_session_for(@admin)
end
it_should_behave_like 'user with users list viewer rights'
end
context 'for guest' do
it 'should not be able to perform index action' do
get :index
response.should redirect_to(new_user_session_path)
end
end
context 'for simple user' do
before(:each) do
set_session_for(@simple_user)
end
it_should_behave_like 'user with users list viewer rights'
end
end