From 62391e5cf75554a959b0ca3c6ca0a5886af8c1c2 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 10 Aug 2016 11:17:37 +0200 Subject: [PATCH 1/4] Rails 4 doesn't allow match to be used like that anymore --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 2eaab6c..bded4a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,6 @@ end else RedmineApp::Application.routes.draw do - match 'projects/:id/wiki/decode', :to => 'redmine_wikicipher', :action => 'decode' + get 'projects/:id/wiki/decode', :to => 'redmine_wikicipher', :action => 'decode' end end From eb3c3481dc520cce3c8ae22597397529bb156352 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 10 Aug 2016 11:20:40 +0200 Subject: [PATCH 2/4] Fix generation of cipher/decipher URLs This solves the issue where the cipher/decipher button cannot be used if Redmine is not deployed on the root URL (see also keeps/redmine_wikicipher#23). In case of Redmine 2.x, Redmine::Utils.relative_url_root needs to be prefixed, as it is not a port of the *_path URLs yet. --- lib/redmine_wikicipher/hooks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/redmine_wikicipher/hooks.rb b/lib/redmine_wikicipher/hooks.rb index 8ca1a48..0588561 100644 --- a/lib/redmine_wikicipher/hooks.rb +++ b/lib/redmine_wikicipher/hooks.rb @@ -33,10 +33,10 @@ def view_wiki_contextual(context={ }) current = current.title if context[:toggle]=='1' - link = "<%= t 'redmine_wikicipher.decode' %>" + link = "<%= t 'redmine_wikicipher.decode' %>" link = link.force_encoding("UTF-8") else - link = "<%= t 'redmine_wikicipher.encode' %>" + link = "<%= t 'redmine_wikicipher.encode' %>" link = link.force_encoding("UTF-8") end hideLink=1 From aed828a1de0da1e83e61a6383c43d398e55c4669 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 10 Aug 2016 11:24:55 +0200 Subject: [PATCH 3/4] Fix strings not being converted into an array properly --- lib/wiki_controller_patch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wiki_controller_patch.rb b/lib/wiki_controller_patch.rb index 21f2548..5939d75 100644 --- a/lib/wiki_controller_patch.rb +++ b/lib/wiki_controller_patch.rb @@ -42,7 +42,7 @@ def encrypt(originalText) def decrypt(encodedContent) e = OpenSSL::Cipher::Cipher.new 'DES-EDE3-CBC' e.decrypt $key - s = encodedContent.to_a.pack("H*").unpack("C*").pack("c*") + s = Array(encodedContent).pack("H*").unpack("C*").pack("c*") s = e.update s decoded = s << e.final return decoded From f85991d68f5c1fb51e8984b00af3b411c234027d Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 10 Aug 2016 11:25:24 +0200 Subject: [PATCH 4/4] Fix PDF generation trying to create a page that already exists When using clone, the page is really created again, which leads to database conflicts, as the page already exists. --- lib/wiki_controller_patch.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/wiki_controller_patch.rb b/lib/wiki_controller_patch.rb index 5939d75..cb2d9ae 100644 --- a/lib/wiki_controller_patch.rb +++ b/lib/wiki_controller_patch.rb @@ -171,11 +171,11 @@ def show_with_decryption if User.current.allowed_to?(:export_wiki_pages, @project) if params[:format] == 'pdf' params[:decode]='1' - @content.text = decodeContent(@content.text,params,0,1); - - clone = @page.clone - clone.content = @content - send_data(wiki_page_to_pdf(clone, @project), :type => 'application/pdf', :filename => "#{clone.title}.pdf") + @content.text = decodeContent(@content.text,params,0,1); + @page = @page.dup + @page.content = @content + #send_data(wiki_page_to_pdf(clone, @project), :type => 'application/pdf', :filename => "#{clone.title}.pdf") + send_file_headers! :type => 'application/pdf', :filename => "#{@page.title}.pdf" return elsif params[:format] == 'html' params[:decode]='1'