summaryrefslogtreecommitdiff
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
initial commit
-rw-r--r--README.md21
-rw-r--r--app/controllers/auto_completes_controller.rb24
-rw-r--r--init.rb9
-rw-r--r--lib/redmine_hacks/timelog_hooks.rb52
4 files changed, 106 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5d6ae51
--- /dev/null
+++ b/README.md
@@ -0,0 +1,21 @@
+This is a Redmine plugin to make various modifications to the behavior of
+stock Redmine that we need for LEAP. It is not generally useful, other than
+for LEAP.
+
+Features:
+
+* Add ability to edit other people's time log entries.
+* Show more entries in the autocomplete for parent task.
+
+Installation:
+
+ cd redmin/plugins
+ git clone https://leap.se/git/redmine_hacks.git
+
+License:
+
+The same as Redmine (GNU GENERAL PUBLIC LICENSE Version 2)
+
+Copyright:
+
+2015 (c) LEAP Encryption Access Project
diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb
new file mode 100644
index 0000000..cbecd77
--- /dev/null
+++ b/app/controllers/auto_completes_controller.rb
@@ -0,0 +1,24 @@
+#
+# Override to change the LIMIT.
+# Copied from Redmine 2.6
+#
+
+class AutoCompletesController < ApplicationController
+ def issues
+ @issues = []
+ q = (params[:q] || params[:term]).to_s.strip
+ if q.present?
+ scope = Issue.cross_project_scope(@project, params[:scope]).visible
+ if q.match(/\A#?(\d+)\z/)
+ @issues << scope.find_by_id($1.to_i)
+ end
+ @issues += scope.
+ where("LOWER(#{Issue.table_name}.subject) LIKE LOWER(?)", "%#{q}%").
+ order("#{Issue.table_name}.id DESC").
+ limit(100).
+ all
+ @issues.compact!
+ end
+ render :layout => false
+ end
+end
diff --git a/init.rb b/init.rb
new file mode 100644
index 0000000..657be0f
--- /dev/null
+++ b/init.rb
@@ -0,0 +1,9 @@
+require_dependency 'redmine_hacks/timelog_hooks'
+
+Redmine::Plugin.register :redmine_hacks do
+ name 'redmine hacks'
+ author 'LEAP'
+ description 'various hacks to redmine'
+ version '0.0.1'
+ url 'https://leap.se/git/redmine_hacks.git'
+end
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