From fc0290115146de3279dab6e9ebe1408effd30a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Fri, 23 Sep 2022 08:27:26 +0200 Subject: [PATCH] #39 Ability to raise a warning or info --- README.md | 146 ++++++++++----- app/models/custom_workflow.rb | 26 +-- lib/redmine_custom_workflows.rb | 37 ++-- .../patches/attachment_patch.rb | 68 ------- .../attachments_controller_patch.rb | 65 +++++++ .../controllers/groups_controller_patch.rb | 65 +++++++ .../issue_relations_controller_patch.rb | 65 +++++++ .../controllers/issues_controller_patch.rb | 65 +++++++ .../controllers/projects_controller_patch.rb | 65 +++++++ .../controllers/timelog_controller_patch.rb | 65 +++++++ .../controllers/users_controller_patch.rb | 65 +++++++ .../controllers/versions_controller_patch.rb | 65 +++++++ .../controllers/wiki_controller_patch.rb | 69 +++++++ .../patches/group_patch.rb | 83 --------- .../{ => helpers}/projects_helper_patch.rb | 20 +- .../patches/issue_relation_patch.rb | 91 --------- .../patches/mailer_patch.rb | 59 ------ .../patches/models/attachment_patch.rb | 77 ++++++++ .../patches/models/group_patch.rb | 91 +++++++++ .../patches/{ => models}/issue_patch.rb | 60 +++--- .../patches/models/issue_relation_patch.rb | 100 ++++++++++ .../patches/models/mailer_patch.rb | 61 ++++++ .../patches/models/project_patch.rb | 91 +++++++++ .../patches/models/time_entry_patch.rb | 77 ++++++++ .../patches/models/user_patch.rb | 76 ++++++++ .../patches/models/version_patch.rb | 76 ++++++++ .../patches/models/wiki_content_patch.rb | 77 ++++++++ .../patches/{ => models}/wiki_page_patch.rb | 37 ++-- .../patches/project_patch.rb | 83 --------- .../patches/time_entry_patch.rb | 68 ------- .../patches/user_patch.rb | 68 ------- .../patches/version_patch.rb | 68 ------- .../patches/wiki_content_patch.rb | 68 ------- test/fixtures/custom_workflows.yml | 176 +++++++++++++++++- test/fixtures/custom_workflows_projects.yml | 18 +- .../attachments_controller_patch_test.rb | 42 +++++ .../custom_workflows_controller_test.rb | 12 +- .../groups_controller_patch_test.rb | 44 +++++ .../issue_relations_controller_patch_test.rb | 43 +++++ .../issues_controller_patch_test.rb | 43 +++++ .../projects_controller_patch_test.rb | 41 ++++ .../timelog_controller_patch_test.rb | 43 +++++ .../functional/users_controller_patch_test.rb | 40 ++++ .../versions_controller_patch_test.rb | 41 ++++ test/functional/wiki_controller_patch_test.rb | 44 +++++ .../test => test}/test_case.rb | 33 ++-- test/test_helper.rb | 3 +- .../unit/attachment_patch_test.rb | 32 ++-- test/unit/custom_workflow_test.rb | 37 ++++ test/unit/group_patch_test.rb | 41 ++++ test/unit/issue_patch_test.rb | 41 ++++ test/unit/issue_relation_patch_test.rb | 41 ++++ test/unit/project_patch_test.rb | 41 ++++ test/unit/time_entry_patch_test.rb | 41 ++++ test/unit/user_patch_test.rb | 41 ++++ test/unit/version_patch_test.rb | 41 ++++ test/unit/wiki_content_patch_test.rb | 41 ++++ test/unit/wiki_page_patch_test.rb | 41 ++++ 58 files changed, 2534 insertions(+), 824 deletions(-) delete mode 100644 lib/redmine_custom_workflows/patches/attachment_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/group_patch.rb rename lib/redmine_custom_workflows/patches/{ => helpers}/projects_helper_patch.rb (70%) delete mode 100644 lib/redmine_custom_workflows/patches/issue_relation_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/mailer_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/attachment_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/group_patch.rb rename lib/redmine_custom_workflows/patches/{ => models}/issue_patch.rb (58%) create mode 100644 lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/mailer_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/project_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/time_entry_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/user_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/version_patch.rb create mode 100644 lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb rename lib/redmine_custom_workflows/patches/{ => models}/wiki_page_patch.rb (52%) delete mode 100644 lib/redmine_custom_workflows/patches/project_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/time_entry_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/user_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/version_patch.rb delete mode 100644 lib/redmine_custom_workflows/patches/wiki_content_patch.rb create mode 100644 test/functional/attachments_controller_patch_test.rb create mode 100644 test/functional/groups_controller_patch_test.rb create mode 100644 test/functional/issue_relations_controller_patch_test.rb create mode 100644 test/functional/issues_controller_patch_test.rb create mode 100644 test/functional/projects_controller_patch_test.rb create mode 100644 test/functional/timelog_controller_patch_test.rb create mode 100644 test/functional/users_controller_patch_test.rb create mode 100644 test/functional/versions_controller_patch_test.rb create mode 100644 test/functional/wiki_controller_patch_test.rb rename {lib/redmine_custom_workflows/test => test}/test_case.rb (70%) rename lib/redmine_custom_workflows/test/unit_test.rb => test/unit/attachment_patch_test.rb (58%) create mode 100644 test/unit/group_patch_test.rb create mode 100644 test/unit/issue_patch_test.rb create mode 100644 test/unit/issue_relation_patch_test.rb create mode 100644 test/unit/project_patch_test.rb create mode 100644 test/unit/time_entry_patch_test.rb create mode 100644 test/unit/user_patch_test.rb create mode 100644 test/unit/version_patch_test.rb create mode 100644 test/unit/wiki_content_patch_test.rb create mode 100644 test/unit/wiki_page_patch_test.rb diff --git a/README.md b/README.md index 047981c..215dcf9 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,33 @@ Custom Workflows plug-in 2.0.6 devel This plug-in provides a great functionality for those who is familiar with the Ruby language. It allows to customize workflow by defining own rules for issues processing. It's possible: + * To change issue properties if some conditions are met. -* To create new issues programmatically, if the conditions are met (for example you can create an issue in another project if the status of source issue is changed to specific value). +* To create new issues programmatically, if the conditions are met (for example you can create an issue in another +project if the status of source issue is changed to specific value). * To raise custom errors which will be displayed to the user, if he does something wrong. * To do anything that conforms to your needs. Supported observable objects: -* Issue (before_save, after_save) -* Group (before_save, after_save) -* User (before_save, after_save) -* Group users (before_add, after_add, before_remove, after_remove) + +* Attachment +* Group +* Issue +* Issue relations +* Time entry +* User +* Version +* Wiki * \ -`` - special type for workflows that running before all other workflows and can provide libraries of additional functions or classes. +`` - a special type for workflows that are running before all other workflows and can provide libraries of +additional functions or classes. Thanks to --------- -The initial development was supported by [DOM Digital Online Media GmbH](https://www.dom.de). The present development is supported by [Kontron](https://www.kontorn.com) +The initial development was supported by [DOM Digital Online Media GmbH](https://www.dom.de). The present development +is supported by [Kontron](https://www.kontron.com) Getting help ------------ @@ -71,70 +80,105 @@ systemctl restart apache2 Configuration ------------- -First, you need to define your own custom workflow(s). We already included one, called "Duration/Done Ratio/Status correlation". You'll find it after installing the plug-in. It demonstrates some possibilities of plug-in. +First, you need to define your own custom workflow(s). We already included one, called "Duration/Done Ratio/Status +correlation". You'll find it after installing the plug-in. It demonstrates some possibilities of the plug-in. -Go to the *Administration* section, then select Custom workflows. A list of defined workflows will appear. Here you can create new workflow, update, reorder and delete existing workflows. The order of workflows specifies the order in which workflow scripts will be executed. +Go to the **_Administration_** section, then select **_Custom workflows_**. A list of defined workflows will appear. Here +you can create a new workflow, update, reorder or delete the existing workflows. The order of workflows specifies the +order in which the workflow scripts will be executed. -Then click the Create a custom workflow button. Enter a short name and full description. Below you will see two textareas. Fill one or both textareas by Ruby-language scripts that will be executed before and after saving the issue (on before_save and after_save callbacks respectively). +Then click the **Create a custom workflow** button. Enter a short name and full description. Below you will see two text +areas. Fill one or both text areas with Ruby-language scripts that will be executed before and after saving the issue +(on _before_save_ and _after_save_ callbacks respectively). -Both scripts are executed in the context of the issue. So access properties and methods of the issue directly (or through keyword "self"). You can also raise exceptions by raise RedmineCustomWorkflows::Errors::WorkflowError, "Your message". If you change some properties of the issue before saving it, it will be revalidated then and additional validation errors can appear. +Both scripts are executed in the context of the issue. So, access properties and methods of the issue directly (or +through keyword `self`). You can also raise exceptions by raising `RedmineCustomWorkflows::Errors::WorkflowError` exception. +If you change some properties of the issue before saving it, it will be revalidated then and additional validation errors +can appear. + +E.g.: + +```ruby + raise RedmineCustomWorkflows::Errors::WorkflowError, 'Your message' +``` + +You can also display an info/warning/error message to the user using an observed object property `custom_workflow_messages`. + +E.g.: + +```ruby + self.custom_workflow_messages[:notice] = 'Custom workflow info' + self.custom_workflow_messages[:warning] = 'Custom workflow warning' + self.custom_workflow_messages[:error] = 'Custom workflow error' +``` Enabling custom workflows for projects -------------------------------- +-------------------------------------- -After you defined your custom workflow(s), you need to enable it for particular project(s). There are two ways of doing this. -* While editing existing or creating new custom workflow; -* In project settings (if the user has appropriate permission). Open Project settings. Go to the Custom workflows tab of the project settings and enable workflow(s) you need for this project. +After you defined your custom workflow(s), you need to enable it for particular project(s). (This is valid for project +related observable objects.) There are two ways of doing +this. +* While editing existing or creating a new custom workflow; +* In the project's settings (if the user has appropriate permission). Open **_Project settings_**. Go to +**_Custom workflows_** tab of the project's settings and enable those workflows you need for this project. -Now go to the *Issues* and test it. +Now go to the **_Issues_** and test it. -Duration/Done Ratio/Status correlation example ----------------------------------------------- +Examples +-------- + +### Duration/Done Ratio/Status correlation example Fill the "before save" script with: - if done_ratio_changed? - if done_ratio==100 && status_id==2 - self.status_id=3 - elsif [1,3,4].include?(status_id) && done_ratio<100 - self.status_id=2 - end - end - - if status_id_changed? - if status_id==2 - self.start_date ||= Time.now - end - if status_id==3 - self.done_ratio = 100 - self.start_date ||= created_on - self.due_date ||= Time.now - end +```ruby +if done_ratio_changed? + if (done_ratio == 100) && (status_id == 2) + self.status_id = 3 + elsif [1,3,4].include?(status_id) && (done_ratio < 100) + self.status_id = 2 end +end -Example of creating subtask if the issue's status has changed -------------------------------------------------------------- +if status_id_changed? + if (status_id == 2) + self.start_date ||= Time.now + end + if (status_id == 3) + self.done_ratio = 100 + self.start_date ||= created_on + self.due_date ||= Time.now + end +end +``` + +### Example of creating subtask if the issue's status has changed Fill the "before save" script with: - @need_create = status_id_changed? && !new_record? +```ruby +@need_create = status_id_changed? && !new_record? +``` Fill the "after save" script with: - if @need_create - issue = Issue.new( - :author => User.current, - :project => project, - :tracker => tracker, - :assigned_to => author, - :parent_issue_id => id, - :subject => "Subtask", - :description => "Description") - - issue.save! - end +```ruby +if @need_create + issue = Issue.new( + author: User.current, + project: project, + tracker: tracker, + assigned_to: author, + parent_issue_id: id, + subject: 'Subtask', + description: 'Description') + issue.save! +end +``` -Do not forget to check whether issue is just created. Here we create the new issue and newly created issue will also be passed to this script on save. So without check, it will create another sub-issue. And etc. Thus it will fall into infinite recursion. +Do not forget to check whether the issue is just created. Here, we create a new issue and newly created issue will also +be passed to this script on save event. So, without a check, it will create another sub-issue. And so on. Thus, it will +fall into infinite loop. Compatibility ------------- diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index 406a6e4..4095f90 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -38,9 +38,11 @@ class CustomWorkflow < ActiveRecord::Base scope :active, lambda { where(active: true) } scope :sorted, lambda { 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) + 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 @@ -162,20 +164,17 @@ 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} + [:before_add, :after_add, :before_remove, :after_remove].each { |field| validate_syntax_for object, field } end end def export_as_xml - only = [:author, :name, :description, :before_save, :after_save, :shared_code, :observable, - :before_add, :after_add, :before_remove, :after_remove, :before_destroy, :after_destroy, :created_at] - only = only.select { |p| self[p] } - to_xml :only => only do |xml| - xml.tag! 'exported-at', Time.current.xmlschema - xml.tag! 'plugin-version', Redmine::Plugin.find(:redmine_custom_workflows).version - xml.tag! 'ruby-version', "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" - xml.tag! 'rails-version', Rails::VERSION::STRING - end + attrs = self.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}" + attrs['rails-version'] = Rails::VERSION::STRING + attrs.to_xml end def <=>(other) @@ -185,4 +184,5 @@ class CustomWorkflow < ActiveRecord::Base def to_s name end + end diff --git a/lib/redmine_custom_workflows.rb b/lib/redmine_custom_workflows.rb index 149388e..cf571f0 100644 --- a/lib/redmine_custom_workflows.rb +++ b/lib/redmine_custom_workflows.rb @@ -27,14 +27,29 @@ require File.dirname(__FILE__) + '/redmine_custom_workflows/hooks/views/base_vie require File.dirname(__FILE__) + '/redmine_custom_workflows/errors/workflow_error' # Patches -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/attachment_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/group_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/issue_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/issue_relation_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/project_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/projects_helper_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/time_entry_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/user_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/version_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/wiki_content_patch' -require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/wiki_page_patch' + +# 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' + +# 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' + +# Helpers +require File.dirname(__FILE__) + '/redmine_custom_workflows/patches/helpers/projects_helper_patch' diff --git a/lib/redmine_custom_workflows/patches/attachment_patch.rb b/lib/redmine_custom_workflows/patches/attachment_patch.rb deleted file mode 100644 index 9a605f3..0000000 --- a/lib/redmine_custom_workflows/patches/attachment_patch.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 AttachmentPatch - - 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 - end - - def before_save_custom_workflows - @attachment = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :attachment, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :attachment, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Attachment', 'RedmineCustomWorkflows::Patches::AttachmentPatch' -else - Attachment.prepend RedmineCustomWorkflows::Patches::AttachmentPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb new file mode 100644 index 0000000..71da15d --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/attachments_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module AttachmentsControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @attachments + objects = @attachments + elsif @attachment + objects = [@attachment] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +AttachmentsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::AttachmentsControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb new file mode 100644 index 0000000..78a2977 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/groups_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module GroupsControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @groups + objects = @groups + elsif @group + objects = [@group] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +GroupsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::GroupsControllerPatch \ No newline at end of file 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 new file mode 100644 index 0000000..5d62feb --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/issue_relations_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module IssueRelationsControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @relations + objects = @relations + elsif @relation + objects = [@relation] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +IssueRelationsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::IssueRelationsControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb new file mode 100644 index 0000000..508678f --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/issues_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module IssuesControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @issues + objects = @issues + elsif @issue + objects = [@issue] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +IssuesController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::IssuesControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb new file mode 100644 index 0000000..2a7cb15 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/projects_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module ProjectsControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @projects + objects = @projects + elsif @project + objects = [@project] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +ProjectsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::ProjectsControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb new file mode 100644 index 0000000..6694dc2 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/timelog_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module TimelogControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @time_entries + objects = @time_entries + elsif @time_entry + objects = [@time_entry] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +TimelogController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::TimelogControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb new file mode 100644 index 0000000..e30a689 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/users_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module UsersControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @users + objects = @users + elsif @user + objects = [@user] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +UsersController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::UsersControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb new file mode 100644 index 0000000..6d74bd4 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/versions_controller_patch.rb @@ -0,0 +1,65 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module VersionsControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @versions + objects = @versions + elsif @version + objects = [@version] + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +VersionsController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::VersionsControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb new file mode 100644 index 0000000..83ca3c6 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/controllers/wiki_controller_patch.rb @@ -0,0 +1,69 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 Controllers + module WikiControllerPatch + + ################################################################################################################ + # New methods + # + + def self.prepended(base) + base.class_eval do + after_action :display_custom_workflow_messages + end + end + + def display_custom_workflow_messages + if @pages + objects = @pages + elsif @page + objects = [@page] + end + if @content + objects ||= [] + objects << @content + end + if objects&.any? + objects.each do |o| + if o&.custom_workflow_messages&.any? + o.custom_workflow_messages.each do |key, value| + if value.empty? + flash.delete key + else + flash[key] = value + end + end + o.custom_workflow_messages = {} + end + end + end + end + + end + end + end +end + +WikiController.send :prepend, RedmineCustomWorkflows::Patches::Controllers::WikiControllerPatch \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/group_patch.rb b/lib/redmine_custom_workflows/patches/group_patch.rb deleted file mode 100644 index 5c3e12c..0000000 --- a/lib/redmine_custom_workflows/patches/group_patch.rb +++ /dev/null @@ -1,83 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 GroupPatch - - 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 - - def self.users_callback(event, group, user) - group.instance_variable_set :@group, group - group.instance_variable_set :@user, user - 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| - send("#{observable}_for_users") << if Rails::VERSION::MAJOR >= 4 - lambda { |event, group, user| Group.users_callback(event, group, user) } - else - lambda { |group, user| Group.users_callback(observable, group, user) } - end - end - end - end - - def before_save_custom_workflows - @group = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :group, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :group, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :group, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Group', - 'RedmineCustomWorkflows::Patches::GroupPatch' -else - Group.prepend RedmineCustomWorkflows::Patches::GroupPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/projects_helper_patch.rb b/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb similarity index 70% rename from lib/redmine_custom_workflows/patches/projects_helper_patch.rb rename to lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb index b8c808a..326db81 100644 --- a/lib/redmine_custom_workflows/patches/projects_helper_patch.rb +++ b/lib/redmine_custom_workflows/patches/helpers/projects_helper_patch.rb @@ -22,15 +22,17 @@ module RedmineCustomWorkflows module Patches - module ProjectsHelperPatch + module Helpers + 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) + tabs + end - 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) - tabs end - end end end @@ -38,7 +40,7 @@ end # Apply the patch if Redmine::Plugin.installed?(:easy_extensions) RedmineExtensions::PatchManager.register_helper_patch 'ProjectsHelper', - 'RedmineCustomWorkflows::Patches::ProjectsHelperPatch', prepend: true + 'RedmineCustomWorkflows::Patches::Helpers::ProjectsHelperPatch', prepend: true else - ProjectsController.send :helper, RedmineCustomWorkflows::Patches::ProjectsHelperPatch + ProjectsController.send :helper, RedmineCustomWorkflows::Patches::Helpers::ProjectsHelperPatch end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/issue_relation_patch.rb b/lib/redmine_custom_workflows/patches/issue_relation_patch.rb deleted file mode 100644 index 83283ec..0000000 --- a/lib/redmine_custom_workflows/patches/issue_relation_patch.rb +++ /dev/null @@ -1,91 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 IssueRelationPatch - - 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 - CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :issue_relation, self, :after_destroy - end - - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'IssueRelation', 'RedmineCustomWorkflows::Patches::IssueRelationPatch' -else - IssueRelation.prepend RedmineCustomWorkflows::Patches::IssueRelationPatch -end diff --git a/lib/redmine_custom_workflows/patches/mailer_patch.rb b/lib/redmine_custom_workflows/patches/mailer_patch.rb deleted file mode 100644 index 7be9df7..0000000 --- a/lib/redmine_custom_workflows/patches/mailer_patch.rb +++ /dev/null @@ -1,59 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 MailerPatch - - def self.deliver_custom_email(headers={}) - user = headers.delete :user - headers[:to] = user.mail if user - text_body = headers.delete :text_body - html_body = headers.delete :html_body - template_name = headers.delete :template_name - template_params = headers.delete(:template_params) || {} - if text_body || html_body - mail headers do |format| - format.text { render text: text_body } if text_body - format.html { render text: html_body } if html_body - end - elsif template_name - 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') - end - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Mailer', 'RedmineCustomWorkflows::Patches::MailerPatch' -else - Mailer.prepend RedmineCustomWorkflows::Patches::MailerPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/attachment_patch.rb b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb new file mode 100644 index 0000000..4e3b519 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/attachment_patch.rb @@ -0,0 +1,77 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 AttachmentPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + end + + def before_save_custom_workflows + @attachment = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :attachment, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :attachment, self, :before_destroy + 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) + RedmineExtensions::PatchManager.register_model_patch 'Attachment', + 'RedmineCustomWorkflows::Patches::Models::AttachmentPatch' +else + Attachment.prepend RedmineCustomWorkflows::Patches::Models::AttachmentPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/group_patch.rb b/lib/redmine_custom_workflows/patches/models/group_patch.rb new file mode 100644 index 0000000..9a286d9 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/group_patch.rb @@ -0,0 +1,91 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 GroupPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + + def self.users_callback(event, group, user) + group.instance_variable_set :@group, group + group.instance_variable_set :@user, user + 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| + send("#{observable}_for_users") << if Rails::VERSION::MAJOR >= 4 + lambda { |event, group, user| Group.users_callback(event, group, user) } + else + lambda { |group, user| Group.users_callback(observable, group, user) } + end + end + end + end + + def before_save_custom_workflows + @group = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :group, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :group, self, :before_destroy + 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' +else + Group.prepend RedmineCustomWorkflows::Patches::Models::GroupPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/issue_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_patch.rb similarity index 58% rename from lib/redmine_custom_workflows/patches/issue_patch.rb rename to lib/redmine_custom_workflows/patches/models/issue_patch.rb index 46f114c..2631b80 100644 --- a/lib/redmine_custom_workflows/patches/issue_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/issue_patch.rb @@ -22,37 +22,43 @@ module RedmineCustomWorkflows module Patches - module IssuePatch + module Models + module IssuePatch - 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 - validate :validate_status + attr_accessor 'custom_workflow_messages' - def self.attachments_callback(event, issue, attachment) - issue.instance_variable_set :@issue, issue - issue.instance_variable_set :@attachment, attachment - CustomWorkflow.run_shared_code(issue) if event.to_s.starts_with? 'before_' - CustomWorkflow.run_custom_workflows :issue_attachments, issue, event - end + def custom_workflow_messages + @custom_workflow_messages ||= {} + end - [: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) } - else - lambda { |issue, attachment| Issue.attachments_callback(observable, issue, attachment) } - 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 + validate :validate_status + + def self.attachments_callback(event, issue, attachment) + issue.instance_variable_set :@issue, issue + issue.instance_variable_set :@attachment, attachment + CustomWorkflow.run_shared_code(issue) if event.to_s.starts_with? 'before_' + CustomWorkflow.run_custom_workflows :issue_attachments, issue, event + end + + [: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) } + else + lambda { |issue, attachment| Issue.attachments_callback(observable, issue, attachment) } + end + 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) @@ -77,20 +83,24 @@ module RedmineCustomWorkflows end def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :issue, self, :before_destroy + res = CustomWorkflow.run_custom_workflows(:issue, self, :before_destroy) + if res === false + throw :abort + end 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) - RedmineExtensions::PatchManager.register_model_patch 'Issue', 'RedmineCustomWorkflows::Patches::IssuePatch' + RedmineExtensions::PatchManager.register_model_patch 'Issue', 'RedmineCustomWorkflows::Patches::Models::IssuePatch' else - Issue.prepend RedmineCustomWorkflows::Patches::IssuePatch + Issue.prepend RedmineCustomWorkflows::Patches::Models::IssuePatch end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb new file mode 100644 index 0000000..31d50e6 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/issue_relation_patch.rb @@ -0,0 +1,100 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + CustomWorkflow.run_custom_workflows :issue_relation, self, :before_destroy + 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 new file mode 100644 index 0000000..32dc5c9 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/mailer_patch.rb @@ -0,0 +1,61 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 MailerPatch + + def self.deliver_custom_email(headers={}) + user = headers.delete :user + headers[:to] = user.mail if user + text_body = headers.delete :text_body + html_body = headers.delete :html_body + template_name = headers.delete :template_name + template_params = headers.delete(:template_params) || {} + if text_body || html_body + mail headers do |format| + format.text { render text: text_body } if text_body + format.html { render text: html_body } if html_body + end + elsif template_name + 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') + end + end + + end + end + end +end + +# Apply the patch +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 diff --git a/lib/redmine_custom_workflows/patches/models/project_patch.rb b/lib/redmine_custom_workflows/patches/models/project_patch.rb new file mode 100644 index 0000000..3f51249 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/project_patch.rb @@ -0,0 +1,91 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 ProjectPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + end + + 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) } + + before_save :before_save_custom_workflows + after_save :after_save_custom_workflows + before_destroy :before_destroy_custom_workflows + after_destroy :after_destroy_custom_workflows + + def self.attachments_callback(event, project, attachment) + project.instance_variable_set(:@project, project) + project.instance_variable_set(:@attachment, attachment) + CustomWorkflow.run_shared_code(project) if event.to_s.starts_with? 'before_' + 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) } + end + end + end + + def before_save_custom_workflows + @project = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :project, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :project, self, :before_destroy + 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' +else + Project.prepend RedmineCustomWorkflows::Patches::Models::ProjectPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb new file mode 100644 index 0000000..14da014 --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/time_entry_patch.rb @@ -0,0 +1,77 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 TimeEntryPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + end + + def before_save_custom_workflows + @time_entry = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :time_entry, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy + 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) + RedmineExtensions::PatchManager.register_model_patch 'TimeEntry', + 'RedmineCustomWorkflows::Patches::Models::TimeEntryPatch' +else + TimeEntry.prepend RedmineCustomWorkflows::Patches::Models::TimeEntryPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/user_patch.rb b/lib/redmine_custom_workflows/patches/models/user_patch.rb new file mode 100644 index 0000000..d30af3c --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/user_patch.rb @@ -0,0 +1,76 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 UserPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + end + + def before_save_custom_workflows + @user = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :user, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :user, self, :before_destroy + 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) + RedmineExtensions::PatchManager.register_model_patch 'User', 'RedmineCustomWorkflows::Patches::Models::UserPatch' +else + User.prepend RedmineCustomWorkflows::Patches::Models::UserPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/version_patch.rb b/lib/redmine_custom_workflows/patches/models/version_patch.rb new file mode 100644 index 0000000..66577cc --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/version_patch.rb @@ -0,0 +1,76 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 VersionPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + end + + def before_save_custom_workflows + @version = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :version, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :version, self, :before_destroy + 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' +else + Version.prepend RedmineCustomWorkflows::Patches::Models::VersionPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb new file mode 100644 index 0000000..7d90b7b --- /dev/null +++ b/lib/redmine_custom_workflows/patches/models/wiki_content_patch.rb @@ -0,0 +1,77 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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 WikiContentPatch + + attr_accessor 'custom_workflow_messages' + + def custom_workflow_messages + @custom_workflow_messages ||= {} + 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 + end + + def before_save_custom_workflows + @content = self + @saved_attributes = attributes.dup + 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 + end + + def after_save_custom_workflows + CustomWorkflow.run_custom_workflows :wiki_content, self, :after_save + end + + def before_destroy_custom_workflows + CustomWorkflow.run_custom_workflows :wiki_content, self, :before_destroy + 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) + RedmineExtensions::PatchManager.register_model_patch 'WikiContent', + 'RedmineCustomWorkflows::Patches::Models::WikiContentPatch' +else + WikiContent.prepend RedmineCustomWorkflows::Patches::Models::WikiContentPatch +end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/wiki_page_patch.rb b/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb similarity index 52% rename from lib/redmine_custom_workflows/patches/wiki_page_patch.rb rename to lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb index 33da855..8259dcf 100644 --- a/lib/redmine_custom_workflows/patches/wiki_page_patch.rb +++ b/lib/redmine_custom_workflows/patches/models/wiki_page_patch.rb @@ -22,30 +22,39 @@ module RedmineCustomWorkflows module Patches - module WikiPagePatch + module Models + module WikiPagePatch - def self.prepended(base) - base.class_eval do - def self.attachments_callback(event, page, attachment) - page.instance_variable_set :@page, page - page.instance_variable_set :@attachment, attachment - CustomWorkflow.run_shared_code(page) if event.to_s.starts_with? 'before_' - CustomWorkflow.run_custom_workflows :wiki_page_attachments, page, event - end + attr_accessor 'custom_workflow_messages' - [: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) } + def custom_workflow_messages + @custom_workflow_messages ||= {} + end + + def self.prepended(base) + base.class_eval do + def self.attachments_callback(event, page, attachment) + page.instance_variable_set :@page, page + page.instance_variable_set :@attachment, attachment + CustomWorkflow.run_shared_code(page) if event.to_s.starts_with? 'before_' + 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) } + end end end - end + end end end end # Apply the patch if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'WikiPage', 'RedmineCustomWorkflows::Patches::WikiPagePatch' + RedmineExtensions::PatchManager.register_model_patch 'WikiPage', + 'RedmineCustomWorkflows::Patches::Models::WikiPagePatch' else - WikiPage.prepend RedmineCustomWorkflows::Patches::WikiPagePatch + WikiPage.prepend RedmineCustomWorkflows::Patches::Models::WikiPagePatch end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/project_patch.rb b/lib/redmine_custom_workflows/patches/project_patch.rb deleted file mode 100644 index 19df52d..0000000 --- a/lib/redmine_custom_workflows/patches/project_patch.rb +++ /dev/null @@ -1,83 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 ProjectPatch - - 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) } - - before_save :before_save_custom_workflows - after_save :after_save_custom_workflows - before_destroy :before_destroy_custom_workflows - after_destroy :after_destroy_custom_workflows - - def self.attachments_callback(event, project, attachment) - project.instance_variable_set(:@project, project) - project.instance_variable_set(:@attachment, attachment) - CustomWorkflow.run_shared_code(project) if event.to_s.starts_with? 'before_' - 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) } - end - end - end - - def before_save_custom_workflows - @project = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :project, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :project, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :project, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Project', 'RedmineCustomWorkflows::Patches::ProjectPatch' -else - Project.prepend RedmineCustomWorkflows::Patches::ProjectPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/time_entry_patch.rb b/lib/redmine_custom_workflows/patches/time_entry_patch.rb deleted file mode 100644 index cc8ee3e..0000000 --- a/lib/redmine_custom_workflows/patches/time_entry_patch.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 TimeEntryPatch - - 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 - end - - def before_save_custom_workflows - @time_entry = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :time_entry, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :time_entry, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :time_entry, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'TimeEntry', 'RedmineCustomWorkflows::Patches::TimeEntryPatch' -else - TimeEntry.prepend RedmineCustomWorkflows::Patches::TimeEntryPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/user_patch.rb b/lib/redmine_custom_workflows/patches/user_patch.rb deleted file mode 100644 index 69f0ff8..0000000 --- a/lib/redmine_custom_workflows/patches/user_patch.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 UserPatch - - 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 - end - - def before_save_custom_workflows - @user = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :user, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :user, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :user, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'User', 'RedmineCustomWorkflows::Patches::UserPatch' -else - User.prepend RedmineCustomWorkflows::Patches::UserPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/version_patch.rb b/lib/redmine_custom_workflows/patches/version_patch.rb deleted file mode 100644 index f2a6aab..0000000 --- a/lib/redmine_custom_workflows/patches/version_patch.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 VersionPatch - - 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 - end - - def before_save_custom_workflows - @version = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :version, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :version, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :version, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'Version', 'RedmineCustomWorkflows::Patches::VersionPatch' -else - Version.prepend RedmineCustomWorkflows::Patches::VersionPatch -end \ No newline at end of file diff --git a/lib/redmine_custom_workflows/patches/wiki_content_patch.rb b/lib/redmine_custom_workflows/patches/wiki_content_patch.rb deleted file mode 100644 index 8180fad..0000000 --- a/lib/redmine_custom_workflows/patches/wiki_content_patch.rb +++ /dev/null @@ -1,68 +0,0 @@ -# encoding: utf-8 -# frozen_string_literal: true -# -# Redmine plugin for Custom Workflows -# -# Copyright © 2015-19 Anton Argirov -# Copyright © 2019-22 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 WikiContentPatch - - 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 - end - - def before_save_custom_workflows - @content = self - @saved_attributes = attributes.dup - 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 - end - - def after_save_custom_workflows - CustomWorkflow.run_custom_workflows :wiki_content, self, :after_save - end - - def before_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :wiki_content, self, :before_destroy - end - - def after_destroy_custom_workflows - CustomWorkflow.run_custom_workflows :wiki_content, self, :after_destroy - end - - end - end -end - -# Apply the patch -if Redmine::Plugin.installed?(:easy_extensions) - RedmineExtensions::PatchManager.register_model_patch 'WikiContent', 'RedmineCustomWorkflows::Patches::WikiContentPatch' -else - WikiContent.prepend RedmineCustomWorkflows::Patches::WikiContentPatch -end \ No newline at end of file diff --git a/test/fixtures/custom_workflows.yml b/test/fixtures/custom_workflows.yml index 776155a..a804d22 100644 --- a/test/fixtures/custom_workflows.yml +++ b/test/fixtures/custom_workflows.yml @@ -1,8 +1,8 @@ --- custom_workflows_001: id: 1 - before_save: "Rails.logger.info '>>> before save'" - after_save: "Rails.logger.info '>>> after save'" + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' name: 'Issue CW test' description: 'Testing workflow' position: 1 @@ -17,5 +17,173 @@ custom_workflows_001: after_add: NULL before_remove: NULL after_remove: NULL - before_destroy: "Rails.logger.info '>>> before destroy'" - after_destroy : "Rails.logger.info '>>> after destroy'" + before_destroy: '' + after_destroy : '' + +custom_workflows_002: + id: 2 + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' + name: 'Version CW test' + description: 'Testing workflow' + position: 2 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'version' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: '' + after_destroy : '' + +custom_workflows_003: + id: 3 + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' + name: 'User CW test' + description: 'Testing workflow' + position: 3 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'user' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: '' + after_destroy : '' + +custom_workflows_004: + id: 4 + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' + name: 'Project CW test' + description: 'Testing workflow' + position: 4 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'project' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: '' + after_destroy : '' + +custom_workflows_005: + id: 5 + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' + name: 'Group CW test' + description: 'Testing workflow' + position: 5 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'group' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: '' + after_destroy : '' + +custom_workflows_006: + id: 6 + before_save: '' + after_save: '' + name: 'Attachment CW test' + description: 'Testing workflow' + position: 6 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'attachment' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_destroy : '' + +custom_workflows_007: + id: 7 + before_save: '' + after_save: '' + name: 'Issue relation CW test' + description: 'Testing workflow' + position: 7 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'issue_relation' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_destroy : '' + +custom_workflows_008: + id: 8 + before_save: '' + after_save: '' + name: 'Time entry CW test' + description: 'Testing workflow' + position: 8 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'time_entry' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_destroy : '' + +custom_workflows_009: + id: 9 + before_save: "self.custom_workflow_messages[:notice] = 'Custom workflow'" + after_save: '' + name: 'Wiki CW test' + description: 'Testing workflow' + position: 9 + is_for_all: 0 + author: 'karel.picman@kontron.com' + created_at: 2018-12-20 14:01:27 +02:00 + updated_at: 2018-12-20 14:01:27 +02:00 + active: 1 + observable: 'wiki_content' + shared_code: NULL + before_add: NULL + after_add: NULL + before_remove: NULL + after_remove: NULL + before_destroy: '' + after_destroy : '' \ No newline at end of file diff --git a/test/fixtures/custom_workflows_projects.yml b/test/fixtures/custom_workflows_projects.yml index cce4b67..a7f19c9 100644 --- a/test/fixtures/custom_workflows_projects.yml +++ b/test/fixtures/custom_workflows_projects.yml @@ -1,4 +1,20 @@ --- custom_workflows_projects_001: project_id: 1 - custom_workflow_id: 1 + custom_workflow_id: 1 # Issue + +custom_workflows_projects_002: + project_id: 1 + custom_workflow_id: 2 # Version + +custom_workflows_projects_003: + project_id: 1 + custom_workflow_id: 4 # Project + +custom_workflows_projects_004: + project_id: 1 + custom_workflow_id: 8 # Time entry + +custom_workflows_projects_005: + project_id: 1 + custom_workflow_id: 9 # Wiki content diff --git a/test/functional/attachments_controller_patch_test.rb b/test/functional/attachments_controller_patch_test.rb new file mode 100644 index 0000000..ee8edf1 --- /dev/null +++ b/test/functional/attachments_controller_patch_test.rb @@ -0,0 +1,42 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class AttachmentsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase + + fixtures :attachments, :enabled_modules, :custom_workflows, :custom_workflows_projects, + :roles, :members, :member_roles + + def setup + super + @attachment8 = Attachment.find 8 + @request.session[:user_id] = @jsmith.id + @controller = AttachmentsController.new + end + + def test_delete_with_cw + delete :destroy, params: { id: @attachment8 } + assert_response :redirect + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/custom_workflows_controller_test.rb b/test/functional/custom_workflows_controller_test.rb index 428ffa9..2e5c94d 100644 --- a/test/functional/custom_workflows_controller_test.rb +++ b/test/functional/custom_workflows_controller_test.rb @@ -24,23 +24,17 @@ require File.expand_path('../../test_helper', __FILE__) class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase - fixtures :users, :email_addresses, :custom_workflows, :custom_workflows_projects, :projects, :roles, - :members, :member_roles + fixtures :custom_workflows def setup + super @cw1 = CustomWorkflow.find 1 - @project1 = Project.find 1 - @admin = User.find 1 - @manager = User.find 2 User.current = nil @request.session[:user_id] = @admin.id end def test_truth assert_kind_of CustomWorkflow, @cw1 - assert_kind_of Project, @project1 - assert_kind_of User, @manager - assert_kind_of User, @admin end def test_index_admin @@ -49,7 +43,7 @@ class CustomWorkflowsControllerTest < RedmineCustomWorkflows::Test::TestCase end def test_index_non_admin - @request.session[:user_id] = @manager.id + @request.session[:user_id] = @jsmith.id get :index assert_response :forbidden end diff --git a/test/functional/groups_controller_patch_test.rb b/test/functional/groups_controller_patch_test.rb new file mode 100644 index 0000000..0196d04 --- /dev/null +++ b/test/functional/groups_controller_patch_test.rb @@ -0,0 +1,44 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class GroupControllerPatchTest < RedmineCustomWorkflows::Test::TestCase + include Rails.application.routes.url_helpers + + fixtures :custom_workflows, :custom_workflows_projects + + def setup + super + @group10 = Group.find 10 + @request.session[:user_id] = @admin.id + @controller = GroupsController.new + default_url_options[:host] = 'test.host' + end + + def test_update_with_cw + @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 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/issue_relations_controller_patch_test.rb b/test/functional/issue_relations_controller_patch_test.rb new file mode 100644 index 0000000..d7d38d7 --- /dev/null +++ b/test/functional/issue_relations_controller_patch_test.rb @@ -0,0 +1,43 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +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 + + def setup + super + @ir1 = IssueRelation.find 1 + @request.session[:user_id] = @jsmith.id + @controller = AttachmentsController.new + end + + def test_delete_with_cw + delete :destroy, params: { id: @ir1 } + assert_response :redirect + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/issues_controller_patch_test.rb b/test/functional/issues_controller_patch_test.rb new file mode 100644 index 0000000..40ce3a9 --- /dev/null +++ b/test/functional/issues_controller_patch_test.rb @@ -0,0 +1,43 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +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 + + def setup + super + @issue1 = Issue.find 1 + @request.session[:user_id] = @jsmith.id + @controller = IssuesController.new + end + + def test_update_with_cw + put :update, params: { id: @issue1.id, issue: { subject: 'Updated subject' } } + assert_redirected_to action: 'show', id: @issue1.id + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/projects_controller_patch_test.rb b/test/functional/projects_controller_patch_test.rb new file mode 100644 index 0000000..9da3251 --- /dev/null +++ b/test/functional/projects_controller_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +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 + + def setup + super + @request.session[:user_id] = @jsmith.id + @controller = ProjectsController.new + end + + def test_update_with_cw + post :update, params: { id: @project1.id, project: { name: 'Updated name' } } + assert_redirected_to settings_project_path(@project1) + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/timelog_controller_patch_test.rb b/test/functional/timelog_controller_patch_test.rb new file mode 100644 index 0000000..dac4caf --- /dev/null +++ b/test/functional/timelog_controller_patch_test.rb @@ -0,0 +1,43 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +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 + + def setup + super + @te1 = TimeEntry.find 1 + @request.session[:user_id] = @jsmith.id + @controller = TimelogController.new + end + + def test_delete_with_cw + delete :destroy, params: { id: @te1 } + assert_response :redirect + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/users_controller_patch_test.rb b/test/functional/users_controller_patch_test.rb new file mode 100644 index 0000000..2d9c4e6 --- /dev/null +++ b/test/functional/users_controller_patch_test.rb @@ -0,0 +1,40 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class UsersControllerPatchTest < RedmineCustomWorkflows::Test::TestCase + + fixtures :custom_workflows, :custom_workflows_projects + + def setup + super + @request.session[:user_id] = @admin.id + @controller = UsersController.new + end + + def test_update_with_cw + 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 + +end \ No newline at end of file diff --git a/test/functional/versions_controller_patch_test.rb b/test/functional/versions_controller_patch_test.rb new file mode 100644 index 0000000..5352291 --- /dev/null +++ b/test/functional/versions_controller_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class VersionsControllerPatchTest < RedmineCustomWorkflows::Test::TestCase + + fixtures :versions, :custom_workflows, :custom_workflows_projects, :roles, :members, :member_roles + + def setup + super + @version1 = Version.find 1 + @request.session[:user_id] = @jsmith.id + @controller = VersionsController.new + end + + def test_update_with_cw + put :update, params: { id: @version1.id, version: { name: 'Updated version' } } + assert_redirected_to settings_project_path(id: @project1, tab: 'versions') + assert_equal 'Custom workflow', @controller.flash[:notice] + end + +end \ No newline at end of file diff --git a/test/functional/wiki_controller_patch_test.rb b/test/functional/wiki_controller_patch_test.rb new file mode 100644 index 0000000..3af5f88 --- /dev/null +++ b/test/functional/wiki_controller_patch_test.rb @@ -0,0 +1,44 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +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 + + def setup + super + @wp1 = WikiPage.find 1 + @request.session[:user_id] = @jsmith.id + @controller = WikiController.new + end + + def test_update_with_cw + 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 diff --git a/lib/redmine_custom_workflows/test/test_case.rb b/test/test_case.rb similarity index 70% rename from lib/redmine_custom_workflows/test/test_case.rb rename to test/test_case.rb index f3f1b4a..58bf76d 100644 --- a/lib/redmine_custom_workflows/test/test_case.rb +++ b/test/test_case.rb @@ -22,32 +22,35 @@ module RedmineCustomWorkflows module Test + class TestCase < ActionController::TestCase + self.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, # and allowing us to suppliment redmine fixtures if we need to. def self.fixtures(*table_names) - dir = File.join( File.dirname(__FILE__), '../../../test/fixtures') + dir = File.join(File.dirname(__FILE__), 'fixtures') + redmine_table_names = [] table_names.each do |x| - ActiveRecord::FixtureSet.create_fixtures(dir, x) if File.exist?("#{dir}/#{x}.yml") - end - super(table_names) - end - - def setup - if ::Rails::VERSION::MAJOR >= 5 - if ::Rails::VERSION::MINOR >= 1 - @request = ActionController::TestRequest.create(self.class.controller_class) + if File.exist?(File.join(dir, "#{x}.yml")) + ActiveRecord::FixtureSet.create_fixtures(dir, x) else - @request = ActionController::TestRequest.create + redmine_table_names << x end - else - @request = ActionController::TestRequest.new end - @response = ActionController::TestResponse.new + super redmine_table_names if redmine_table_names.any? end - + + def setup + @jsmith = User.find_by(login: 'jsmith') + @admin = User.find_by(login: 'admin') + @project1 = Project.find 1 + User.current = nil + end + end + end end \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ccd763..218de2e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,4 +23,5 @@ # Load the normal Rails helper require File.expand_path('../../../../test/test_helper', __FILE__) -require_relative 'unit_test' \ No newline at end of file +require_relative 'unit_test' +require_relative 'test_case' \ No newline at end of file diff --git a/lib/redmine_custom_workflows/test/unit_test.rb b/test/unit/attachment_patch_test.rb similarity index 58% rename from lib/redmine_custom_workflows/test/unit_test.rb rename to test/unit/attachment_patch_test.rb index af87d8f..e12de3f 100644 --- a/lib/redmine_custom_workflows/test/unit_test.rb +++ b/test/unit/attachment_patch_test.rb @@ -20,20 +20,22 @@ # 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 Test - class UnitTest < ActiveSupport::TestCase +require File.expand_path('../../test_helper', __FILE__) - # 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__), '../../../test/fixtures') - table_names.each do |x| - ActiveRecord::FixtureSet.create_fixtures(dir, x) if File.exist?("#{dir}/#{x}.yml") - end - super(table_names) - end - end +class AttachmentPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :attachments + + def setup + @attachment1 = Attachment.find 1 end -end + + def test_truth + assert_kind_of Attachment, @attachment1 + end + + def test_custom_workflow_messages + @attachment1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @attachment1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/custom_workflow_test.rb b/test/unit/custom_workflow_test.rb index c5e3466..e36681f 100644 --- a/test/unit/custom_workflow_test.rb +++ b/test/unit/custom_workflow_test.rb @@ -37,5 +37,42 @@ class CustomWorkflowTest < RedmineCustomWorkflows::Test::UnitTest assert_equal @cw1.name, @cw1.to_s end + def test_import_from_xml + xml = %{ + + + 20 + Rails.logger.info '>>> Okay' + + cw 1 + Desc. + 4 + false + karel.picman@kontron.com + 2022-09-21T12:14:21Z + 2022-09-21T12:14:21Z + true + issue + + + + + + + + 2022-09-21T12:31:17Z + 2.0.6 devel + 3.0.2-p107 + 6.1.6.1 + + } + cw = CustomWorkflow.import_from_xml(xml) + assert cw + end + + def test_export_as_xml + xml = @cw1.export_as_xml + assert xml.include?("#{@cw1}") + end end \ No newline at end of file diff --git a/test/unit/group_patch_test.rb b/test/unit/group_patch_test.rb new file mode 100644 index 0000000..8456755 --- /dev/null +++ b/test/unit/group_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class GroupPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :users + + def setup + @group10 = Group.find 10 + end + + def test_truth + assert_kind_of Group, @group10 + end + + def test_custom_workflow_messages + @group10.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @group10.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/issue_patch_test.rb b/test/unit/issue_patch_test.rb new file mode 100644 index 0000000..853d786 --- /dev/null +++ b/test/unit/issue_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class IssuePatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :issues + + def setup + @issue1 = Issue.find 1 + end + + def test_truth + assert_kind_of Issue, @issue1 + end + + def test_custom_workflow_messages + @issue1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @issue1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/issue_relation_patch_test.rb b/test/unit/issue_relation_patch_test.rb new file mode 100644 index 0000000..9f04641 --- /dev/null +++ b/test/unit/issue_relation_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class IssueRelationPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :issue_relations + + def setup + @issue_relation1 = IssueRelation.find 1 + end + + def test_truth + assert_kind_of IssueRelation, @issue_relation1 + end + + def test_custom_workflow_messages + @issue_relation1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @issue_relation1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/project_patch_test.rb b/test/unit/project_patch_test.rb new file mode 100644 index 0000000..b32df40 --- /dev/null +++ b/test/unit/project_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class ProjectPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :projects + + def setup + @project1 = Project.find 1 + end + + def test_truth + assert_kind_of Project, @project1 + end + + def test_custom_workflow_messages + @project1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @project1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/time_entry_patch_test.rb b/test/unit/time_entry_patch_test.rb new file mode 100644 index 0000000..1609713 --- /dev/null +++ b/test/unit/time_entry_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class TimeEntryPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :time_entries + + def setup + @time_entry1 = TimeEntry.find 1 + end + + def test_truth + assert_kind_of TimeEntry, @time_entry1 + end + + def test_custom_workflow_messages + @time_entry1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @time_entry1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/user_patch_test.rb b/test/unit/user_patch_test.rb new file mode 100644 index 0000000..d4e32dd --- /dev/null +++ b/test/unit/user_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class UserPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :users + + def setup + @user1 = User.find 1 + end + + def test_truth + assert_kind_of User, @user1 + end + + def test_custom_workflow_messages + @user1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @user1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/version_patch_test.rb b/test/unit/version_patch_test.rb new file mode 100644 index 0000000..688a017 --- /dev/null +++ b/test/unit/version_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class VersionPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :versions + + def setup + @version1 = Version.find 1 + end + + def test_truth + assert_kind_of Version, @version1 + end + + def test_custom_workflow_messages + @version1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @version1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/wiki_content_patch_test.rb b/test/unit/wiki_content_patch_test.rb new file mode 100644 index 0000000..2d42850 --- /dev/null +++ b/test/unit/wiki_content_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class WikiContentPatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :wiki_contents + + def setup + @wiki_content1 = WikiContent.find 1 + end + + def test_truth + assert_kind_of WikiContent, @wiki_content1 + end + + def test_custom_workflow_messages + @wiki_content1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @wiki_content1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file diff --git a/test/unit/wiki_page_patch_test.rb b/test/unit/wiki_page_patch_test.rb new file mode 100644 index 0000000..3930381 --- /dev/null +++ b/test/unit/wiki_page_patch_test.rb @@ -0,0 +1,41 @@ +# encoding: utf-8 +# frozen_string_literal: true +# +# Redmine plugin for Custom Workflows +# +# Copyright © 2015-19 Anton Argirov +# Copyright © 2019-22 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. + +require File.expand_path('../../test_helper', __FILE__) + +class WikiPagePatchTest < RedmineCustomWorkflows::Test::UnitTest + fixtures :wiki_pages + + def setup + @wiki_page1 = WikiPage.find 1 + end + + def test_truth + assert_kind_of WikiPage, @wiki_page1 + end + + def test_custom_workflow_messages + @wiki_page1.custom_workflow_messages[:notice] = 'Okay' + assert_equal 'Okay', @wiki_page1.custom_workflow_messages[:notice] + end + +end \ No newline at end of file