Project

General

Profile

Feature #242 ยป SearchAndEditUsers.patch

Ron Monson, 2008-02-03 11:01

View differences:

app/controllers/my_controller.rb (working copy)
class MyController < ApplicationController
helper :issues
helper :custom_fields
include CustomFieldsHelper
layout 'base'
before_filter :require_login
......
def account
@user = User.current
@pref = @user.pref
if request.get?
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| @user.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
else
@custom_values = UserCustomField.find(:all, :order => "#{CustomField.table_name}.position").collect { |x| CustomValue.new(:custom_field => x, :customized => @user, :value => params["custom_fields"][x.id.to_s]) }
@user.custom_values = @custom_values
end
if request.post?
@user.attributes = params[:user]
@user.mail_notification = (params[:notification_option] == 'all')
app/controllers/search_controller.rb (working copy)
if @project
# only show what the user is allowed to view
@object_types = %w(issues news documents changesets wiki_pages messages)
@object_types = %w(issues news documents changesets wiki_pages messages users)
@object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
@object_types += %w(users) #this is probably better fixed in User.current.allowed_to
@scope = @object_types.select {|t| params[t]}
@scope = @object_types if @scope.empty?
else
@object_types = @scope = %w(projects)
@object_types = @scope = %w(projects users)
end
# extract tokens from the question
......
:limit => limit,
:conditions => [ (["(#{Project.visible_by(User.current)}) AND (LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
) if @scope.include? 'projects'
# if only one project is found, user is redirected to its overview
redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
@projectCount = @results.size
@results += User.find(:all,
:limit => limit,
:conditions => [ (["(LOWER(firstname) like ? OR LOWER(lastname) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
) if @scope.include? 'users'
@userCount = @results.size - @projectCount
# if only one project/user is found, user is redirected to its overview
redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1 and @projectCount == 1
redirect_to :controller => 'users', :action => 'show', :id => @results.first and return if @results.size == 1 and @userCount == 1
end
else
@question = ""
app/controllers/users_controller.rb (working copy)
render :action => "list", :layout => false if request.xhr?
end
def show
@user = User.find(params[:id])
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
# show only public projects and private projects that the logged in user is also a member of
@memberships = @user.memberships.select do |membership|
membership.project.is_public? || (User.current.role_for_project(membership.project))
end
rescue ActiveRecord::RecordNotFound
render_404
end
def add
if request.get?
app/models/user.rb (working copy)
has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
belongs_to :auth_source
acts_as_searchable :columns => ['firstname', 'lastname'],
:include => :memberships,
:include => :projects,
:project_key => "#{Project.table_name}.id"
acts_as_event :title => Proc.new {|o| "#{l(:field_name)}: #{o.firstname} #{o.lastname}"},
:description => :mail,
:url => Proc.new {|o| {:controller => 'users', :action => 'show', :id => o.id}}
attr_accessor :password, :password_confirmation
attr_accessor :last_before_login_on
# Prevents unauthorized assignments
app/views/my/account.rhtml (working copy)
<p><%= pref_fields.select :time_zone, TimeZone.all.collect {|z| [ z.to_s, z.name ]}, :include_blank => true %></p>
<p><%= pref_fields.check_box :hide_mail %></p>
<% end %>
<% for @custom_value in @custom_values %>
<p><%= custom_field_tag_with_label @custom_value %></p>
<% end if @custom_values%>
</div>
<%= submit_tag l(:button_save) %>
app/views/users/show.rhtml (revision 0)
<h2><%=h @user.name %></h2>
<p>
<%=l(:field_name)%>: <%= @user.firstname %> <%= @user.lastname%><br/>
<%=l(:field_mail)%>: <%= mail_to @user.mail unless @user.pref.hide_mail %><br/>
<%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %><br/>
</p>
<p>
<% for custom_value in @custom_values %>
<% if !custom_value.value.empty? %>
<%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %><br/>
<% end %>
<% end %>
</p>
    (1-1/1)