Project

General

Profile

Feature #242 ยป SearchAndEditUsers.patch

Ron Monson, 2008-02-03 11:01

View differences:

app/controllers/my_controller.rb (working copy)
17 17

  
18 18
class MyController < ApplicationController
19 19
  helper :issues
20
  helper :custom_fields
21
  include CustomFieldsHelper 
20 22
  
21 23
  layout 'base'
22 24
  before_filter :require_login
......
52 54
  def account
53 55
    @user = User.current
54 56
    @pref = @user.pref
57
    if request.get?
58
      @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) }
59
    else
60
      @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]) }
61
      @user.custom_values = @custom_values
62
    end
55 63
    if request.post?
56 64
      @user.attributes = params[:user]
57 65
      @user.mail_notification = (params[:notification_option] == 'all')
app/controllers/search_controller.rb (working copy)
43 43
    
44 44
    if @project
45 45
      # only show what the user is allowed to view
46
      @object_types = %w(issues news documents changesets wiki_pages messages)
46
      @object_types = %w(issues news documents changesets wiki_pages messages users)
47 47
      @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
48
      
48
      @object_types += %w(users) #this is probably better fixed in User.current.allowed_to
49 49
      @scope = @object_types.select {|t| params[t]}
50 50
      @scope = @object_types if @scope.empty?
51 51
    else
52
      @object_types = @scope = %w(projects)
52
      @object_types = @scope = %w(projects users)
53 53
    end
54 54
    
55 55
    # extract tokens from the question
......
94 94
                                 :limit => limit,
95 95
                                 :conditions => [ (["(#{Project.visible_by(User.current)}) AND (LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
96 96
                                 ) if @scope.include? 'projects'
97
        # if only one project is found, user is redirected to its overview
98
        redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
97
        @projectCount = @results.size
98
        @results += User.find(:all, 
99
                               :limit => limit,
100
                               :conditions => [ (["(LOWER(firstname) like ? OR LOWER(lastname) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort]
101
                               ) if @scope.include? 'users'
102
        @userCount = @results.size - @projectCount
103
        # if only one project/user is found, user is redirected to its overview
104
        redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1 and @projectCount == 1
105
        redirect_to :controller => 'users', :action => 'show', :id => @results.first and return if @results.size == 1 and @userCount == 1
99 106
      end
100 107
    else
101 108
      @question = ""
app/controllers/users_controller.rb (working copy)
48 48

  
49 49
    render :action => "list", :layout => false if request.xhr?	
50 50
  end
51
  
52
  def show
53
    @user = User.find(params[:id])
54
    @custom_values = @user.custom_values.find(:all, :include => :custom_field)
55
    
56
    # show only public projects and private projects that the logged in user is also a member of
57
    @memberships = @user.memberships.select do |membership|
58
      membership.project.is_public? || (User.current.role_for_project(membership.project))
59
    end
60
  rescue ActiveRecord::RecordNotFound
61
    render_404
62
  end
51 63

  
52 64
  def add
53 65
    if request.get?
app/models/user.rb (working copy)
32 32
  has_one :rss_token, :dependent => :destroy, :class_name => 'Token', :conditions => "action='feeds'"
33 33
  belongs_to :auth_source
34 34
  
35
  acts_as_searchable :columns => ['firstname', 'lastname'],
36
                     :include => :memberships,
37
                     :include => :projects,
38
                     :project_key => "#{Project.table_name}.id"
39
  acts_as_event :title => Proc.new {|o| "#{l(:field_name)}: #{o.firstname} #{o.lastname}"},
40
                :description => :mail,
41
                :url => Proc.new {|o| {:controller => 'users', :action => 'show', :id => o.id}}
42
  
35 43
  attr_accessor :password, :password_confirmation
36 44
  attr_accessor :last_before_login_on
37 45
  # Prevents unauthorized assignments
app/views/my/account.rhtml (working copy)
20 20
<p><%= pref_fields.select :time_zone, TimeZone.all.collect {|z| [ z.to_s, z.name ]}, :include_blank => true %></p>
21 21
<p><%= pref_fields.check_box :hide_mail %></p>
22 22
<% end %>
23

  
24
<% for @custom_value in @custom_values %>
25
	<p><%= custom_field_tag_with_label @custom_value %></p>
26
<% end if @custom_values%>
23 27
</div>
24 28

  
25 29
<%= submit_tag l(:button_save) %>
app/views/users/show.rhtml (revision 0)
1
<h2><%=h @user.name %></h2>
2

  
3
<p>
4
<%=l(:field_name)%>: <%= @user.firstname %> <%= @user.lastname%><br/>
5
<%=l(:field_mail)%>: <%= mail_to @user.mail unless @user.pref.hide_mail %><br/>
6
<%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %><br/>
7
</p>
8

  
9
<p>
10
<% for custom_value in @custom_values %>
11
<% if !custom_value.value.empty? %>
12
    <%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %><br/>
13
<% end %>
14
<% end %>
15
</p>
16

  
    (1-1/1)