プロジェクト

全般

プロフィール

Vote #76014

完了

link_to in Redmine::Hook::ViewListener omits url root

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
80
issue_org_id:
19024
author_id:
107146
assigned_to_id:
1
comments:
6
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Linking to a controller action omits the configured url root (@RAILS_RELATIVE_URL_ROOT@ environment variable).

For example, put the following code in a plugin & set @RAILS_RELATIVE_URL_ROOT=/redmine@:

link_to "Test", { :controller => 'my', :action => 'plugin' }
# => Test
# Should be: href="/redmine/my/plugin"

There are quite a few others that seem to have the same problem:
https://github.com/peelman/my_projects/issues/5
https://stackoverflow.com/questions/25315103/link-to-omits-redmine-root

I am not sure if this is only reproducible under specific environments (at least the my_projects author doesn't seem to have this problem); I tried both the Bitnami Installer on Windows and the @sameersbn/redmine@ Docker container. You should get the same results with the following steps:

Download https://github.com/peelman/my_projects

On Windows: Install Redmine using Bitnami and put the plugin in the plugins folder

On Linux: Install Docker & fig, put "this":https://gist.github.com/jgillich/97c88a99092c37e5d327 in the addon folder and type @fig up@.

Open Redmine, create a project and go to the @Home@ page.

Observe that all links generated by the plugin don't include the relative URL.


journals

--------------------------------------------------------------------------------
Google "Redmine::Hook::ViewListener suburi".
http://goo.gl/A95cJa

On Windows bitnami.
<pre>
C:\Bitnami\redmine-2.6.0-1\apps\redmine\htdocs>bundle exec thin
-e production -a localhost -p 3000 --prefix /redmine start
</pre>

<pre><code class="diff">
diff --git a/lib/my_projects/view_hook_listener.rb b/lib/my_projects/view_hook_listener.rb
index fc404d8..f099f08 100644
--- a/lib/my_projects/view_hook_listener.rb
+++ b/lib/my_projects/view_hook_listener.rb
@@ -42,10 +42,21 @@ class MyProjects < Redmine::Hook::ViewListener

return html
end
-
+
+ def suburi(url)
+ baseurl = Redmine::Utils.relative_url_root
+ if not url.match(/^#{baseurl}/)
+ url = baseurl + url
+ end
+ return url
+ end
+
def link_to_project(project)
html = '<li>'
- html += "#{link_to h(project.name), { :controller => 'projects', :action => 'show', :id => project } }"
+ # html += "#{link_to h(project.name), { :controller => 'projects', :action => 'show', :id => project } }"
+ url = suburi(url_for({ :controller => 'projects', :action => 'show', :id => project}))
+ html += "#{link_to(h(project.name), url)}"
+
html += " | #{link_to l(:label_issue_plural), { :controller => 'issues', :action=>'index', :project_id => project } } "
html += " | #{link_to l(:label_wiki), { :controller => 'wiki', :action=>'show', :project_id => project } } "
html += '</li>'

</code></pre>
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Are you saying that this has to be fixed in the plugins and not in Redmine? That seems wrong to me, the url root is something that Redmine supports by default, you can't possibly expect every single plugin to handle that case. Also, the core code uses just @link_to@, I guess there is already some logic in place to prepend the url root.
--------------------------------------------------------------------------------
This is fixed in r13960. Unfortunately, this fix works with Rails 4 only and won't be backported in 2.6 branch.
--------------------------------------------------------------------------------
Thanks! I guess I'll just use the workaround until then.
--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリPlugin API_20 にセット
  • 対象バージョン3.0.0_80 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0