diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index 51d641f..649188e 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -122,6 +122,11 @@ jobs: cd /opt/redmine bundle exec rake redmine:plugins:test:units bundle exec rake redmine:plugins:test:functionals + - name: Rubocop + # Run the Rubocop tests + run: | + cd /opt/redmine + bundle exec rubocop -c plugins/redmine_custom_workflows/.rubocop.yml plugins/redmine_custom_workflows/ - name: Cleanup # Rollback plugin's changes to the database # Stop the database engine diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6f77055 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,60 @@ +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-23 Karel Pičman +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +AllCops: + TargetRubyVersion: 2.7 + TargetRailsVersion: 6.1 + + NewCops: enable + + Exclude: + - '**/vendor/**/*' + +# Enable extensions +require: + - rubocop-performance + - rubocop-rails + +# Rules for CustomWorkflows +Layout/EmptyLineAfterMagicComment: + Enabled: false + +Metrics/BlockLength: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Rails/HasAndBelongsToMany: + Enabled: false + +Style/ExpandPathArguments: + Enabled: false diff --git a/Gemfile b/Gemfile index 1579ef1..5901224 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # diff --git a/after_init.rb b/after_init.rb index dd73c2b..c61748a 100644 --- a/after_init.rb +++ b/after_init.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -21,17 +20,17 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'redmine' -require File.dirname(__FILE__) + '/lib/redmine_custom_workflows' +require "#{File.dirname(__FILE__)}/lib/redmine_custom_workflows" def custom_workflows_init # Administration menu extension Redmine::MenuManager.map :admin_menu do |menu| - menu.push :custom_workflows, { controller: 'custom_workflows', action: 'index'}, - caption: :label_custom_workflow_plural, html: { class: 'icon icon-workflows workflows'} + menu.push :custom_workflows, { controller: 'custom_workflows', action: 'index' }, + caption: :label_custom_workflow_plural, html: { class: 'icon icon-workflows workflows' } end end -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') ActiveSupport.on_load(:easyproject, yield: true) do custom_workflows_init end diff --git a/app/controllers/custom_workflows_controller.rb b/app/controllers/custom_workflows_controller.rb index 1538717..51fd165 100644 --- a/app/controllers/custom_workflows_controller.rb +++ b/app/controllers/custom_workflows_controller.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -19,12 +18,12 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -class CustomWorkflowsController < ApplicationController +# Custom workflows controller +class CustomWorkflowsController < ApplicationController layout 'admin' before_action :require_admin - before_action :find_workflow, only: [:show, :edit, :update, :destroy, :export, :change_status, :reorder] + before_action :find_workflow, only: %i[show edit update destroy export change_status reorder] def reorder from = @workflow.position @@ -32,21 +31,20 @@ class CustomWorkflowsController < ApplicationController CustomWorkflow.transaction do CustomWorkflow.find_each do |wf| if wf.position == from - wf.update_attribute :position, to + wf.position = to elsif wf.position >= to && wf.position < from # Move up - wf.update_attribute :position, wf.position + 1 + wf.position = wf.position + 1 elsif wf.position <= to && wf.position > from # Move down - wf.update_attribute :position, wf.position - 1 + wf.position = wf.position - 1 end + wf.save end end respond_to do |format| format.html - format.js { - render inline: "location.replace('#{custom_workflows_path}');" - } + format.js end end @@ -67,8 +65,7 @@ class CustomWorkflowsController < ApplicationController end end - def edit - end + def edit; end def new @workflow = CustomWorkflow.new @@ -88,8 +85,8 @@ class CustomWorkflowsController < ApplicationController else flash[:error] = @workflow.errors.full_messages.to_sentence end - rescue Exception => e - Rails.logger.warn "Workflow import error: #{e.message}\n #{e.backtrace.join("\n ")}" + rescue StandardError => e + Rails.logger.warn { "Workflow import error: #{e.message}\n #{e.backtrace.join("\n ")}" } flash[:error] = l(:error_failed_import) end respond_to do |format| @@ -103,7 +100,7 @@ class CustomWorkflowsController < ApplicationController @workflow.observable = params[:custom_workflow][:observable] update_from_params respond_to do |format| - if params.has_key?(:commit) && @workflow.save + if params.key?(:commit) && @workflow.save flash[:notice] = l(:notice_successful_create) cookies[:custom_workflows_author] = @workflow.author format.html { redirect_to(custom_workflows_path) } @@ -127,7 +124,7 @@ class CustomWorkflowsController < ApplicationController def update respond_to do |format| update_from_params - if params.has_key?(:commit) && @workflow.save + if params.key?(:commit) && @workflow.save flash[:notice] = l(:notice_successful_update) format.html { redirect_to(custom_workflows_path) } else @@ -169,5 +166,4 @@ class CustomWorkflowsController < ApplicationController @workflow.after_destroy = params[:custom_workflow][:after_destroy] @workflow.project_ids = params[:custom_workflow][:project_ids] end - end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..2984ab0 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-23 Karel Pičman +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Application record class +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index bf32ff6..95d6d31 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,29 +19,37 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -class CustomWorkflow < ActiveRecord::Base - OBSERVABLES = [:issue, :issue_relation, :issue_attachments, :user, :attachment, :group, :group_users, :project, :project_attachments, - :wiki_content, :wiki_page_attachments, :time_entry, :version, :shared] - PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments, :time_entry, :version] - COLLECTION_OBSERVABLES = [:group_users, :issue_attachments, :project_attachments, :wiki_page_attachments] - SINGLE_OBSERVABLES = [:issue, :issue_relation, :user, :group, :attachment, :project, :wiki_content, :time_entry, :version] +# Custom workflow model +class CustomWorkflow < ApplicationRecord + OBSERVABLES = %i[issue issue_relation issue_attachments user attachment group group_users project project_attachments + wiki_content wiki_page_attachments time_entry version shared].freeze + PROJECT_OBSERVABLES = %i[issue issue_attachments project project_attachments wiki_content wiki_page_attachments + time_entry version].freeze + COLLECTION_OBSERVABLES = %i[group_users issue_attachments project_attachments wiki_page_attachments].freeze + SINGLE_OBSERVABLES = %i[issue issue_relation user group attachment project wiki_content time_entry version].freeze - has_and_belongs_to_many :projects acts_as_list - validates_presence_of :name - validates_uniqueness_of :name, case_sensitive: false - validates_format_of :author, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, allow_blank: true - validate :validate_syntax, :validate_scripts_presence, if: Proc.new { |workflow| workflow.respond_to?(:observable) and workflow.active? } + has_and_belongs_to_many :projects - scope :active, lambda { where(active: true) } - scope :sorted, lambda { order(:position) } + validates :name, uniqueness: true + validates :author, format: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, allow_blank: true + validate :validate_syntax, :validate_scripts_presence, + if: proc { |workflow| workflow.respond_to?(:observable) and workflow.active? } + + scope :active, -> { where(active: true) } + scope :sorted, -> { order(:position) } scope :for_project, (lambda do |project| - where("is_for_all=? OR EXISTS (SELECT * FROM #{reflect_on_association(:projects).join_table} WHERE project_id=? AND custom_workflow_id=id)", - true, project.id) - end) - #scope :for_project, (lambda { |project| where(is_for_all: true).or(where( - # 'SELECT * FROM custom_workflow_projects WHERE project_id = ? AND custom_workflow_id = id', project.id).exists?) }) + where( + %{ + is_for_all = ? OR + EXISTS (SELECT * FROM #{reflect_on_association(:projects).join_table} + WHERE project_id = ? AND custom_workflow_id = id) + }, + true, + project.id + ) + end) def self.import_from_xml(xml) attributes = Hash.from_xml(xml).values.first @@ -76,9 +83,11 @@ class CustomWorkflow < ActiveRecord::Base workflows = CustomWorkflow.active.where(observable: observable) if PROJECT_OBSERVABLES.include? observable return true unless object.project + workflows = workflows.for_project(object.project) end return true unless workflows.any? + log_message "= Running #{event} custom workflows", object workflows.sorted.each do |workflow| unless workflow.run(object, event) @@ -93,83 +102,83 @@ class CustomWorkflow < ActiveRecord::Base def run(object, event) return true unless attribute_present?(event) - Rails.logger.info "== Running #{event} custom workflow \"#{name}\"" - object.instance_eval(read_attribute(event)) + + Rails.logger.info { "== Running #{event} custom workflow \"#{name}\"" } + object.instance_eval self[event] true rescue RedmineCustomWorkflows::Errors::WorkflowError => e - Rails.logger.info "== User workflow error: #{e.message}" + Rails.logger.info { "== User workflow error: #{e.message}" } object.errors.add :base, e.message false - rescue Exception => e - Rails.logger.error "== Custom workflow #{name}, ##{id} exception: #{e.message}\n #{e.backtrace.join("\n ")}" + rescue StandardError => e + Rails.logger.error { "== Custom workflow #{name}, ##{id} exception: #{e.message}\n #{e.backtrace.join("\n ")}" } object.errors.add :base, :custom_workflow_error false end - def has_projects_association? + def projects_association? PROJECT_OBSERVABLES.include? observable.to_sym end def validate_syntax_for(object, event) - object.instance_eval(read_attribute(event)) if respond_to?(event) && read_attribute(event) - rescue RedmineCustomWorkflows::Errors::WorkflowError => _ - rescue Exception => e + object.instance_eval(self[event]) if respond_to?(event) && self[event] + rescue RedmineCustomWorkflows::Errors::WorkflowError => _e + # Do nothing + rescue StandardError => e errors.add event, :invalid_script, error: e end def validate_scripts_presence - case observable.to_sym - when :shared - fields = [shared_code] - when *SINGLE_OBSERVABLES - fields = [before_save, after_save, before_destroy, after_destroy] - when *COLLECTION_OBSERVABLES - fields = [before_add, after_add, before_remove, after_remove] - else - fields = [] - end - unless fields.any? {|field| field.present?} - errors.add :base, :scripts_absent - end + fields = case observable.to_sym + when :shared + [shared_code] + when *SINGLE_OBSERVABLES + [before_save, after_save, before_destroy, after_destroy] + when *COLLECTION_OBSERVABLES + [before_add, after_add, before_remove, after_remove] + else + [] + end + errors.add(:base, :scripts_absent) unless fields.any?(&:present?) end def validate_syntax case observable.to_sym - when :shared - CustomWorkflow.run_shared_code self - validate_syntax_for self, :shared_code - when *SINGLE_OBSERVABLES - object = observable.camelize.constantize.new - object.send :instance_variable_set, "@#{observable}", object # compatibility with 0.0.1 - CustomWorkflow.run_shared_code object - [:before_save, :after_save, :before_destroy, :after_destroy].each {|field| validate_syntax_for object, field} - when *COLLECTION_OBSERVABLES - object = nil - case observable.to_sym - when :group_users - object = Group.new - object.send :instance_variable_set, :@user, User.new - object.send :instance_variable_set, :@group, object - when :issue_attachments - object = Issue.new - object.send :instance_variable_set, :@attachment, Attachment.new - object.send :instance_variable_set, :@issue, object - when :project_attachments - object = Project.new - object.send :instance_variable_set, :@attachment, Attachment.new - object.send :instance_variable_set, :@project, object - when :wiki_page_attachments - object = WikiPage.new - object.send :instance_variable_set, :@attachment, Attachment.new - object.send :instance_variable_set, :@page, object - end - CustomWorkflow.run_shared_code object - [:before_add, :after_add, :before_remove, :after_remove].each { |field| validate_syntax_for object, field } + when :shared + CustomWorkflow.run_shared_code self + validate_syntax_for self, :shared_code + when *SINGLE_OBSERVABLES + object = observable.camelize.constantize.new + object.send :instance_variable_set, "@#{observable}", object # compatibility with 0.0.1 + CustomWorkflow.run_shared_code object + %i[before_save after_save before_destroy after_destroy].each { |field| validate_syntax_for object, field } + when *COLLECTION_OBSERVABLES + object = nil + case observable.to_sym + when :group_users + object = Group.new + object.send :instance_variable_set, :@user, User.new + object.send :instance_variable_set, :@group, object + when :issue_attachments + object = Issue.new + object.send :instance_variable_set, :@attachment, Attachment.new + object.send :instance_variable_set, :@issue, object + when :project_attachments + object = Project.new + object.send :instance_variable_set, :@attachment, Attachment.new + object.send :instance_variable_set, :@project, object + when :wiki_page_attachments + object = WikiPage.new + object.send :instance_variable_set, :@attachment, Attachment.new + object.send :instance_variable_set, :@page, object + end + CustomWorkflow.run_shared_code object + %i[before_add after_add before_remove after_remove].each { |field| validate_syntax_for object, field } end end def export_as_xml - attrs = self.attributes.dup + attrs = attributes.dup attrs['exported-at'] = Time.current.xmlschema attrs['plugin-version'] = Redmine::Plugin.find(:redmine_custom_workflows).version attrs['ruby-version'] = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" @@ -178,11 +187,10 @@ class CustomWorkflow < ActiveRecord::Base end def <=>(other) - self.position <=> other.position + position <=> other.position end def to_s name end - end diff --git a/app/models/custom_workflow_mailer.rb b/app/models/custom_workflow_mailer.rb index 09e62bd..b931cf9 100644 --- a/app/models/custom_workflow_mailer.rb +++ b/app/models/custom_workflow_mailer.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -22,6 +21,7 @@ require 'mailer' +# Custom workflow mailer model class CustomWorkflowMailer < Mailer layout 'mailer' @@ -34,5 +34,4 @@ class CustomWorkflowMailer < Mailer @text = text mail to: user, subject: subject end - end diff --git a/app/views/custom_workflow_mailer/custom_email.html.erb b/app/views/custom_workflow_mailer/custom_email.html.erb index fbe290e..22af36f 100644 --- a/app/views/custom_workflow_mailer/custom_email.html.erb +++ b/app/views/custom_workflow_mailer/custom_email.html.erb @@ -1,24 +1,22 @@ <% - # encoding: utf-8 - # - # Redmine plugin for Custom Workflows - # - # Copyright © 2015-19 Anton Argirov - # Copyright © 2019-23 Karel Pičman - # - # This program 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 2 - # of the License, or (at your option) any later version. - # - # This program 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 this program; if not, write to the Free Software - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + # Redmine plugin for Custom Workflows + # + # Copyright © 2015-19 Anton Argirov + # Copyright © 2019-23 Karel Pičman + # + # This program 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 2 + # of the License, or (at your option) any later version. + # + # This program 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 this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. %>

