summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-06-07 23:34:25 -0700
committerelijah <elijah@riseup.net>2015-06-07 23:34:25 -0700
commit7ffb825d6775449ec842f5b66b1eb4d8fbc37765 (patch)
tree8525583402c1c32d371bd4ba0a57811823145a10 /lib
initial commit
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine_hacks/timelog_hooks.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/redmine_hacks/timelog_hooks.rb b/lib/redmine_hacks/timelog_hooks.rb
new file mode 100644
index 0000000..ad2e13f
--- /dev/null
+++ b/lib/redmine_hacks/timelog_hooks.rb
@@ -0,0 +1,52 @@
+#
+# Allows anyone who is authorized to log time be able to log time
+# as anyone else who is also authorized to log time.
+#
+
+module RedmineHacks
+ class Hooks < Redmine::Hook::ViewListener
+
+ def controller_timelog_edit_before_save(context={})
+ params = context[:params]
+ time_entry = context[:time_entry]
+ if params[:time_entry] && params[:time_entry][:user_id]
+ user = User.find_by_id(params[:time_entry][:user_id])
+ if user && user.allowed_to?(:log_time, time_entry.project)
+ time_entry.user = user
+ end
+ end
+ end
+
+ def view_timelog_edit_form_bottom(context={})
+ form = context[:form]
+ time_entry = context[:time_entry]
+ "<p>%s</p>" % form.select(
+ :user_id,
+ timelog_user_collection_for_select_options(time_entry),
+ {:required => true},
+ {:size => time_entry.project.members.size}
+ )
+ end
+
+ protected
+
+ def timelog_user_collection_for_select_options(time_entry)
+ collection = time_entry.project.members.map{|member| member.user }.sort
+ collection.keep_if{|user| user.allowed_to?(:log_time, time_entry.project)}
+ if time_entry.user && !collection.include?(time_entry.user)
+ collection << time_entry.user
+ end
+ s = ''
+ collection.sort.each do |element|
+ if time_entry.user && time_entry.user == element
+ selected_attribute = ' selected="selected"'
+ else
+ selected_attribute = ''
+ end
+ s << %(<option value="#{element.id}"#{selected_attribute}>#{h element.login} - #{h element.name}</option>)
+ end
+ s.html_safe
+ end
+
+ end
+end