Index: app/helpers/timelog_helper.rb =================================================================== --- app/helpers/timelog_helper.rb (revision 4702) +++ app/helpers/timelog_helper.rb (working copy) @@ -53,6 +53,17 @@ collection end + # Returns a collection of users for a select field. + def user_collection_for_select_options + users = @projects = User.find(:all) + collection = [] + users.each do |a| + roles = a.roles_for_project(@project) + collection << [a.name, a.id] if roles and roles.detect {|role| role.member? && role.allowed_to?(:log_time)} + end + collection + end + def select_hours(data, criteria, value) if value.to_s.empty? data.select {|row| row[criteria].blank? } Index: app/controllers/timelog_controller.rb =================================================================== --- app/controllers/timelog_controller.rb (revision 4702) +++ app/controllers/timelog_controller.rb (working copy) @@ -106,7 +106,13 @@ end def new - @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) + # Check if current user has permissions to edit time entries + if request.post? and User.current.allowed_to?(:edit_time_entries, @project) + user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) + else + user = User.current + end + @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today) @time_entry.attributes = params[:time_entry] call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) @@ -115,7 +121,13 @@ verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } def create - @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) + # Check if current user has permissions to edit time entries + if request.post? and User.current.allowed_to?(:edit_time_entries, @project) + user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) + else + user = User.current + end + @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today) @time_entry.attributes = params[:time_entry] call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) Index: app/views/timelog/edit.rhtml =================================================================== --- app/views/timelog/edit.rhtml (revision 4702) +++ app/views/timelog/edit.rhtml (working copy) @@ -11,6 +11,9 @@

<%= f.text_field :issue_id, :size => 6 %> <%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %>

+<% if User.current.allowed_to?(:edit_time_entries, @project) %> +

<%= f.select :user_id, user_collection_for_select_options, :required => true %>

+<% end %>

<%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %>

<%= f.text_field :hours, :size => 6, :required => true %>

<%= f.text_field :comments, :size => 100 %>