Skip to content

Commit

Permalink
Added support to Redmine v2.2.x.
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
sleroux-keep committed Jan 29, 2013
1 parent ad13796 commit faa946a
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ The Redmine Wikicipher plugin allows to encrypt sections of the Wiki

== Compatibility

This plugin works (has been tested) with redmine v1.4

This plugin works (has been tested) with redmine v1.4.x and redmine v2.2.x.
== Installation

* Place the plugin into +/path/to/redmine/vendor/plugins+ . The name of the plugin's directory/folder should be *redmine_wikicipher*.
* Change directory to +/path/to/redmine/+ .
* Update the "database_cipher_key" configuration located in +/path/to/redmine/config/configuration.yml file with some random key (this key will be used to cipher/decipher the wiki content)
* For redmine v2.2.x, edit the application.rb file (+/path/to/redmine/config/application.rb+), adding ":text" to the filter parameters (config.filter_parameters += [:password, :text]).
* Restart redmine.

== How to change the cipher key
Expand Down
40 changes: 28 additions & 12 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/env ruby
# encoding: utf-8

require 'redmine'
require 'dispatcher'
require 'dispatcher' unless Rails::VERSION::MAJOR >= 3
require 'wiki_controller_patch'
require 'wiki_page_patch'
require_dependency 'redmine_wikicipher/hooks'
Expand All @@ -13,17 +16,30 @@
description 'This plugin adds the ability to encrypt section of text'
version '0.0.2'
url 'https://github.com/keeps/redmine_wikicipher'
if Redmine::VERSION::MAJOR > 1
raise Redmine::PluginRequirementError.new("redmine_wikicipher plugin requires Redmine 1.x but current is #{Redmine::VERSION}")
end
end

ApplicationController.class_eval do
filter_parameter_logging :password, :text
end
Dispatcher.to_prepare do
require_dependency 'wiki_controller'
require_dependency 'wiki_page'
WikiController.send(:include, WikiControllerPatch)
WikiPage.send(:include, WikiPagePatch)


if Rails::VERSION::MAJOR >= 3
ActionDispatch::Callbacks.to_prepare do
require_dependency 'wiki_controller'
require_dependency 'wiki_page'
WikiController.send(:include, WikiControllerPatch)
WikiPage.send(:include, WikiPagePatch)
end
else
ApplicationController.class_eval do
filter_parameter_logging :password, :text
end
Dispatcher.to_prepare do
require_dependency 'wiki_controller'
require_dependency 'wiki_page'
WikiController.send(:include, WikiControllerPatch)
WikiPage.send(:include, WikiPagePatch)
end

end




105 changes: 103 additions & 2 deletions lib/wiki_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,111 @@ def edit_with_decription_tagged
end

def update_with_encryption

if Redmine::VERSION::MAJOR > 1
logger.warn("redmine 2.X")









return render_403 unless editable?
was_new_page = @page.new_record?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]

@page.content.versions.each do |v|
if(v.text.strip.match(/^\{\{history\_coded\_start\}\}/) && v.text.strip.match(/\{\{history\_coded\_stop\}\}$/))
#v.save()
else
v.comments = "["+v.updated_on.to_s+"] "+v.comments
v.text = encodeOldVersion(v.text.strip,params,v.updated_on)
v.save()
end
end



@content = @page.content
content_params = params[:content]
if content_params.nil? && params[:wiki_page].is_a?(Hash)
content_params = params[:wiki_page].slice(:text, :comments, :version)
end
content_params ||= {}

@content.comments = content_params[:comments]
@text = content_params[:text]
if params[:section].present? && Redmine::WikiFormatting.supports_section_edit?
@section = params[:section].to_i
@section_hash = params[:section_hash]
@content.text = Redmine::WikiFormatting.formatter.new(@content.text).update_section(params[:section].to_i, @text, @section_hash)
else
@content.version = content_params[:version] if content_params[:version]
@content.text = @text
end
@content.author = User.current

@content.text = encodeContent(@content.text,params)

if @page.save_with_content
attachments = Attachment.attach_files(@page, params[:attachments])
render_attachment_warning_if_needed(@page)
call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})

respond_to do |format|
format.html { redirect_to :action => 'show', :project_id => @project, :id => @page.title }
format.api {
if was_new_page
render :action => 'show', :status => :created, :location => url_for(:controller => 'wiki', :action => 'show', :project_id => @project, :id => @page.title)
else
render_api_ok
end
}
end
else
respond_to do |format|
format.html { render :action => 'edit' }
format.api { render_validation_errors(@content) }
end
end

























else



return render_403 unless editable?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
@page.safe_attributes = params[:wiki_page]

@page.content.versions.each do |v|
@page.content.versions.each do |v|
if(v.text.strip.match(/^\{\{history\_coded\_start\}\}/) && v.text.strip.match(/\{\{history\_coded\_stop\}\}$/))
#v.save()
else
Expand All @@ -265,7 +365,6 @@ def update_with_encryption
end
end


@content = @page.content_for_version(params[:version])
@content.text = initial_page_content(@page) if @content.text.blank?
# don't keep previous comment
Expand Down Expand Up @@ -302,6 +401,8 @@ def update_with_encryption
render :action => 'edit'
end


end
rescue ActiveRecord::StaleObjectError, Redmine::WikiFormatting::StaleSectionError
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
Expand Down

0 comments on commit faa946a

Please sign in to comment.