From 7ffb825d6775449ec842f5b66b1eb4d8fbc37765 Mon Sep 17 00:00:00 2001 From: elijah Date: Sun, 7 Jun 2015 23:34:25 -0700 Subject: initial commit --- README.md | 21 +++++++++++ app/controllers/auto_completes_controller.rb | 24 +++++++++++++ init.rb | 9 +++++ lib/redmine_hacks/timelog_hooks.rb | 52 ++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 README.md create mode 100644 app/controllers/auto_completes_controller.rb create mode 100644 init.rb create mode 100644 lib/redmine_hacks/timelog_hooks.rb 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] + "

%s

" % 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 << %() + end + s.html_safe + end + + end +end -- cgit v1.2.3