Feature #3848 » log-time-for-another-user.diff
app/helpers/timelog_helper.rb (working copy) | ||
---|---|---|
53 | 53 |
collection |
54 | 54 |
end |
55 | 55 |
|
56 |
# Returns a collection of users for a select field. |
|
57 |
def user_collection_for_select_options |
|
58 |
users = @projects = User.find(:all) |
|
59 |
collection = [] |
|
60 |
users.each do |a| |
|
61 |
roles = a.roles_for_project(@project) |
|
62 |
collection << [a.name, a.id] if roles and roles.detect {|role| role.member? && role.allowed_to?(:log_time)} |
|
63 |
end |
|
64 |
collection |
|
65 |
end |
|
66 |
|
|
56 | 67 |
def select_hours(data, criteria, value) |
57 | 68 |
if value.to_s.empty? |
58 | 69 |
data.select {|row| row[criteria].blank? } |
app/controllers/timelog_controller.rb (working copy) | ||
---|---|---|
106 | 106 |
end |
107 | 107 | |
108 | 108 |
def new |
109 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
109 |
# Check if current user has permissions to edit time entries |
|
110 |
if request.post? and User.current.allowed_to?(:edit_time_entries, @project) |
|
111 |
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) |
|
112 |
else |
|
113 |
user = User.current |
|
114 |
end |
|
115 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today) |
|
110 | 116 |
@time_entry.attributes = params[:time_entry] |
111 | 117 |
|
112 | 118 |
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
... | ... | |
115 | 121 | |
116 | 122 |
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } |
117 | 123 |
def create |
118 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) |
|
124 |
# Check if current user has permissions to edit time entries |
|
125 |
if request.post? and User.current.allowed_to?(:edit_time_entries, @project) |
|
126 |
user = User.find(Hash[params[:time_entry].to_a]["user_id"].to_i) |
|
127 |
else |
|
128 |
user = User.current |
|
129 |
end |
|
130 |
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => user, :spent_on => User.current.today) |
|
119 | 131 |
@time_entry.attributes = params[:time_entry] |
120 | 132 |
|
121 | 133 |
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) |
app/views/timelog/edit.rhtml (working copy) | ||
---|---|---|
11 | 11 | |
12 | 12 |
<div class="box"> |
13 | 13 |
<p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> |
14 |
<% if User.current.allowed_to?(:edit_time_entries, @project) %> |
|
15 |
<p> <%= f.select :user_id, user_collection_for_select_options, :required => true %></p> |
|
16 |
<% end %> |
|
14 | 17 |
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> |
15 | 18 |
<p><%= f.text_field :hours, :size => 6, :required => true %></p> |
16 | 19 |
<p><%= f.text_field :comments, :size => 100 %></p> |