Actualizar plugin Checklists a 3.1.18 light

This commit is contained in:
Manuel Cillero 2020-11-22 21:32:57 +01:00
parent a26f5567af
commit 24560c8598
55 changed files with 992 additions and 307 deletions

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -22,7 +22,7 @@ module RedmineChecklists
class ControllerIssuesHook < Redmine::Hook::ViewListener
def controller_issues_edit_after_save(context = {})
if (Setting.issue_done_ratio == "issue_field") && RedmineChecklists.settings["issue_done_ratio"].to_i > 0
if (Setting.issue_done_ratio == 'issue_field') && RedmineChecklists.issue_done_ratio?
Checklist.recalc_issue_done_ratio(context[:issue].id)
end
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -0,0 +1,38 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# redmine_checklists is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
module RedmineChecklists
module Patches
module ApplicationHelperPatch
def self.included(base) # :nodoc:
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
def stocked_reorder_link(object, name = nil, url = {}, method = :post)
Redmine::VERSION.to_s > '3.3' ? reorder_handle(object, :param => name) : reorder_links(name, url, method)
end
end
end
end
end
end
unless ApplicationHelper.included_modules.include?(RedmineChecklists::Patches::ApplicationHelperPatch)
ApplicationHelper.send(:include, RedmineChecklists::Patches::ApplicationHelperPatch)
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -17,13 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
require_dependency 'journal'
module RedmineChecklists
module Patches
module JournalPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
@ -40,7 +38,7 @@ module RedmineChecklists
(Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
(Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
)
checklist_email_nootification(self).deliver
deliver_checklist_notification
end
end
@ -49,17 +47,24 @@ module RedmineChecklists
end
end
def checklist_email_nootification(journal)
def deliver_checklist_notification
if Redmine::VERSION.to_s >= '4.0'
(notified_watchers | notified_users).each do |user|
Mailer.issue_edit(user, self).deliver
end
else
checklist_email_notification(self).deliver
end
end
def checklist_email_notification(journal)
if Redmine::VERSION.to_s < '2.4'
Mailer.issue_edit(journal)
else
to_users = Redmine::VERSION.to_s <= '3.0' ? journal.notified_users : journal.recipients
cc_users = Redmine::VERSION.to_s <= '3.0' ? journal.notified_watchers - to_users : journal.watcher_recipients - to_users
Mailer.issue_edit(journal, to_users, cc_users)
Mailer.issue_edit(journal, journal.notified_users, journal.notified_watchers - journal.notified_users)
end
end
end
end
end
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -21,41 +21,46 @@ require_dependency 'issue'
module RedmineChecklists
module Patches
module IssuePatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
attr_accessor :old_checklists
attr_accessor :removed_checklist_ids
attr_reader :copied_from
alias_method_chain :copy, :checklist
alias_method :copy_without_checklist, :copy
alias_method :copy, :copy_with_checklist
after_save :copy_subtask_checklists
if ActiveRecord::VERSION::MAJOR >= 4
has_many :checklists, lambda { order("#{Checklist.table_name}.position") }, :class_name => "Checklist", :dependent => :destroy, :inverse_of => :issue
has_many :checklists, lambda { order("#{Checklist.table_name}.position") }, :class_name => 'Checklist', :dependent => :destroy, :inverse_of => :issue
else
has_many :checklists, :class_name => "Checklist", :dependent => :destroy, :inverse_of => :issue,
:order => 'position'
has_many :checklists, :class_name => 'Checklist', :dependent => :destroy, :inverse_of => :issue, :order => 'position'
end
accepts_nested_attributes_for :checklists, :allow_destroy => true, :reject_if => proc { |attrs| attrs["subject"].blank? }
accepts_nested_attributes_for :checklists, :allow_destroy => true, :reject_if => proc { |attrs| attrs['subject'].blank? }
validate :block_issue_closing_if_checklists_unclosed
safe_attributes 'checklists_attributes',
:if => lambda {|issue, user| (user.allowed_to?(:done_checklists, issue.project) ||
user.allowed_to?(:edit_checklists, issue.project))}
def copy_checklists(arg)
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
issue.checklists.each{ |checklist| Checklist.create(checklist.attributes.except('id','issue_id').merge(:issue => self)) } if issue
end
:if => lambda { |issue, user| (user.allowed_to?(:done_checklists, issue.project) || user.allowed_to?(:edit_checklists, issue.project)) }
end
end
module InstanceMethods
def copy_checklists(arg)
issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
if issue
issue.checklists.each do |checklist|
Checklist.create(checklist.attributes.except('id', 'issue_id').merge(issue: self))
end
end
end
def copy_subtask_checklists
return if !copy? || parent_id.nil? || checklists.any?
return if !copy? || parent_id.nil? || checklists.reload.any?
copy_checklists(@copied_from)
end
@ -64,6 +69,23 @@ module RedmineChecklists
copy.copy_checklists(self)
copy
end
def all_checklist_items_is_done?
(checklists - checklists.where(id: removed_checklist_ids)).reject(&:is_section).all?(&:is_done)
end
def need_to_block_issue_closing?
RedmineChecklists.block_issue_closing? &&
checklists.reject(&:is_section).any? &&
status.is_closed? &&
!all_checklist_items_is_done?
end
def block_issue_closing_if_checklists_unclosed
if need_to_block_issue_closing?
errors.add(:checklists, l(:label_checklists_must_be_completed))
end
end
end
end
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -32,6 +32,7 @@ module RedmineChecklists
end
end
unless IssueQuery.included_modules.include?(RedmineChecklists::Patches::IssueQueryPatch)
if (ActiveRecord::Base.connection.tables.include?('queries') rescue false) &&
IssueQuery.included_modules.exclude?(RedmineChecklists::Patches::IssueQueryPatch)
IssueQuery.send(:include, RedmineChecklists::Patches::IssueQueryPatch)
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -26,8 +26,9 @@ module RedmineChecklists
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
alias_method_chain :build_new_issue_from_params, :checklist
before_filter :save_before_state, :only => [:update]
alias_method :build_new_issue_from_params_without_checklist, :build_new_issue_from_params
alias_method :build_new_issue_from_params, :build_new_issue_from_params_with_checklist
before_action :save_before_state, :only => [:update]
end
end
@ -44,6 +45,14 @@ module RedmineChecklists
def save_before_state
@issue.old_checklists = @issue.checklists.to_json
checklists_params = params[:issue].present? && params[:issue][:checklists_attributes].present? ? params[:issue][:checklists_attributes] : {}
@issue.removed_checklist_ids =
if checklists_params.present?
checklists_params = checklists_params.respond_to?(:to_unsafe_hash) ? checklists_params.to_unsafe_hash : checklists_params
checklists_params.map { |_k, v| v['id'].to_i if ['1', 'true'].include?(v['_destroy']) }.compact
else
[]
end
end
def fill_checklist_attributes
@ -60,14 +69,16 @@ module RedmineChecklists
def add_checklists_to_params(checklists)
params[:issue].blank? ? params[:issue] = { :checklists_attributes => {} } : params[:issue][:checklists_attributes] = {}
checklists.each_with_index do |checklist_item, index|
params[:issue][:checklists_attributes][index.to_s] = { :is_done => checklist_item.is_done,
:subject => checklist_item.subject,
:position => checklist_item.position }
params[:issue][:checklists_attributes][index.to_s] = {
is_done: checklist_item.is_done,
subject: checklist_item.subject,
position: checklist_item.position,
is_section: checklist_item.is_section
}
end
end
end
end
end
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -26,26 +26,18 @@ module RedmineChecklists
base.class_eval do
unloadable
alias_method_chain :details_to_strings, :checklists
alias_method_chain :render_email_issue_attributes, :checklists if Redmine::VERSION.to_s <= '2.4' && Redmine::VERSION.to_s >= '2.2'
alias_method :details_to_strings_without_checklists, :details_to_strings
alias_method :details_to_strings, :details_to_strings_with_checklists
end
end
module InstanceMethods
def render_email_issue_attributes_with_checklists(issue, html = false)
journal = issue.journals.order(:id).last
return render_email_issue_attributes_without_checklists(issue, html) unless journal
details = journal.details
return render_email_issue_attributes_without_checklists(issue, html) unless details
checklist_details = details.select{ |x| x.prop_key == 'checklist'}
return render_email_issue_attributes_without_checklists(issue, html) unless checklist_details.any?
return render_email_issue_attributes_without_checklists(issue, html) + details_to_strings_with_checklists(checklist_details, !html).join(html ? "<br/>".html_safe : "\n")
end
def details_to_strings_with_checklists(details, no_html = false, options = {})
details_checklist, details_other = details.partition{ |x| x.prop_key == 'checklist' }
return details_to_strings_without_checklists(details_other, no_html, options) unless User.current.allowed_to?(:view_checklists, @issue.project)
details_checklist.map do |detail|
result = []
diff = Hash.new([])
@ -56,15 +48,19 @@ module RedmineChecklists
diff = JournalChecklistHistory.new(detail.old_value, detail.value).diff
end
checklist_item_label = lambda do |item|
item[:is_section] ? l(:label_checklist_section) : l(:label_checklist_item)
end
if diff[:done].any?
diff[:done].each do |item|
result << "<b>#{ERB::Util.h l(:label_checklist_item)}</b> <input type='checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{ERB::Util.h item[:subject]}</i> #{ERB::Util.h l(:label_checklist_done)}"
result << "<b>#{ERB::Util.h l(:label_checklist_item)}</b> <input type='checkbox' class='checklist-checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{ERB::Util.h item[:subject]}</i> #{ERB::Util.h l(:label_checklist_done)}"
end
end
if diff[:undone].any?
diff[:undone].each do |item|
result << "<b>#{ERB::Util.h l(:label_checklist_item)}</b> <input type='checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{ERB::Util.h item[:subject]}</i> #{ERB::Util.h l(:label_checklist_undone)}"
result << "<b>#{ERB::Util.h l(:label_checklist_item)}</b> <input type='checkbox' class='checklist-checkbox' #{item.is_done ? 'checked' : '' } disabled> <i>#{ERB::Util.h item[:subject]}</i> #{ERB::Util.h l(:label_checklist_undone)}"
end
end
@ -72,8 +68,8 @@ module RedmineChecklists
result = nil if result.blank?
if result && no_html
result = result.gsub /<\/li><li>/, "\n"
result = result.gsub /<input type='checkbox'[^c^>]*checked[^>]*>/, '[x]'
result = result.gsub /<input type='checkbox'[^c^>]*>/, '[ ]'
result = result.gsub /<input type='checkbox' class='checklist-checkbox'[^c^>]*checked[^>]*>/, '[x]'
result = result.gsub /<input type='checkbox' class='checklist-checkbox'[^c^>]*>/, '[ ]'
result = result.gsub /<[^>]*>/, ''
result = CGI.unescapeHTML(result)
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -26,7 +26,8 @@ module RedmineChecklists
base.send(:include, InstanceMethods)
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
alias_method_chain :copy_issues, :checklist
alias_method :copy_issues_without_checklist, :copy_issues
alias_method :copy_issues, :copy_issues_with_checklist
end
end
@ -34,7 +35,7 @@ module RedmineChecklists
def copy_issues_with_checklist(project)
copy_issues_without_checklist(project)
issues.each{ |issue| issue.copy_checklists(issue.copied_from)}
issues.each{ |issue| issue.copy_checklists(issue.copied_from) if issue.reload.checklists.empty? }
end
end
end

View file

@ -1,7 +1,7 @@
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
# issue checklists management plugin for Redmine
#
# Copyright (C) 2011-2017 RedmineUP
# Copyright (C) 2011-2020 RedmineUP
# http://www.redmineup.com/
#
# redmine_checklists is free software: you can redistribute it and/or modify
@ -18,6 +18,8 @@
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
Rails.configuration.to_prepare do
require 'redmine_checklists/patches/compatibility/application_helper_patch'
require 'redmine_checklists/hooks/views_issues_hook'
require 'redmine_checklists/hooks/views_layouts_hook'
require 'redmine_checklists/hooks/controller_issues_hook'
@ -33,5 +35,13 @@ Rails.configuration.to_prepare do
end
module RedmineChecklists
def self.settings() Setting[:plugin_redmine_checklists].blank? ? {} : Setting[:plugin_redmine_checklists] end
def self.settings() Setting.plugin_redmine_checklists.blank? ? {} : Setting.plugin_redmine_checklists end
def self.block_issue_closing?
settings['block_issue_closing'].to_i > 0
end
def self.issue_done_ratio?
settings['issue_done_ratio'].to_i > 0
end
end