Rubocop tests

This commit is contained in:
Karel Pičman 2023-04-14 09:44:36 +02:00
parent 11164f452f
commit 042761b6e0
83 changed files with 887 additions and 869 deletions

View File

@ -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

60
.rubocop.yml Normal file
View File

@ -0,0 +1,60 @@
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-23 Karel Pičman <karel.picman@kontron.com>
#
# 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

View File

@ -1,4 +1,4 @@
# encoding: utf-8
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows
#

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,25 @@
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-23 Karel Pičman <karel.picman@kontron.com>
#
# 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

View File

@ -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)
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?) })
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,44 +102,44 @@ 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
fields = case observable.to_sym
when :shared
fields = [shared_code]
[shared_code]
when *SINGLE_OBSERVABLES
fields = [before_save, after_save, before_destroy, after_destroy]
[before_save, after_save, before_destroy, after_destroy]
when *COLLECTION_OBSERVABLES
fields = [before_add, after_add, before_remove, after_remove]
[before_add, after_add, before_remove, after_remove]
else
fields = []
end
unless fields.any? {|field| field.present?}
errors.add :base, :scripts_absent
[]
end
errors.add(:base, :scripts_absent) unless fields.any?(&:present?)
end
def validate_syntax
@ -142,7 +151,7 @@ class CustomWorkflow < ActiveRecord::Base
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}
%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
@ -164,12 +173,12 @@ class CustomWorkflow < ActiveRecord::Base
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 }
%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

View File

@ -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

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -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? %></p>
<p><%= f.text_area :description, class: 'wiki-edit' %></p>
<% if @workflow.has_projects_association? %>
<% if @workflow.projects_association? %>
<p>
<%= f.check_box :is_for_all, onclick: "checkAndDisable('custom_workflow_enabled_projects', this.checked);",
label: :field_enabled_for_all_projects %>
@ -42,7 +40,7 @@
<p><%= f.check_box :active, label: l(:field_active) %></p>
</div>
</div>
<% if @workflow.has_projects_association? %>
<% if @workflow.projects_association? %>
<div class="splitcontentright">
<div class="box tabular">
<%= content_tag 'fieldset', id: 'custom_workflow_enabled_projects' do %>

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -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 %>');

View File

@ -1,6 +1,4 @@
<%
# encoding: utf-8
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
create_join_table :projects, :custom_workflows
end
add_index :custom_workflows_projects, [:project_id]
add_index :custom_workflows_projects, [:custom_workflow_id]
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-23 Karel Pičman <karel.picman@kontron.com>
#
# 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
return unless ActiveRecord::Base.connection.adapter_name.match?(/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
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

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows
#
# Copyright © 2015-19 Anton Argirov
# Copyright © 2019-20 Karel Pičman <karel.picman@kontron.com>
#
# 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

View File

@ -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')

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
AttachmentsController.prepend RedmineCustomWorkflows::Patches::Controllers::AttachmentsControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
GroupsController.prepend RedmineCustomWorkflows::Patches::Controllers::GroupsControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
IssueRelationsController.prepend RedmineCustomWorkflows::Patches::Controllers::IssueRelationsControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
IssuesController.prepend RedmineCustomWorkflows::Patches::Controllers::IssuesControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
ProjectsController.prepend RedmineCustomWorkflows::Patches::Controllers::ProjectsControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
TimelogController.prepend RedmineCustomWorkflows::Patches::Controllers::TimelogControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
UsersController.prepend RedmineCustomWorkflows::Patches::Controllers::UsersControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
end
def display_custom_workflow_messages
objects = get_model_objects
if objects&.any?
objects = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
VersionsController.prepend RedmineCustomWorkflows::Patches::Controllers::VersionsControllerPatch

View File

@ -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 = model_objects
return unless objects&.any?
objects.each do |o|
if request.remote_ip.present?
o.custom_workflow_env[:remote_ip] = request.remote_ip
end
end
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 = model_objects
return unless objects&.any?
objects.each do |o|
if o&.custom_workflow_messages&.any?
next if o&.custom_workflow_messages&.empty?
o.custom_workflow_messages.each do |key, value|
unless value&.present?
flash.delete key
else
if value&.present?
flash[key] = value
else
flash.delete key
end
end
o.custom_workflow_messages = {}
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
WikiController.prepend RedmineCustomWorkflows::Patches::Controllers::WikiControllerPatch

View File

@ -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

View File

@ -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,22 +59,19 @@ 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'
else

View File

@ -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

View File

@ -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,22 +94,19 @@ 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

View File

@ -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 relation model patch
module IssueRelationPatch
attr_accessor 'custom_workflow_messages'
attr_accessor 'custom_workflow_env'
def custom_workflow_messages
@custom_workflow_messages ||= {}
end
@ -45,27 +41,24 @@ module RedmineCustomWorkflows
end
base.prepend InstanceMethods
end
# Instance methods module
module InstanceMethods
################################################################################################################
# Overriden methods
##############################################################################################################
# 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)
def to_s(issue = nil)
super
rescue NoMethodError => e
if issue_from.present? || issue_to.present?
raise e
end
raise e if issue_from.present? || issue_to.present?
end
################################################################################################################
##############################################################################################################
# New methods
#
def before_save_custom_workflows
@issue_relation = self
@saved_attributes = attributes.dup
@ -83,24 +76,20 @@ module RedmineCustomWorkflows
def before_destroy_custom_workflows
res = CustomWorkflow.run_custom_workflows :issue_relation, 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_relation, self, :after_destroy
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 'IssueRelation',
'RedmineCustomWorkflows::Patches::Models::IssueRelationPatch'
else

View File

@ -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,23 +37,22 @@ 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

View File

@ -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

View File

@ -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,22 +59,19 @@ 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'
else

View File

@ -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,22 +59,19 @@ 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

View File

@ -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

View File

@ -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,22 +59,19 @@ 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'
else

View File

@ -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,19 +41,20 @@ 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'
else

View File

@ -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

View File

@ -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

View File

@ -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
# 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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,4 +1,3 @@
# encoding: utf-8
# frozen_string_literal: true
#
# Redmine plugin for Custom Workflows

View File

@ -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

View File

@ -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

View File

@ -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 = %(
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<id type="integer">20</id>
@ -65,7 +65,7 @@ class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest
<ruby-version>3.0.2-p107</ruby-version>
<rails-version>6.1.6.1</rails-version>
</hash>
}
)
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?("<name>#{@cw1}</name>")
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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