Skip to content

Commit f6470cb

Browse files
committed
port to redmine 6 by using after_plugins_loaded and prepend
1 parent 8559402 commit f6470cb

File tree

4 files changed

+44
-87
lines changed

4 files changed

+44
-87
lines changed

init.rb

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
1-
require 'redmine'
2-
require 'redmine_redirect_after_create/issues_controller_patch'
3-
require 'redmine_redirect_after_create/routes_helper_patch'
1+
module RedmineRedirectAfterCreate
2+
module IssuesControllerPatch
3+
def self.prepended(base)
4+
def redirect_after_create
5+
redirect_url = params[:redirect_url].to_s
6+
if redirect_url.present? && valid_back_url?(redirect_url)
7+
redirect_to redirect_url
8+
else
9+
super
10+
end
11+
end
12+
end
13+
end
14+
15+
module RoutesHelperPatch
16+
def self.prepended(base)
17+
def _project_issues_path(project, *args)
18+
if params[:redirect_url]
19+
options = args.extract_options!
20+
options = options.reverse_merge redirect_url: params[:redirect_url]
21+
args << options
22+
end
23+
super project, *args
24+
end
25+
end
26+
end
27+
end
28+
29+
class AfterPluginsLoadedHook < Redmine::Hook::Listener
30+
def after_plugins_loaded(_context = {})
31+
IssuesController.prepend RedmineRedirectAfterCreate::IssuesControllerPatch
32+
RoutesHelper.prepend RedmineRedirectAfterCreate::RoutesHelperPatch
33+
end
34+
end
435

536
Redmine::Plugin.register :redmine_redirect_after_create do
6-
name 'Redmine redirect after create plugin'
7-
author 'Intera GmbH'
8-
description 'This plugin redirects the user to a custom URL after ticket creation based on a URL parameter.'
9-
version '0.0.1'
10-
url 'https://github.com/Intera/redmine_redirect_after_create'
37+
name "Redmine Redirect After Create Plugin"
38+
author "Intera GmbH"
39+
description "This plugin redirects the user to a custom URL after ticket creation based on a URL parameter."
40+
version "0.1.0"
41+
url "https://github.com/Intera/redmine_redirect_after_create"
42+
requires_redmine :version_or_higher => "6.0.0"
1143
end

lib/redmine_redirect_after_create/issues_controller_patch.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

lib/redmine_redirect_after_create/routes_helper_patch.rb

Lines changed: 0 additions & 38 deletions
This file was deleted.

README.rdoc renamed to readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
= redmine_redirect_after_create
1+
# redmine_redirect_after_create
22

33
This Redmine plugin allows to specify a custom redirect URL when a new issue is created.
44

5-
You can use it by appending the redirect_url parameter the the URL for creating a new issue.
5+
You can use it by appending the redirect_url parameter the the URL for creating a new issue.
66

77
For example:
88

9-
http://my-redmine-url.tld/projects/myprojects/issues/new?redirect_url=%2F
9+
http://my-redmine-url.tld/projects/myprojects/issues/new?redirect_url=/projects
1010

11-
This URL will redirect the user to the homepage after the ticket was created.
11+
This URL will redirect the user to the projects overview after the ticket was created.

0 commit comments

Comments
 (0)