Index: app/helpers/timelog_helper.rb =================================================================== --- app/helpers/timelog_helper.rb (revisión: 117) +++ app/helpers/timelog_helper.rb (copia de trabajo) @@ -54,7 +54,23 @@ activities.each { |a| collection << [a.name, a.id] } collection end + + # Returns a collection of users for a select field. + def user_collection_for_select_options(project, selected = nil) + collection = project.members.map{|member| member.user } + collection.keep_if{|user| user.allowed_to?(:log_time, project)} + + s = '' + s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id) if User.current.admin? || collection.include?(User.current) + collection.sort.each do |element| + selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) + s << %() + end + + s.html_safe + end + def select_hours(data, criteria, value) if value.to_s.empty? data.select {|row| row[criteria].blank? } Index: app/models/time_entry.rb =================================================================== --- app/models/time_entry.rb (revisión: 117) +++ app/models/time_entry.rb (copia de trabajo) @@ -24,7 +24,7 @@ belongs_to :user belongs_to :activity, :class_name => 'TimeEntryActivity', :foreign_key => 'activity_id' - attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek + attr_protected :project_id, :tyear, :tmonth, :tweek acts_as_customizable acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, @@ -67,6 +67,7 @@ } safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields' + safe_attributes 'user_id', :if => lambda{ |time_entry, user| user.allowed_to?(:edit_time_entries, time_entry.project) } def initialize(attributes=nil, *args) super Index: app/models/issue.rb =================================================================== --- app/models/issue.rb (revisión: 117) +++ app/models/issue.rb (copia de trabajo) @@ -954,10 +954,10 @@ @time_entry = existing_time_entry || TimeEntry.new @time_entry.project = project @time_entry.issue = self - @time_entry.user = User.current - @time_entry.spent_on = User.current.today - @time_entry.attributes = params[:time_entry] - self.time_entries << @time_entry + @time_entry.user ||= User.current # For some unknown reason, if User.current override @time_entry.user when it's already set, + @time_entry.spent_on ||= User.current.today + @time_entry.attributes = params[:time_entry] # and although this instruction will revert the user to that in params[:time_entry][:user_id] + self.time_entries << @time_entry # This instruction will force @time_entry.user to be User.current, independently of what it has already set. Or at least that happened to me. end # TODO: Rename hook Index: app/controllers/timelog_controller.rb =================================================================== --- app/controllers/timelog_controller.rb (revisión: 117) +++ app/controllers/timelog_controller.rb (copia de trabajo) @@ -123,7 +123,14 @@ end 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(params[:time_entry][:user_id]) + else + user = User.current + end + + @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => user.today) @time_entry.safe_attributes = params[:time_entry] call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) Index: app/views/timelog/_form.html.erb =================================================================== --- app/views/timelog/_form.html.erb (revisión: 117) +++ app/views/timelog/_form.html.erb (copia de trabajo) @@ -12,6 +12,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 %>

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

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

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

<%= f.select :user_id, user_collection_for_select_options(@project, @time_entry.user), :required => true %>

+ <% end %>

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

<%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %>

<% @time_entry.custom_field_values.each do |value| %> Index: app/views/issues/_edit.html.erb =================================================================== --- app/views/issues/_edit.html.erb (revisión: 117) +++ app/views/issues/_edit.html.erb (copia de trabajo) @@ -18,6 +18,9 @@

<%= time_entry.select :activity_id, activity_collection_for_select_options %>

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

<%= time_entry.select :user_id, user_collection_for_select_options(@project, @time_entry.user), :required => true %>

+ <% end %>

<%= time_entry.text_field :comments, :size => 60 %>

<% @time_entry.custom_field_values.each do |value| %>

<%= custom_field_tag_with_label :time_entry, value %>