Skip to content

redmine 5.0 ruby 3.1 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Subtasks Inherited Fields is a plugin that allows to choose which fields are inh

* Config which fields you want to inherit in the plugin administration page
* Allows to select the default subtask tracker
* Fast Create or Create and Continue subtask creation
* Support for custom fields
* Tested on Redmine 2.4.6 and Redmine 2.5.1
* Works on Redmine 2.4.x, 2.5.x and 2.6.x (For Redmine 4.0.x and 3.x.x check out branch master)

## Install

Expand Down Expand Up @@ -57,6 +58,14 @@ Additional RSpec tests can also be run by entering the following command:
rspec plugins/redmine_subtasks_inherited_fields/spec
```

## Sponsors

Thanks to [Luis Blasco](http://www.luisblasco.com) for his contribution to support this plugin and implement the Create and Continue feature.

## Contact

If you have any doubt please raise an Github Issue. Comments are Welcome!

## License

This plugin is open source and released under the terms of the [GNU General Public License v2 (GPL)](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
7 changes: 5 additions & 2 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
name 'Redmine Subtasks Inherited Fields plugin'
author 'Edosoft Factory'
description 'This is a plugin for Redmine to allow choosing which fields are inherited when you create a subtask'
version '0.0.3'
version '1.1.0'
url 'http://www.edosoftfactory.com'
author_url 'mailto:david.verdu@edosoftfactory.com'

requires_redmine :version_or_higher => '2.0.0'
#requires_redmine :version_or_higher => '2.0.0'
requires_redmine :version => '2.0'..'2.6'

settings :default => {
:inherit_fixed_version_id => true,
Expand All @@ -24,4 +25,6 @@

end

require 'subtasks_inherited_fields'
require 'issues_helper_patch'
require 'issues_controller_patch'
68 changes: 68 additions & 0 deletions lib/issues_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

module SubtasksInheritedFields
module IssuesControllerPatch
module InstanceMethods

#redefine create method to call our redirect_after_create
def create_plugin
call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
@issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
if @issue.save
call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
respond_to do |format|
format.html {
render_attachment_warning_if_needed(@issue)
flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
redirect_after_create #redirect after create inheriting subtask fields
}
format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
end
return
else
respond_to do |format|
format.html { render :action => 'new' }
format.api { render_validation_errors(@issue) }
end
end
end

# Redirects user after a successful issue creation with inheritance
def redirect_after_create
if params[:continue]

attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}

#inherit fields on create subtask and continue
if @issue.parent_issue_id
parent_issue = Issue.find(@issue.parent_issue_id)
attrs = SubtasksInheritedFields::Helpers.inherit_attrs(parent_issue)
end

if params[:project_id]
redirect_to new_project_issue_path(@issue.project, :issue => attrs)
else
attrs.merge! :project_id => @issue.project_id
redirect_to new_issue_path(:issue => attrs)
end
else
redirect_to issue_path(@issue)
end
end
end

def self.included(receiver)
receiver.send :include, InstanceMethods

receiver.class_eval do
unloadable
alias_method :create, :create_plugin
end
end
end
end

unless IssuesController.included_modules.include?(SubtasksInheritedFields::IssuesControllerPatch)
#puts "Including module into IssuesController"
IssuesController.send(:include, SubtasksInheritedFields::IssuesControllerPatch)
end

36 changes: 1 addition & 35 deletions lib/issues_helper_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,7 @@ module InstanceMethods

# Returns a link for adding a new subtask to the given issue
def link_to_new_subtask_plugin(issue)
settings = Setting.find_by_name("plugin_redmine_subtasks_inherited_fields") || {}
settings = settings.value if settings.respond_to? :value
settings = {} if settings == ""
attrs = {
#:tracker_id => issue.tracker,
:parent_issue_id => issue
}
if settings[:inherit_tracker_id] #inherit tracker
attrs[:tracker_id] = issue.tracker
else #use default subtask tracker
default_tracker = Tracker.find_by_id(settings[:default_tracker_id] || 0) || issue.tracker
default_tracker = issue.tracker unless @project.trackers.include? default_tracker
attrs[:tracker_id] = default_tracker
end
attrs[:fixed_version_id] = issue.fixed_version_id if settings[:inherit_fixed_version_id]
attrs[:category_id] = issue.category_id if settings[:inherit_category_id]
attrs[:assigned_to_id] = issue.assigned_to_id if settings[:inherit_assigned_to_id]
attrs[:priority_id] = issue.priority_id if settings[:inherit_priority_id]
attrs[:start_date] = issue.start_date if settings[:inherit_start_date]
attrs[:due_date] = issue.due_date if settings[:inherit_due_date]
attrs[:description] = issue.description if settings[:inherit_description]
attrs[:is_private] = issue.is_private if settings[:inherit_is_private]
attrs[:status_id] = issue.status_id if settings[:inherit_status_id]

#inherit custom fields
inherit_custom_fields = settings[:inherit_custom_fields] || {}
unless inherit_custom_fields.empty?
custom_field_values = {}
issue.custom_field_values.each do |v|
custom_field_values[v.custom_field_id] = v.value if inherit_custom_fields[v.custom_field_id.to_s]
end

attrs[:custom_field_values] = custom_field_values unless custom_field_values.empty?
end

attrs = SubtasksInheritedFields::Helpers.inherit_attrs(issue)
link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
end
end
Expand Down
41 changes: 41 additions & 0 deletions lib/subtasks_inherited_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

module SubtasksInheritedFields
module Helpers
def self.inherit_attrs(parent_issue)
attrs = {:parent_issue_id => parent_issue.id}
settings = Setting.find_by_name("plugin_redmine_subtasks_inherited_fields") || {}
settings = settings.value if settings.respond_to? :value
settings = {} if settings == ""
if settings[:inherit_tracker_id] #inherit tracker
attrs[:tracker_id] = parent_issue.tracker
else #use default subtask tracker
default_tracker = Tracker.find_by_id(settings[:default_tracker_id] || 0) || parent_issue.tracker
project = parent_issue.project
default_tracker = parent_issue.tracker unless project.trackers.include? default_tracker
attrs[:tracker_id] = default_tracker
end
attrs[:fixed_version_id] = parent_issue.fixed_version_id if settings[:inherit_fixed_version_id]
attrs[:category_id] = parent_issue.category_id if settings[:inherit_category_id]
attrs[:assigned_to_id] = parent_issue.assigned_to_id if settings[:inherit_assigned_to_id]
attrs[:priority_id] = parent_issue.priority_id if settings[:inherit_priority_id]
attrs[:start_date] = parent_issue.start_date if settings[:inherit_start_date]
attrs[:due_date] = parent_issue.due_date if settings[:inherit_due_date]
attrs[:description] = parent_issue.description if settings[:inherit_description]
attrs[:is_private] = parent_issue.is_private if settings[:inherit_is_private]
attrs[:status_id] = parent_issue.status_id if settings[:inherit_status_id]

#inherit custom fields
inherit_custom_fields = settings[:inherit_custom_fields] || {}
unless inherit_custom_fields.empty?
custom_field_values = {}
parent_issue.custom_field_values.each do |v|
custom_field_values[v.custom_field_id] = v.value if inherit_custom_fields[v.custom_field_id.to_s]
end

attrs[:custom_field_values] = custom_field_values unless custom_field_values.empty?
end

return attrs
end
end
end