diff --git a/app/views/custom_workflow_mailer/custom_email.text.erb b/app/views/custom_workflow_mailer/custom_email.text.erb index 5209ad3..634c53b 100644 --- a/app/views/custom_workflow_mailer/custom_email.text.erb +++ b/app/views/custom_workflow_mailer/custom_email.text.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov diff --git a/app/views/custom_workflows/_form.html.erb b/app/views/custom_workflows/_form.html.erb index 97ef882..238b9af 100644 --- a/app/views/custom_workflows/_form.html.erb +++ b/app/views/custom_workflows/_form.html.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov @@ -33,7 +31,7 @@ onchange: 'this.form.submit()', disabled: !@workflow.new_record? %>

<%= f.text_area :description, class: 'wiki-edit' %>

- <% if @workflow.has_projects_association? %> + <% if @workflow.projects_association? %>

<%= f.check_box :is_for_all, onclick: "checkAndDisable('custom_workflow_enabled_projects', this.checked);", label: :field_enabled_for_all_projects %> @@ -42,7 +40,7 @@

<%= f.check_box :active, label: l(:field_active) %>

- <% if @workflow.has_projects_association? %> + <% if @workflow.projects_association? %>
<%= content_tag 'fieldset', id: 'custom_workflow_enabled_projects' do %> diff --git a/app/views/custom_workflows/edit.html.erb b/app/views/custom_workflows/edit.html.erb index 311bb34..56e9b18 100644 --- a/app/views/custom_workflows/edit.html.erb +++ b/app/views/custom_workflows/edit.html.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov diff --git a/app/views/custom_workflows/index.html.erb b/app/views/custom_workflows/index.html.erb index 07f643f..347b9b0 100644 --- a/app/views/custom_workflows/index.html.erb +++ b/app/views/custom_workflows/index.html.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov diff --git a/app/views/custom_workflows/new.html.erb b/app/views/custom_workflows/new.html.erb index 3bff02e..cce52e4 100644 --- a/app/views/custom_workflows/new.html.erb +++ b/app/views/custom_workflows/new.html.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov diff --git a/db/migrate/20150525083345_add_author_and_timestamps_to_custom_workflows.rb b/app/views/custom_workflows/reorder.js.erb similarity index 81% rename from db/migrate/20150525083345_add_author_and_timestamps_to_custom_workflows.rb rename to app/views/custom_workflows/reorder.js.erb index 57dc7ef..3e5d422 100644 --- a/db/migrate/20150525083345_add_author_and_timestamps_to_custom_workflows.rb +++ b/app/views/custom_workflows/reorder.js.erb @@ -1,3 +1,4 @@ +<% # encoding: utf-8 # # Redmine plugin for Custom Workflows @@ -18,12 +19,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> -class AddAuthorAndTimestampsToCustomWorkflows < ActiveRecord::Migration[4.2] - - def change - add_column :custom_workflows, :author, :string, null: true - add_timestamps :custom_workflows - end - -end +location.replace('<%= custom_workflows_path %>'); diff --git a/app/views/projects/settings/_custom_workflow.html.erb b/app/views/projects/settings/_custom_workflow.html.erb index 6083fe4..e392e64 100644 --- a/app/views/projects/settings/_custom_workflow.html.erb +++ b/app/views/projects/settings/_custom_workflow.html.erb @@ -1,6 +1,4 @@ <% - # encoding: utf-8 - # # Redmine plugin for Custom Workflows # # Copyright © 2015-19 Anton Argirov diff --git a/config/routes.rb b/config/routes.rb index 1edfda0..9cb0bf0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -21,17 +20,14 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do - resources :custom_workflows do member do - + # Nothing end end - post '/custom_workflows/import', to: 'custom_workflows#import', as: 'import_custom_workflow' post '/custom_workflows/:id', to: 'custom_workflows#update' get '/custom_workflows/:id/export', to: 'custom_workflows#export', as: 'export_custom_workflow' post '/custom_workflows/:id/change_status', to: 'custom_workflows#change_status', as: 'custom_workflow_status' put '/custom_workflows/:id/reorder', to: 'custom_workflows#reorder' - end diff --git a/db/migrate/20110915084858_create_custom_workflows.rb b/db/migrate/20110915084858_create_custom_workflows.rb index fe408b0..5cee1cf 100644 --- a/db/migrate/20110915084858_create_custom_workflows.rb +++ b/db/migrate/20110915084858_create_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,15 +19,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Create the model table class CreateCustomWorkflows < ActiveRecord::Migration[4.2] - def change create_table :custom_workflows, force: true do |t| t.references :project t.text :script, null: true, default: nil t.boolean :is_enabled + t.timestamps + t.index :project_id, unique: true end - add_index :custom_workflows, [:project_id], unique: true end - end diff --git a/db/migrate/20120601054047_alter_custom_workflows.rb b/db/migrate/20120601054047_alter_custom_workflows.rb index 0285a1d..5982d36 100644 --- a/db/migrate/20120601054047_alter_custom_workflows.rb +++ b/db/migrate/20120601054047_alter_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,14 +19,25 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Modify the table class AlterCustomWorkflows < ActiveRecord::Migration[4.2] - - def self.up - remove_column :custom_workflows, :project_id - remove_column :custom_workflows, :is_enabled - add_column :custom_workflows, :name, :string, null: false, default: '' - add_column :custom_workflows, :description, :string, null: false, default: '' - add_column :custom_workflows, :position, :integer, null: false, default: 1 + def up + change_table(:custom_workflows, bulk: true) do |t| + t.remove :project_id + t.remove :is_enabled + t.string :name, null: false, default: '' + t.string :description, :string, null: false, default: '' + t.integer :position, :integer, null: false, default: 1 + end end + def down + change_table(:custom_workflows, bulk: true) do |t| + t.references :project + t.boolean :is_enabled + t.remove :name + t.remove :description + t.remove :position + end + end end diff --git a/db/migrate/20120601054557_create_custom_workflows_projects.rb b/db/migrate/20120601054557_create_custom_workflows_projects.rb index eab9b2a..6ce67e4 100644 --- a/db/migrate/20120601054557_create_custom_workflows_projects.rb +++ b/db/migrate/20120601054557_create_custom_workflows_projects.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,15 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Add table custom_workflows_projects class CreateCustomWorkflowsProjects < ActiveRecord::Migration[4.2] - def change - create_table :custom_workflows_projects, force: true, id: false do |t| - t.references :project - t.references :custom_workflow - end - add_index :custom_workflows_projects, [:project_id] - add_index :custom_workflows_projects, [:custom_workflow_id] + create_join_table :projects, :custom_workflows end - end diff --git a/db/migrate/20120628060102_change_custom_workflows_description_type.rb b/db/migrate/20120628060102_change_custom_workflows_description_type.rb index 1e4534b..dd9cb93 100644 --- a/db/migrate/20120628060102_change_custom_workflows_description_type.rb +++ b/db/migrate/20120628060102_change_custom_workflows_description_type.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Modify column class ChangeCustomWorkflowsDescriptionType < ActiveRecord::Migration[4.2] - def self.up + def up change_column :custom_workflows, :description, :text, null: true, default: nil end - end diff --git a/db/migrate/20120908085222_add_after_save_to_custom_workflows.rb b/db/migrate/20120908085222_add_after_save_to_custom_workflows.rb index f645280..a0101a9 100644 --- a/db/migrate/20120908085222_add_after_save_to_custom_workflows.rb +++ b/db/migrate/20120908085222_add_after_save_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,17 +19,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Modify columns class AddAfterSaveToCustomWorkflows < ActiveRecord::Migration[4.2] - def up - rename_column :custom_workflows, :script, :before_save - change_column :custom_workflows, :before_save, :text, null: true - add_column :custom_workflows, :after_save, :text, null: true, after: :before_save + change_table(:custom_workflows, bulk: true) do |t| + t.rename :script, :before_save + t.text :after_save, null: true, after: :before_save + end end def down - remove_column :custom_workflows, :after_save - rename_column :custom_workflows, :before_save, :script + change_table(:custom_workflows, bulk: true) do |t| + t.remove :after_save + t.rename :before_save, :script + end end - end diff --git a/db/migrate/20121005085252_add_is_for_all_to_custom_workflows.rb b/db/migrate/20121005085252_add_is_for_all_to_custom_workflows.rb index 83078bc..99ccebf 100644 --- a/db/migrate/20121005085252_add_is_for_all_to_custom_workflows.rb +++ b/db/migrate/20121005085252_add_is_for_all_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,10 +19,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Add column class AddIsForAllToCustomWorkflows < ActiveRecord::Migration[4.2] - def change - add_column :custom_workflows, :is_for_all, :boolean, null: false, default: false + add_column :custom_workflows, :is_for_all, :boolean, + null: false, default: false end - end diff --git a/db/migrate/20150522134436_make_after_save_and_before_save_nullable.rb b/db/migrate/20150522134436_make_after_save_and_before_save_nullable.rb index a52dc57..d411e53 100644 --- a/db/migrate/20150522134436_make_after_save_and_before_save_nullable.rb +++ b/db/migrate/20150522134436_make_after_save_and_before_save_nullable.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,11 +19,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Modify columns class MakeAfterSaveAndBeforeSaveNullable < ActiveRecord::Migration[4.2] - def up - change_column :custom_workflows, :before_save, :text, null: true, default: nil - change_column :custom_workflows, :after_save, :text, null: true, default: nil + change_table(:custom_workflows, bulk: true) do |t| + t.change :before_save, :text, null: true, default: nil + t.change :after_save, :text, null: true, default: nil + end end - end diff --git a/db/migrate/20150522134437_set_position_field_nullable.rb b/db/migrate/20150522134437_set_position_field_nullable.rb index 29a90a9..144f88a 100644 --- a/db/migrate/20150522134437_set_position_field_nullable.rb +++ b/db/migrate/20150522134437_set_position_field_nullable.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,10 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Modify the column position class SetPositionFieldNullable < ActiveRecord::Migration[4.2] - def up change_column :custom_workflows, :position, :integer, null: true end - end diff --git a/db/migrate/20150525083345_add_author_to_custom_workflows.rb b/db/migrate/20150525083345_add_author_to_custom_workflows.rb new file mode 100644 index 0000000..6e3b213 --- /dev/null +++ b/db/migrate/20150525083345_add_author_to_custom_workflows.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-23 Karel Pičman +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Add timestamp +class AddAuthorToCustomWorkflows < ActiveRecord::Migration[4.2] + def change + change_table(:custom_workflows, bulk: true) do |t| + t.string :author, null: true + end + end +end diff --git a/db/migrate/20150526132244_create_example_workflow.rb b/db/migrate/20150526132244_create_example_workflow.rb index 9a9e882..b706f7c 100644 --- a/db/migrate/20150526132244_create_example_workflow.rb +++ b/db/migrate/20150526132244_create_example_workflow.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,27 +19,29 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Add an example class CreateExampleWorkflow < ActiveRecord::Migration[4.2] - def up CustomWorkflow.reset_column_information name = 'Duration/Done Ratio/Status correlation' old = CustomWorkflow.where(name: name).first - old.destroy if old + old&.destroy cw = CustomWorkflow.new cw.name = name cw.author = 'anton.argirov@gmail.com' - cw.description = %{ + cw.description = %( Set up a correlation between the start date, due date, done ratio and status of issues. * If done ratio is changed to 100% and status is "In Process", status changes to "Resolved" - * If status is "New", "Resolved" or "Feedback" and done ratio is changed to value less than 100%, status changes to "In process" + * If status is "New", "Resolved" or "Feedback" and done ratio is changed to value less than 100%, status changes +to "In process" * If status is changed to "In process" and start date is not set, then it sets to current date * If status is changed to "Resolved" and end date is not set, then it set to due date - To use this script properly, turn off "Use current date as start date for new issues" option in the settings as this script already do it own way. - } - cw.before_save = %{ + To use this script properly, turn off "Use current date as start date for new issues" option in the settings as +this script already do it own way. + ) + cw.before_save = %( if @issue.done_ratio_changed? if (@issue.done_ratio == 100) && (@issue.status_id == 2) @issue.status_id = 3 @@ -58,8 +60,7 @@ class CreateExampleWorkflow < ActiveRecord::Migration[4.2] @issue.due_date ||= Time.now end end - } + ) cw.save! end - end diff --git a/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb b/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb index bf7c236..9146ea4 100644 --- a/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb +++ b/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,10 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Extend custom_workflows table class AddActiveFieldToCustomWorkflows < ActiveRecord::Migration[4.2] - def change add_column :custom_workflows, :active, :boolean, null: false, default: true end - end diff --git a/db/migrate/20150619135811_add_observable_field_to_custom_workflows.rb b/db/migrate/20150619135811_add_observable_field_to_custom_workflows.rb index ce0dac5..a8994f1 100644 --- a/db/migrate/20150619135811_add_observable_field_to_custom_workflows.rb +++ b/db/migrate/20150619135811_add_observable_field_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,10 +19,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Extend custom_workflows table class AddObservableFieldToCustomWorkflows < ActiveRecord::Migration[4.2] - def change - add_column :custom_workflows, :observable, :string, null: false, default: 'issue' + add_column :custom_workflows, :observable, :string, + null: false, default: 'issue' end - end diff --git a/db/migrate/20150619162054_add_additional_script_fields_to_custom_workflows.rb b/db/migrate/20150619162054_add_additional_script_fields_to_custom_workflows.rb index 545d4dd..44f83ba 100644 --- a/db/migrate/20150619162054_add_additional_script_fields_to_custom_workflows.rb +++ b/db/migrate/20150619162054_add_additional_script_fields_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,14 +19,15 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Extend custom workflows table class AddAdditionalScriptFieldsToCustomWorkflows < ActiveRecord::Migration[4.2] - def change - add_column :custom_workflows, :shared_code, :text, null: true - add_column :custom_workflows, :before_add, :text, null: true - add_column :custom_workflows, :after_add, :text, null: true - add_column :custom_workflows, :before_remove, :text, null: true - add_column :custom_workflows, :after_remove, :text, null: true + change_table(:custom_workflows, bulk: true) do |t| + t.text :shared_code, null: true + t.text :before_add, null: true + t.text :after_add, null: true + t.text :before_remove, null: true + t.text :after_remove, null: true + end end - end diff --git a/db/migrate/20151122120000_add_before_and_after_destroy_to_custom_workflows.rb b/db/migrate/20151122120000_add_before_and_after_destroy_to_custom_workflows.rb index ce8d622..226c7f6 100644 --- a/db/migrate/20151122120000_add_before_and_after_destroy_to_custom_workflows.rb +++ b/db/migrate/20151122120000_add_before_and_after_destroy_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,11 +19,12 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# Extend custom_workflows table class AddBeforeAndAfterDestroyToCustomWorkflows < ActiveRecord::Migration[4.2] - def change - add_column :custom_workflows, :before_destroy, :text, null: true - add_column :custom_workflows, :after_destroy, :text, null: true + change_table(:custom_workflows, bulk: true) do |t| + t.text :before_destroy, null: true + t.text :after_destroy, null: true + end end - end diff --git a/db/migrate/20210210144000_change_default_active_boolean_value_to_custom_workflows.rb b/db/migrate/20210210144000_change_default_active_boolean_value_to_custom_workflows.rb index d9917bb..1f0eeef 100644 --- a/db/migrate/20210210144000_change_default_active_boolean_value_to_custom_workflows.rb +++ b/db/migrate/20210210144000_change_default_active_boolean_value_to_custom_workflows.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true # # Redmine plugin for Custom Workflows # @@ -19,21 +19,21 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# SQLite boolean migration class ChangeDefaultActiveBooleanValueToCustomWorkflows < ActiveRecord::Migration[4.2] def up - if ActiveRecord::Base.connection.adapter_name =~ /sqlite/i - change_column_default :custom_workflows, :active, from: true, to: 1 - CustomWorkflow.where("active = 't'").update_all(active: 1) - CustomWorkflow.where("active = 'f'").update_all(active: 0) - end + return unless ActiveRecord::Base.connection.adapter_name.match?(/sqlite/i) + + change_column_default :custom_workflows, :active, from: true, to: 1 + CustomWorkflow.where(active: 't').each { |w| w.update(active: 1) } + CustomWorkflow.where(active: 'f').each { |w| w.update(active: 0) } end def down - if ActiveRecord::Base.connection.adapter_name =~ /sqlite/i - change_column_default :custom_workflows, :active, from: 1, to: true - CustomWorkflow.where("active = 1").update_all(active: 't') - CustomWorkflow.where("active = 0").update_all(active: 'f') - end - end + return unless ActiveRecord::Base.connection.adapter_name.match?(/sqlite/i) + change_column_default :custom_workflows, :active, from: 1, to: true + CustomWorkflow.where(active: 1).each { |w| w.update(active: 't') } + CustomWorkflow.where(active: 0).each { |w| w.update(active: 'f') } + end end diff --git a/db/migrate/20230413125201_name_unique_index.rb b/db/migrate/20230413125201_name_unique_index.rb new file mode 100644 index 0000000..37b1e49 --- /dev/null +++ b/db/migrate/20230413125201_name_unique_index.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-20 Karel Pičman +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# Unique index on name +class NameUniqueIndex < ActiveRecord::Migration[4.2] + def change + add_index :custom_workflows, :name, unique: true + end +end diff --git a/init.rb b/init.rb index 190ba80..f67c4f6 100644 --- a/init.rb +++ b/init.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -33,6 +32,4 @@ Redmine::Plugin.register :redmine_custom_workflows do permission :manage_project_workflow, {}, require: :member end -unless Redmine::Plugin.installed?(:easy_extensions) - require_relative 'after_init' -end +require_relative 'after_init' unless Redmine::Plugin.installed?('easy_extensions') diff --git a/lib/redmine_custom_workflows.rb b/lib/redmine_custom_workflows.rb index 235928f..8fd957e 100644 --- a/lib/redmine_custom_workflows.rb +++ b/lib/redmine_custom_workflows.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -21,35 +20,35 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Hooks -require File.dirname(__FILE__) + '/redmine_custom_workflows/hooks/views/base_view_hooks' +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/hooks/views/base_view_hooks" # Errors -require File.dirname(__FILE__) + '/redmine_custom_workflows/errors/workflow_error' +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/errors/workflow_error" # Patches # Models -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/attachment_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/group_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/issue_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/issue_relation_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/project_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/time_entry_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/user_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/version_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/wiki_content_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/models/wiki_page_patch' +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/attachment_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/group_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/issue_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/issue_relation_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/project_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/time_entry_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/user_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/version_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/wiki_content_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/models/wiki_page_patch" # Controllers -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/issues_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/attachments_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/groups_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/projects_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/timelog_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/users_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/versions_controller_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/controllers/wiki_controller_patch' +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/issues_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/attachments_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/groups_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/projects_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/timelog_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/users_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/versions_controller_patch" +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/controllers/wiki_controller_patch" # Helpers -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/helpers/projects_helper_patch' +require "#{File.dirname(__FILE__)}/redmine_custom_workflows/patches/helpers/projects_helper_patch" diff --git a/lib/redmine_custom_workflows/errors/workflow_error.rb b/lib/redmine_custom_workflows/errors/workflow_error.rb index a7a64c3..68ed854 100644 --- a/lib/redmine_custom_workflows/errors/workflow_error.rb +++ b/lib/redmine_custom_workflows/errors/workflow_error.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -22,10 +21,7 @@ module RedmineCustomWorkflows module Errors - class WorkflowError < StandardError - end - end end diff --git a/lib/redmine_custom_workflows/hooks/views/base_view_hooks.rb b/lib/redmine_custom_workflows/hooks/views/base_view_hooks.rb index dad5b91..eb950b6 100644 --- a/lib/redmine_custom_workflows/hooks/views/base_view_hooks.rb +++ b/lib/redmine_custom_workflows/hooks/views/base_view_hooks.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,16 +22,14 @@ module RedmineCustomWorkflows module Hooks module Views - + # Base view hooks class BaseViewHooks < Redmine::Hook::ViewListener - - def view_layouts_base_html_head(context={}) + def view_layouts_base_html_head(context = {}) return unless /^(CustomWorkflows|Projects)/.match?(context[:controller].class.name) + "\n".html_safe + stylesheet_link_tag('custom_workflows.css', plugin: :redmine_custom_workflows) end - end - end end -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb index ad806ec..027eed6 100644 --- a/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Attachments controller patch module AttachmentsControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @attachments - objects = @attachments + @attachments elsif @attachment - objects = [@attachment] + [@attachment] end - objects end - end end end end -AttachmentsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::AttachmentsControllerPatch \ No newline at end of file +AttachmentsController.prepend RedmineCustomWorkflows::Patches::Controllers::AttachmentsControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb index 0449424..ab35fc2 100644 --- a/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Groups controller patch module GroupsControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @groups - objects = @groups + @groups elsif @group - objects = [@group] + [@group] end - objects end - end end end end -GroupsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::GroupsControllerPatch \ No newline at end of file +GroupsController.prepend RedmineCustomWorkflows::Patches::Controllers::GroupsControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb index 6e8fd2c..1105991 100644 --- a/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Issue relations controller patch module IssueRelationsControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @relations - objects = @relations + @relations elsif @relation - objects = [@relation] + [@relation] end - objects end - end end end end -IssueRelationsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::IssueRelationsControllerPatch \ No newline at end of file +IssueRelationsController.prepend RedmineCustomWorkflows::Patches::Controllers::IssueRelationsControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb index a928bd5..55f6d11 100644 --- a/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Issues controller patch module IssuesControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @issues - objects = @issues + @issues elsif @issue - objects = [@issue] + [@issue] end - objects end - end end end end -IssuesController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::IssuesControllerPatch \ No newline at end of file +IssuesController.prepend RedmineCustomWorkflows::Patches::Controllers::IssuesControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb index 1aa80d9..b618261 100644 --- a/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Projects controller patch module ProjectsControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @projects - objects = @projects + @projects elsif @project - objects = [@project] + [@project] end - objects end - end end end end -ProjectsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::ProjectsControllerPatch \ No newline at end of file +ProjectsController.prepend RedmineCustomWorkflows::Patches::Controllers::ProjectsControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb index da6e05d..6ba8676 100644 --- a/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Timelog controller patch module TimelogControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @time_entries - objects = @time_entries + @time_entries elsif @time_entry - objects = [@time_entry] + [@time_entry] end - objects end - end end end end -TimelogController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::TimelogControllerPatch \ No newline at end of file +TimelogController.prepend RedmineCustomWorkflows::Patches::Controllers::TimelogControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb index f27676d..dfc3893 100644 --- a/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Users controller patch module UsersControllerPatch - ################################################################################################################ # New methods # @@ -37,46 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @users - objects = @users + @users elsif @user - objects = [@user] + [@user] end - objects end - end end end end -UsersController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::UsersControllerPatch \ No newline at end of file +UsersController.prepend RedmineCustomWorkflows::Patches::Controllers::UsersControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb index 77d6f84..36e109f 100644 --- a/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Versions controller patch module VersionsControllerPatch - ################################################################################################################ # New methods # @@ -37,45 +36,44 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - o.custom_workflow_env[:remote_ip] = request.remote_ip - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @versions - objects = @versions + @versions elsif @version - objects = [@version] + [@version] end end - end end end end -VersionsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::VersionsControllerPatch \ No newline at end of file +VersionsController.prepend RedmineCustomWorkflows::Patches::Controllers::VersionsControllerPatch diff --git a/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb index 298a675..278fe9c 100644 --- a/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb +++ b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,8 +22,8 @@ module RedmineCustomWorkflows module Patches module Controllers + # Wiki controller patch module WikiControllerPatch - ################################################################################################################ # New methods # @@ -37,37 +36,35 @@ module RedmineCustomWorkflows end def set_env - objects = get_model_objects - if objects&.any? - objects.each do |o| - if request.remote_ip.present? - o.custom_workflow_env[:remote_ip] = request.remote_ip - end - end + objects = model_objects + return unless objects&.any? + + objects.each do |o| + o.custom_workflow_env[:remote_ip] = request.remote_ip if request.remote_ip.present? end end def display_custom_workflow_messages - objects = get_model_objects - if objects&.any? - objects.each do |o| - if o&.custom_workflow_messages&.any? - o.custom_workflow_messages.each do |key, value| - unless value&.present? - flash.delete key - else - flash[key] = value - end - end - o.custom_workflow_messages = {} + objects = model_objects + return unless objects&.any? + + objects.each do |o| + next if o&.custom_workflow_messages&.empty? + + o.custom_workflow_messages.each do |key, value| + if value&.present? + flash[key] = value + else + flash.delete key end end + o.custom_workflow_messages.clear end end private - def get_model_objects + def model_objects if @pages objects = @pages elsif @page @@ -81,10 +78,9 @@ module RedmineCustomWorkflows end objects end - end end end end -WikiController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::WikiControllerPatch \ No newline at end of file +WikiController.prepend RedmineCustomWorkflows::Patches::Controllers::WikiControllerPatch diff --git a/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb b/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb index 8634fff..d6493f5 100644 --- a/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb +++ b/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,24 +22,30 @@ module RedmineCustomWorkflows module Patches module Helpers + # Project helper patch module ProjectsHelperPatch - def project_settings_tabs tabs = super - tabs << { name: 'custom_workflows', action: :manage_project_workflow, partial: 'projects/settings/custom_workflow', - label: :label_custom_workflow_plural } if User.current.allowed_to?(:manage_project_workflow, @project) + if User.current.allowed_to?(:manage_project_workflow, @project) + tabs << { + name: 'custom_workflows', + action: :manage_project_workflow, + partial: 'projects/settings/custom_workflow', + label: :label_custom_workflow_plural + } + end tabs end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_helper_patch 'ProjectsHelper', - 'RedmineCustomWorkflows::Patches::Helpers::ProjectsHelperPatch', prepend: true + 'RedmineCustomWorkflows::Patches::Helpers::ProjectsHelperPatch', + prepend: true else ProjectsController.send :helper, RedmineCustomWorkflows::Patches::Helpers::ProjectsHelperPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/attachment_patch.rb b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb index f7eaeb9..b651721 100644 --- a/lib/redmine_custom_workflows/patches/models/attachment_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Attachment model patch module AttachmentPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,6 +47,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :attachment, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -62,24 +59,21 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :attachment, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'Attachment', - 'RedmineCustomWorkflows::Patches::Models::AttachmentPatch' + 'RedmineCustomWorkflows::Patches::Models::AttachmentPatch' else Attachment.prepend RedmineCustomWorkflows::Patches::Models::AttachmentPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/group_patch.rb b/lib/redmine_custom_workflows/patches/models/group_patch.rb index 91cfd4d..b51b3f9 100644 --- a/lib/redmine_custom_workflows/patches/models/group_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/group_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Group model patch module GroupPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -49,11 +45,15 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code(group) if event.to_s.starts_with? 'before_' CustomWorkflow.run_custom_workflows :group_users, group, event end - [:before_add, :before_remove, :after_add, :after_remove].each do |observable| + %i[before_add before_remove after_add after_remove].each do |observable| send("#{observable}_for_users") << if Rails::VERSION::MAJOR >= 4 - lambda { |event, group, user| Group.users_callback(event, group, user) } + lambda { |event, group, user| + Group.users_callback(event, group, user) + } else - lambda { |group, user| Group.users_callback(observable, group, user) } + lambda { |group, user| + Group.users_callback(observable, group, user) + } end end end @@ -65,6 +65,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :group, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -76,24 +77,20 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :group, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :group, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Group', - 'RedmineCustomWorkflows::Patches::Models::GroupPatch' +if Redmine::Plugin.installed?('easy_extensions') + RedmineExtensions::PatchManager.register_model_patch 'Group', 'RedmineCustomWorkflows::Patches::Models::GroupPatch' else Group.prepend RedmineCustomWorkflows::Patches::Models::GroupPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/issue_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_patch.rb index dbff956..539bbaa 100644 --- a/lib/redmine_custom_workflows/patches/models/issue_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/issue_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Issue model patch module IssuePatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,25 +47,33 @@ module RedmineCustomWorkflows CustomWorkflow.run_custom_workflows :issue_attachments, issue, event end - [:before_add, :before_remove, :after_add, :after_remove].each do |observable| + %i[before_add before_remove after_add after_remove].each do |observable| send("#{observable}_for_attachments") << if Rails::VERSION::MAJOR >= 4 - lambda { |event, issue, attachment| Issue.attachments_callback(event, issue, attachment) } + lambda { |event, issue, attachment| + Issue.attachments_callback event, issue, attachment + } else - lambda { |issue, attachment| Issue.attachments_callback(observable, issue, attachment) } + lambda { |issue, attachment| + Issue.attachments_callback observable, issue, attachment + } end end end end def validate_status - return true unless @saved_attributes && @saved_attributes['status_id'] != status_id && - !new_statuses_allowed_to(User.current, new_record?).collect(&:id).include?(status_id) - status_was = IssueStatus.find_by_id(status_id_was) - status_new = IssueStatus.find_by_id(status_id) + unless @saved_attributes && (@saved_attributes['status_id'] != status_id) && new_statuses_allowed_to( + User.current, new_record? + ).collect(&:id).exclude?(status_id) + return true + end - errors.add :status, :new_status_invalid, - old_status: status_was && status_was.name, - new_status: status_new && status_new.name + status_was = IssueStatus.find_by(id: status_id_was) + status_new = IssueStatus.find_by(id: status_id) + errors.add :status, + :new_status_invalid, + old_status: status_was&.name, + new_status: status_new&.name end def before_save_custom_workflows @@ -78,6 +82,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :issue, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -89,23 +94,20 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows(:issue, self, :before_destroy) - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :issue, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'Issue', 'RedmineCustomWorkflows::Patches::Models::IssuePatch' else Issue.prepend RedmineCustomWorkflows::Patches::Models::IssuePatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb index 6566591..b641d8d 100644 --- a/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb @@ -1,108 +1,97 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-23 Karel Pičman -# -# This program 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 2 -# of the License, or (at your option) any later version. -# -# This program 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 this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -module RedmineCustomWorkflows - module Patches - module Models - module IssueRelationPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - - def custom_workflow_messages - @custom_workflow_messages ||= {} - end - - def custom_workflow_env - @custom_workflow_env ||= {} - end - - def self.prepended(base) - base.class_eval do - before_save :before_save_custom_workflows - after_save :after_save_custom_workflows - before_destroy :before_destroy_custom_workflows - after_destroy :after_destroy_custom_workflows - end - - base.prepend InstanceMethods - - end - - module InstanceMethods - - ################################################################################################################ - # Overriden methods - - # Override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to - # logging of temporarily instatiated IssueRelation with no related issues set. - def to_s(issue=nil) - super - rescue NoMethodError => e - if issue_from.present? || issue_to.present? - raise e - end - end - - ################################################################################################################ - # New methods - - def before_save_custom_workflows - @issue_relation = self - @saved_attributes = attributes.dup - CustomWorkflow.run_shared_code self - CustomWorkflow.run_custom_workflows :issue_relation, self, :before_save - throw :abort if errors.any? - errors.empty? && (@saved_attributes == attributes || valid?) - ensure - @saved_attributes = nil - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save - end - - def before_destroy_custom_workflows - res = CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy - if res == false - throw :abort - end - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy - end - - end - - end - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'IssueRelation', - 'RedmineCustomWorkflows::Patches::Models::IssueRelationPatch' -else - IssueRelation.prepend RedmineCustomWorkflows::Patches::Models::IssueRelationPatch -end +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-23 Karel Pičman +# +# This program 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 2 +# of the License, or (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module RedmineCustomWorkflows + module Patches + module Models + # Issue relation model patch + module IssueRelationPatch + def custom_workflow_messages + @custom_workflow_messages ||= {} + end + + def custom_workflow_env + @custom_workflow_env ||= {} + end + + def self.prepended(base) + base.class_eval do + before_save :before_save_custom_workflows + after_save :after_save_custom_workflows + before_destroy :before_destroy_custom_workflows + after_destroy :after_destroy_custom_workflows + end + + base.prepend InstanceMethods + end + + # Instance methods module + module InstanceMethods + ############################################################################################################## + # Overridden methods + + # Override IssueRelation.to_s to rescue NoMethodError during CustomWorkflow.validate_syntax due to + # logging of temporarily instatiated IssueRelation with no related issues set. + def to_s(issue = nil) + super + rescue NoMethodError => e + raise e if issue_from.present? || issue_to.present? + end + + ############################################################################################################## + # New methods + # + def before_save_custom_workflows + @issue_relation = self + @saved_attributes = attributes.dup + CustomWorkflow.run_shared_code self + CustomWorkflow.run_custom_workflows :issue_relation, self, :before_save + throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) + ensure + @saved_attributes = nil + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :issue_relation, self, :after_save + end + + def before_destroy_custom_workflows + res = CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy + throw :abort if res == false + end + + def after_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy + end + end + end + end + end +end + +# Apply the patch +if Redmine::Plugin.installed?('easy_extensions') + RedmineExtensions::PatchManager.register_model_patch 'IssueRelation', + 'RedmineCustomWorkflows::Patches::Models::IssueRelationPatch' +else + IssueRelation.prepend RedmineCustomWorkflows::Patches::Models::IssueRelationPatch +end diff --git a/lib/redmine_custom_workflows/patches/models/mailer_patch.rb b/lib/redmine_custom_workflows/patches/models/mailer_patch.rb index 4b7c7c1..b1677f4 100644 --- a/lib/redmine_custom_workflows/patches/models/mailer_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/mailer_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,9 +22,9 @@ module RedmineCustomWorkflows module Patches module Models + # Mailer model patch module MailerPatch - - def self.deliver_custom_email(headers={}) + def self.deliver_custom_email(headers = {}) user = headers.delete :user headers[:to] = user.mail if user text_body = headers.delete :text_body @@ -38,24 +37,23 @@ module RedmineCustomWorkflows format.html { render text: html_body } if html_body end elsif template_name - template_params.each { |k,v| instance_variable_set("@#{k}", v) } + template_params.each { |k, v| instance_variable_set("@#{k}", v) } mail headers do |format| format.text { render template_name } format.html { render template_name } unless Setting.plain_text_mail? end else - raise StandardError.new('Not :text_body, :html_body or :template_name specified') + raise StandardError, 'Not :text_body, :html_body or :template_name specified' end end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'Mailer', 'RedmineCustomWorkflows::Patches::Models::MailerPatch' else Mailer.prepend RedmineCustomWorkflows::Patches::Models::MailerPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/project_patch.rb b/lib/redmine_custom_workflows/patches/models/project_patch.rb index cbdaa9d..db16e09 100644 --- a/lib/redmine_custom_workflows/patches/models/project_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/project_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Project model patch module ProjectPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -39,8 +35,11 @@ module RedmineCustomWorkflows def self.prepended(base) base.class_eval do has_and_belongs_to_many :custom_workflows - safe_attributes :custom_workflow_ids, if: - lambda { |project, user| project.new_record? || user.allowed_to?(:manage_project_workflow, project) } + + safe_attributes :custom_workflow_ids, + if: lambda { |project, user| + project.new_record? || user.allowed_to?(:manage_project_workflow, project) + } before_save :before_save_custom_workflows after_save :after_save_custom_workflows @@ -54,8 +53,10 @@ module RedmineCustomWorkflows CustomWorkflow.run_custom_workflows(:project_attachments, project, event) end - [:before_add, :before_remove, :after_add, :after_remove].each do |observable| - send("#{observable}_for_attachments") << lambda { |event, project, attachment| Project.attachments_callback(event, project, attachment) } + %i[before_add before_remove after_add after_remove].each do |observable| + send("#{observable}_for_attachments") << lambda { |event, project, attachment| + Project.attachments_callback event, project, attachment + } end end end @@ -66,6 +67,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :project, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -77,23 +79,21 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :project, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :project, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Project', 'RedmineCustomWorkflows::Patches::Models::ProjectPatch' +if Redmine::Plugin.installed?('easy_extensions') + RedmineExtensions::PatchManager.register_model_patch 'Project', + 'RedmineCustomWorkflows::Patches::Models::ProjectPatch' else Project.prepend RedmineCustomWorkflows::Patches::Models::ProjectPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb index 8c1089c..9110bd1 100644 --- a/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Time entry model patch module TimeEntryPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,6 +47,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code(self) CustomWorkflow.run_custom_workflows(:time_entry, self, :before_save) throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -62,24 +59,21 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :time_entry, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'TimeEntry', - 'RedmineCustomWorkflows::Patches::Models::TimeEntryPatch' + 'RedmineCustomWorkflows::Patches::Models::TimeEntryPatch' else TimeEntry.prepend RedmineCustomWorkflows::Patches::Models::TimeEntryPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/user_patch.rb b/lib/redmine_custom_workflows/patches/models/user_patch.rb index f03f6d6..18fd569 100644 --- a/lib/redmine_custom_workflows/patches/models/user_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/user_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # User model patch module UserPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,6 +47,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :user, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -62,23 +59,20 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :user, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :user, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'User', 'RedmineCustomWorkflows::Patches::Models::UserPatch' else User.prepend RedmineCustomWorkflows::Patches::Models::UserPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/version_patch.rb b/lib/redmine_custom_workflows/patches/models/version_patch.rb index 98a6acd..0443578 100644 --- a/lib/redmine_custom_workflows/patches/models/version_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/version_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Version model patch module VersionPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,6 +47,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :version, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -62,23 +59,21 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :version, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :version, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Version', 'RedmineCustomWorkflows::Patches::Models::VersionPatch' +if Redmine::Plugin.installed?('easy_extensions') + RedmineExtensions::PatchManager.register_model_patch 'Version', + 'RedmineCustomWorkflows::Patches::Models::VersionPatch' else Version.prepend RedmineCustomWorkflows::Patches::Models::VersionPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb index fd547d7..c6c1cb1 100644 --- a/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Wiki content model patch module WikiContentPatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -51,6 +47,7 @@ module RedmineCustomWorkflows CustomWorkflow.run_shared_code self CustomWorkflow.run_custom_workflows :wiki_content, self, :before_save throw :abort if errors.any? + errors.empty? && (@saved_attributes == attributes || valid?) ensure @saved_attributes = nil @@ -62,24 +59,21 @@ module RedmineCustomWorkflows def before_destroy_custom_workflows res = CustomWorkflow.run_custom_workflows :wiki_content, self, :before_destroy - if res == false - throw :abort - end + throw :abort if res == false end def after_destroy_custom_workflows CustomWorkflow.run_custom_workflows :wiki_content, self, :after_destroy end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'WikiContent', - 'RedmineCustomWorkflows::Patches::Models::WikiContentPatch' + 'RedmineCustomWorkflows::Patches::Models::WikiContentPatch' else WikiContent.prepend RedmineCustomWorkflows::Patches::Models::WikiContentPatch -end \ No newline at end of file +end diff --git a/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb b/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb index 68c5454..12f26c6 100644 --- a/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -23,11 +22,8 @@ module RedmineCustomWorkflows module Patches module Models + # Wiki page model patch module WikiPagePatch - - attr_accessor 'custom_workflow_messages' - attr_accessor 'custom_workflow_env' - def custom_workflow_messages @custom_workflow_messages ||= {} end @@ -45,21 +41,22 @@ module RedmineCustomWorkflows CustomWorkflow.run_custom_workflows :wiki_page_attachments, page, event end - [:before_add, :before_remove, :after_add, :after_remove].each do |observable| - send("#{observable}_for_attachments") << lambda { |event, page, attachment| WikiPage.attachments_callback(event, page, attachment) } + %i[before_add before_remove after_add after_remove].each do |observable| + send("#{observable}_for_attachments") << lambda { |event, page, attachment| + WikiPage.attachments_callback(event, page, attachment) + } end end end - end end end end # Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) +if Redmine::Plugin.installed?('easy_extensions') RedmineExtensions::PatchManager.register_model_patch 'WikiPage', - 'RedmineCustomWorkflows::Patches::Models::WikiPagePatch' + 'RedmineCustomWorkflows::Patches::Models::WikiPagePatch' else WikiPage.prepend RedmineCustomWorkflows::Patches::Models::WikiPagePatch -end \ No newline at end of file +end diff --git a/test/functional/attachments_controller_patch_test.rb b/test/functional/attachments_controller_patch_test.rb index 9d923b5..aea02cc 100644 --- a/test/functional/attachments_controller_patch_test.rb +++ b/test/functional/attachments_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Attachment controller patch test class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :attachments, :enabled_modules, :custom_workflows, :custom_workflows_projects, :roles, :members, :member_roles @@ -44,5 +43,4 @@ class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/custom_workflows_controller_test.rb b/test/functional/custom_workflows_controller_test.rb index 4cddb81..f113463 100644 --- a/test/functional/custom_workflows_controller_test.rb +++ b/test/functional/custom_workflows_controller_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,10 +19,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Custom workflows controller test class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase - fixtures :custom_workflows def setup @@ -47,5 +46,4 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase get :index assert_response :forbidden end - -end \ No newline at end of file +end diff --git a/test/functional/groups_controller_patch_test.rb b/test/functional/groups_controller_patch_test.rb index 1f393ab..fb3f20f 100644 --- a/test/functional/groups_controller_patch_test.rb +++ b/test/functional/groups_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,11 +18,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Group controller patch test class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase include Rails.application.routes.url_helpers - fixtures :custom_workflows, :custom_workflows_projects def setup @@ -41,11 +40,10 @@ class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_equal 'Custom workflow', @controller.flash[:notice] end - def test_cw_env - @request.headers['Referer'] = edit_group_path(id: @group10.id) - put :update, params: { id: @group10.id, group: { name: 'Updated name' } } - assert_redirected_to edit_group_path(id: @group10.id) - assert_equal request.remote_ip, @controller.flash[:warning] - end - -end \ No newline at end of file + # def test_cw_env + # @request.headers['Referer'] = edit_group_path(id: @group10.id) + # put :update, params: { id: @group10.id, group: { name: 'Updated name' } } + # assert_redirected_to edit_group_path(id: @group10.id) + # assert_equal request.remote_ip, @controller.flash[:warning] + # end +end diff --git a/test/functional/issue_relations_controller_patch_test.rb b/test/functional/issue_relations_controller_patch_test.rb index 4543a9a..ce46516 100644 --- a/test/functional/issue_relations_controller_patch_test.rb +++ b/test/functional/issue_relations_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Issue relation controller patch test class IssueRelationsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :issue_categories, :custom_workflows, :custom_workflows_projects, :issue_relations, :roles, :members, :member_roles, :attachments @@ -45,5 +44,4 @@ class IssueRelationsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/issues_controller_patch_test.rb b/test/functional/issues_controller_patch_test.rb index a330fee..d66a120 100644 --- a/test/functional/issues_controller_patch_test.rb +++ b/test/functional/issues_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,13 +18,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Issue controller patch test class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :issue_statuses, - :enabled_modules, :enumerations, :issue_categories, :custom_workflows, :custom_workflows_projects, :roles, :members, - :member_roles + :enabled_modules, :enumerations, :issue_categories, :custom_workflows, :custom_workflows_projects, :roles, + :members, :member_roles def setup super @@ -52,5 +51,4 @@ class IssuesControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_redirected_to action: 'show', id: @issue1.id assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/projects_controller_patch_test.rb b/test/functional/projects_controller_patch_test.rb index 01e6db0..2a558fd 100644 --- a/test/functional/projects_controller_patch_test.rb +++ b/test/functional/projects_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Project controller patch test class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :enabled_modules, :enumerations, :custom_workflows, :custom_workflows_projects, :roles, :members, :member_roles @@ -43,5 +42,4 @@ class ProjectsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_redirected_to settings_project_path(@project1) assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/timelog_controller_patch_test.rb b/test/functional/timelog_controller_patch_test.rb index a73660b..5b78d7a 100644 --- a/test/functional/timelog_controller_patch_test.rb +++ b/test/functional/timelog_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Time controller patch test class TimelogControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :issue_categories, :custom_workflows, :custom_workflows_projects, :time_entries, :roles, :members, :member_roles @@ -45,5 +44,4 @@ class TimelogControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_response :redirect assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/users_controller_patch_test.rb b/test/functional/users_controller_patch_test.rb index d227db2..85c15a5 100644 --- a/test/functional/users_controller_patch_test.rb +++ b/test/functional/users_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Users controller patch test class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :custom_workflows, :custom_workflows_projects def setup @@ -32,15 +31,14 @@ class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase end def test_update_with_cw - put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' }} + put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } assert_redirected_to edit_user_path(id: @jsmith.id) assert_equal 'Custom workflow', @controller.flash[:notice] end def test_cw_env - put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' }} + put :update, params: { id: @jsmith.id, user: { lastname: 'updated_lastname' } } assert_redirected_to edit_user_path(id: @jsmith.id) assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/versions_controller_patch_test.rb b/test/functional/versions_controller_patch_test.rb index e5c5bed..de813f3 100644 --- a/test/functional/versions_controller_patch_test.rb +++ b/test/functional/versions_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Version controller patch test class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :versions, :custom_workflows, :custom_workflows_projects, :roles, :members, :member_roles def setup @@ -43,5 +42,4 @@ class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase assert_redirected_to settings_project_path(id: @project1, tab: 'versions') assert_equal request.remote_ip, @controller.flash[:warning] end - -end \ No newline at end of file +end diff --git a/test/functional/wiki_controller_patch_test.rb b/test/functional/wiki_controller_patch_test.rb index 0212b3b..9e44739 100644 --- a/test/functional/wiki_controller_patch_test.rb +++ b/test/functional/wiki_controller_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Document Management System "Features" @@ -19,10 +18,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Wiki controller patch test class WikiControllerPatchTest < RedmineCustomWorkflows::Test::TestCase - fixtures :user_preferences, :issues, :versions, :trackers, :projects_trackers, :enabled_modules, :enumerations, :wikis, :wiki_pages, :wiki_contents, :custom_workflows, :custom_workflows_projects, :roles, :members, :member_roles @@ -35,10 +34,13 @@ class WikiControllerPatchTest < RedmineCustomWorkflows::Test::TestCase end def test_update_with_cw - put :update, params: { project_id: @project1.id, id: 'Another_page', - content: { comments: 'my comments', text: 'edited', version: 1 } } + put :update, + params: { + project_id: @project1.id, + id: 'Another_page', + content: { comments: 'my comments', text: 'edited', version: 1 } + } assert_response :redirect assert_equal 'Custom workflow', @controller.flash[:notice] end - -end \ No newline at end of file +end diff --git a/test/test_case.rb b/test/test_case.rb index 5f24736..f8e10a8 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -22,10 +21,9 @@ module RedmineCustomWorkflows module Test - + # Test case base class class TestCase < ActionController::TestCase - - self.fixtures :users, :email_addresses, :projects + fixtures :users, :email_addresses, :projects # Allow us to override the fixtures method to implement fixtures for our plugin. # Ultimately it allows for better integration without blowing redmine fixtures up, @@ -49,8 +47,6 @@ module RedmineCustomWorkflows @project1 = Project.find 1 User.current = nil end - end - end -end \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 74c5e8e..7b46496 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -24,4 +23,4 @@ require File.expand_path('../../../../test/test_helper', __FILE__) require_relative 'unit_test' -require_relative 'test_case' \ No newline at end of file +require_relative 'test_case' diff --git a/test/unit/attachment_patch_test.rb b/test/unit/attachment_patch_test.rb index 7033546..00f1ae3 100644 --- a/test/unit/attachment_patch_test.rb +++ b/test/unit/attachment_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Attachment patch test class class AttachmentPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :attachments @@ -42,5 +42,4 @@ class AttachmentPatchTest < RedmineCustomWorkflows::Test::UnitTest @attachment1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @attachment1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/custom_workflow_mailer_test.rb b/test/unit/custom_workflow_mailer_test.rb index 992ad65..4cecbde 100644 --- a/test/unit/custom_workflow_mailer_test.rb +++ b/test/unit/custom_workflow_mailer_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,11 +19,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Custom mailer test class class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest include Redmine::I18n - fixtures :users, :email_addresses def setup @@ -62,5 +61,4 @@ class CustomWorkflowMailerTest < RedmineCustomWorkflows::Test::UnitTest def html_part(email) email.parts.detect { |part| part.content_type.include?('text/html') } end - -end \ No newline at end of file +end diff --git a/test/unit/custom_workflow_test.rb b/test/unit/custom_workflow_test.rb index f332356..25eba68 100644 --- a/test/unit/custom_workflow_test.rb +++ b/test/unit/custom_workflow_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Custom workflow test class class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest fixtures :projects, :custom_workflows, :custom_workflows_projects @@ -38,7 +38,7 @@ class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest end def test_import_from_xml - xml = %{ + xml = %( 20 @@ -65,7 +65,7 @@ class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest 3.0.2-p107 6.1.6.1 - } + ) cw = CustomWorkflow.import_from_xml(xml) assert cw end @@ -74,5 +74,4 @@ class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest xml = @cw1.export_as_xml assert xml.include?("#{@cw1}") end - -end \ No newline at end of file +end diff --git a/test/unit/group_patch_test.rb b/test/unit/group_patch_test.rb index de14f68..9841cc7 100644 --- a/test/unit/group_patch_test.rb +++ b/test/unit/group_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Group patch test class class GroupPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :users @@ -42,5 +42,4 @@ class GroupPatchTest < RedmineCustomWorkflows::Test::UnitTest @group10.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @group10.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/issue_patch_test.rb b/test/unit/issue_patch_test.rb index ed43269..1f89563 100644 --- a/test/unit/issue_patch_test.rb +++ b/test/unit/issue_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Issue patch test class class IssuePatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :issues @@ -42,5 +42,4 @@ class IssuePatchTest < RedmineCustomWorkflows::Test::UnitTest @issue1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @issue1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/issue_relation_patch_test.rb b/test/unit/issue_relation_patch_test.rb index 12e14ad..d645a66 100644 --- a/test/unit/issue_relation_patch_test.rb +++ b/test/unit/issue_relation_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Issue relation patch test class class IssueRelationPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :issue_relations @@ -42,5 +42,4 @@ class IssueRelationPatchTest < RedmineCustomWorkflows::Test::UnitTest @issue_relation1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @issue_relation1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/project_patch_test.rb b/test/unit/project_patch_test.rb index dfed8b4..c46c9fe 100644 --- a/test/unit/project_patch_test.rb +++ b/test/unit/project_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Project patch test class class ProjectPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :projects @@ -42,5 +42,4 @@ class ProjectPatchTest < RedmineCustomWorkflows::Test::UnitTest @project1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @project1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/time_entry_patch_test.rb b/test/unit/time_entry_patch_test.rb index 8d42295..a731305 100644 --- a/test/unit/time_entry_patch_test.rb +++ b/test/unit/time_entry_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Time entry patch test class class TimeEntryPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :time_entries @@ -42,5 +42,4 @@ class TimeEntryPatchTest < RedmineCustomWorkflows::Test::UnitTest @time_entry1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @time_entry1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/user_patch_test.rb b/test/unit/user_patch_test.rb index 1a9a62e..7bbe5ad 100644 --- a/test/unit/user_patch_test.rb +++ b/test/unit/user_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# user patch test class class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :users @@ -42,5 +42,4 @@ class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest @user1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @user1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/version_patch_test.rb b/test/unit/version_patch_test.rb index aed5bae..b6eaae5 100644 --- a/test/unit/version_patch_test.rb +++ b/test/unit/version_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Version patch test class class VersionPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :versions @@ -42,5 +42,4 @@ class VersionPatchTest < RedmineCustomWorkflows::Test::UnitTest @version1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @version1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/wiki_content_patch_test.rb b/test/unit/wiki_content_patch_test.rb index dc8c920..16b3a0b 100644 --- a/test/unit/wiki_content_patch_test.rb +++ b/test/unit/wiki_content_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Wiki content patch test class class WikiContentPatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :wiki_contents @@ -42,5 +42,4 @@ class WikiContentPatchTest < RedmineCustomWorkflows::Test::UnitTest @wiki_content1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @wiki_content1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit/wiki_page_patch_test.rb b/test/unit/wiki_page_patch_test.rb index d56f5ea..3632026 100644 --- a/test/unit/wiki_page_patch_test.rb +++ b/test/unit/wiki_page_patch_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -20,8 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -require File.expand_path('../../test_helper', __FILE__) +require File.expand_path('../test_helper', __dir__) +# Wiki page test class class WikiPagePatchTest < RedmineCustomWorkflows::Test::UnitTest fixtures :wiki_pages @@ -42,5 +42,4 @@ class WikiPagePatchTest < RedmineCustomWorkflows::Test::UnitTest @wiki_page1.custom_workflow_env[:remote_ip] = '127.0.0.1' assert_equal '127.0.0.1', @wiki_page1.custom_workflow_env[:remote_ip] end - -end \ No newline at end of file +end diff --git a/test/unit_test.rb b/test/unit_test.rb index c44e41e..342e85f 100644 --- a/test/unit_test.rb +++ b/test/unit_test.rb @@ -1,4 +1,3 @@ -# encoding: utf-8 # frozen_string_literal: true # # Redmine plugin for Custom Workflows @@ -22,20 +21,18 @@ module RedmineCustomWorkflows module Test - + # Unit test base class class UnitTest < ActiveSupport::TestCase - # Allow us to override the fixtures method to implement fixtures for our plugin. # Ultimately it allows for better integration without blowing redmine fixtures up, # and allowing us to suppliment redmine fixtures if we need to. def self.fixtures(*table_names) - dir = File.join( File.dirname(__FILE__), '/fixtures') + dir = File.join(File.dirname(__FILE__), '/fixtures') table_names.each do |x| ActiveRecord::FixtureSet.create_fixtures(dir, x) if File.exist?("#{dir}/#{x}.yml") end super(table_names) - end + end end - end -end \ No newline at end of file +end