From eeed26afe079b4b8cfcfa3b813bfa272fc96b33c Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 26 Aug 2026 20:49:39 -0400 Subject: [PATCH] Initial plugin structure with issue relation functionality --- LICENSE | 21 ++++++ README.md | 58 ++++++++++++++++ init.rb | 15 +++++ lib/redmine_recursive_relations.rb | 19 ++++++ .../issue_relations_controller_patch.rb | 67 +++++++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.rb create mode 100644 lib/redmine_recursive_relations.rb create mode 100644 lib/redmine_recursive_relations/patches/issue_relations_controller_patch.rb diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6ca2371 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2026 Rick Barrette + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3121d4 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# Recursive Issue Relations + +## Overview +This plugin extends the default issue relation functionality in Redmine. When adding multiple issues as a relation via a comma-separated string (e.g., `12, 13, 15`), Redmine natively links the base issue to each of these targets. This plugin automatically extends this behavior by cross-relating all the newly provided issues with each other. + +## Features +- Automatically creates cross-relations for comma-separated issue IDs. +- Gracefully handles validation failures (e.g., missing issues, cross-project restrictions). +- Lightweight, using standard Rails `ActiveSupport::Concern` to patch the controller without overriding core files. + +--- + +## Compatibility + +| Plugin Version | Redmine Version | +| :--- | :--- | +| **2026.8.0+** | Redmine 5.x | + +--- + +## Installation + +### 1. Clone the Plugin + +Install the plugin into your Redmine `plugins` directory. + +```bash +cd /path/to/redmine/plugins +git clone https://github.com/rickbarrette/redmine_recursive_relations.git +cd redmine_recursive_relations + +# Optional but recommended: Checkout a specific tagged release for stability +git checkout +``` + +### 2. Restart Redmine + +Because this plugin patches the core controller, no database migrations are required. Simply restart your Redmine application server (e.g., Puma, Passenger, or Unicorn) so the plugin and hooks are loaded. + +--- + +## Usage + +Once installed and the server is restarted, there is no configuration needed. + +--- + +## License + +> The MIT License (MIT) +> +> Copyright (c) 2026 Rick Barrette +> +> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..f5c06cd --- /dev/null +++ b/init.rb @@ -0,0 +1,15 @@ +require 'redmine' + +Redmine::Plugin.register :redmine_recursive_relations do + name 'Recursive Issue Relations' + author 'Rick Barrette' + description 'Automatically cross-relates all issues provided in a single relation string.' + version '2026.8.0' + url 'https://github.com/rickbarrette/redmine_recursive_relations' + author_url 'https://github.com/rickbarrette' + + # Require the core scheduler runner logic + requires_redmine version_or_higher: '5.0.0' +end + +RedmineRecursiveRelations.setup \ No newline at end of file diff --git a/lib/redmine_recursive_relations.rb b/lib/redmine_recursive_relations.rb new file mode 100644 index 0000000..b164564 --- /dev/null +++ b/lib/redmine_recursive_relations.rb @@ -0,0 +1,19 @@ +#The MIT License (MIT) +# +#Copyright (c) 2026 rick barrette +# +#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +module RedmineRecursiveRelations + + def self.setup + Rails.logger.info "[RedmineRecursiveRelations] setup" + unless IssueRelationsController.included_modules.include?(RedmineRecursiveRelations::Patches::IssueRelationsControllerPatch) + IssueRelationsController.include(RedmineRecursiveRelations::Patches::IssueRelationsControllerPatch) + end + end +end \ No newline at end of file diff --git a/lib/redmine_recursive_relations/patches/issue_relations_controller_patch.rb b/lib/redmine_recursive_relations/patches/issue_relations_controller_patch.rb new file mode 100644 index 0000000..10588a2 --- /dev/null +++ b/lib/redmine_recursive_relations/patches/issue_relations_controller_patch.rb @@ -0,0 +1,67 @@ +module RedmineRecursiveRelations + module Patches + module IssueRelationsControllerPatch + extend ActiveSupport::Concern + + included do + # 1. Capture the form data before Redmine modifies it in the core 'create' method + before_action :store_original_relation_params, only: [:create] + + # 2. Run the cross-linking after Redmine has linked the base issue to the targets + after_action :create_cross_relations, only: [:create] + end + + private + + def log(msg) + Rails.logger.info "[IssueRelationsControllerPatch] #{msg}" + end + + def store_original_relation_params + log "store_original_relation_params" + return unless params[:relation] + + # relation_issues_to_id is a core method that parses strings like "12, 13, 15" into an array + @original_target_ids = relation_issues_to_id.dup + + # Save the params deeply so they aren't overwritten by the core looping mechanism + @original_relation_params = params[:relation].to_unsafe_hash.deep_dup + end + + def create_cross_relations + log "create_cross_relations" + # Ensure we have data and at least 2 issues to cross-relate + return if @original_target_ids.blank? || @original_relation_params.blank? + return if @original_target_ids.size < 2 + + successful_target_ids = @original_target_ids.map(&:to_i) + + # Remove any issues that failed standard validation on the base issue + # (e.g., they don't exist, or cross-project linking is disabled) + if @unsaved_relations.present? + failed_ids = @unsaved_relations.map(&:issue_to_id) + successful_target_ids -= failed_ids + end + + # Fetch the valid issues for cross-linking + valid_issues = Issue.visible(User.current).where(id: successful_target_ids).to_a + + # Generate all unique pairs from the list (e.g., 12->13, 12->15, 13->15) + valid_issues.combination(2).each do |issue_from, issue_to| + relation = IssueRelation.new + relation.issue_from = issue_from + relation.safe_attributes = @original_relation_params.merge('issue_to_id' => issue_to.id) + relation.init_journals(User.current) + + begin + # Standard saves trigger core validations. If an issue creates a circular + # dependency (e.g., with 'blocks'), Redmine will safely reject it here silently. + relation.save + rescue ActiveRecord::RecordNotUnique + # Suppress errors if a duplicate relation somehow already exists in the database + end + end + end + end + end +end \ No newline at end of file