Skip to content

Commit

Permalink
Enhance compatibility with Redmine 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Sep 28, 2023
1 parent 8b4dc95 commit 0996f4f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/4_2_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ jobs:
repository: jbbarth/redmine_base_rspec
path: redmine/plugins/redmine_base_rspec

# Stay on rails-dom-testing gem version "2.0.3", because "2.1.1" is not fully compatible with Redmine 4.2.10 - TODO Remove this when Redmine 4.2.11 is released
- name: Prepare Redmine source
working-directory: redmine
run: |
sed -i -e 's/.*rails-dom-testing.*/ gem "rails-dom-testing", "~> 2.0.3"/' Gemfile
sed -i '/rubocop/d' Gemfile
rm -f .rubocop*
cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/4_1_7.yml → .github/workflows/5_0_5.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Tests 4.1.7
name: Tests 5.0.5

env:
PLUGIN_NAME: redmine_drafts
REDMINE_VERSION: 4.1.7
REDMINE_VERSION: 5.0.5
RAILS_ENV: test

on:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
ruby: ['2.6']
ruby: ['2.7']
db: ['postgres']
fail-fast: false

Expand Down Expand Up @@ -86,9 +86,11 @@ jobs:
repository: jbbarth/redmine_base_rspec
path: redmine/plugins/redmine_base_rspec

# Stay on rails-dom-testing gem version "2.0.3", because "2.1.1" is not fully compatible with Redmine 5.0.5 - TODO Remove this when Redmine 5.0.6 is released
- name: Prepare Redmine source
working-directory: redmine
run: |
sed -i -e 's/.*rails-dom-testing.*/ gem "rails-dom-testing", "~> 2.0.3"/' Gemfile
sed -i '/rubocop/d' Gemfile
rm -f .rubocop*
cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Then :

## Test status

|Plugin branch| Redmine Version | Test Status |
|-------------|-------------------|------------------|
|master | 4.2.10 | [![4.2.10][1]][5]|
|master | 4.1.7 | [![4.1.7][2]][5] |
|master | master | [![master][4]][5]|
|Plugin branch| Redmine Version | Test Status |
|-------------|-----------------|-------------------|
|master | 4.2.10 | [![4.2.10][1]][5] |
|master | 5.0.5 | [![5.0.5][2]][5] |
|master | master | [![master][4]][5] |

[1]: https://github.com/jbbarth/redmine_drafts/actions/workflows/4_2_10.yml/badge.svg
[2]: https://github.com/jbbarth/redmine_drafts/actions/workflows/4_1_7.yml/badge.svg
Expand Down
8 changes: 1 addition & 7 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
require 'redmine'

require 'redmine_drafts/hooks'

ActiveSupport::Reloader.to_prepare do
require_dependency 'redmine_drafts/issue_patch'
require_dependency 'redmine_drafts/issues_controller_patch'
end
require_relative 'lib/redmine_drafts/hooks'

Redmine::Plugin.register :redmine_drafts do
name 'Redmine Drafts plugin'
Expand Down
7 changes: 7 additions & 0 deletions lib/redmine_drafts/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ def view_layouts_base_html_head(context)
javascript_include_tag('jquery.observe-form.js', :plugin => 'redmine_drafts')
end

class ModelHook < Redmine::Hook::Listener
def after_plugins_loaded(_context = {})
require_relative 'issue_patch'
require_relative 'issues_controller_patch'
end
end

end
end
23 changes: 14 additions & 9 deletions lib/redmine_drafts/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
require_dependency 'issue'

class Issue < ActiveRecord::Base

has_many :drafts, :as => :element

after_create :clean_drafts_after_create
after_update :clean_drafts_after_update

module RedmineDrafts::IssuePatch
def clean_drafts_after_create
draft = Draft.find_for_issue(:element_id => 0, :user_id => User.current.id)
draft.destroy if draft
end

def clean_drafts_after_update
self.drafts.select{|d| d.user_id == User.current.id}.each(&:destroy)
self.drafts.select { |d| d.user_id == User.current.id }.each(&:destroy)
end
end

class Issue < ActiveRecord::Base

include RedmineDrafts::IssuePatch

has_many :drafts, :as => :element

after_create :clean_drafts_after_create
after_update :clean_drafts_after_update

end
18 changes: 11 additions & 7 deletions lib/redmine_drafts/issues_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
require_dependency 'issues_controller'

class IssuesController
prepend_before_action :set_draft

private
module RedmineDrafts::IssuesControllerPatch
def set_draft
if params[:draft_id]
if params[:draft_id].present?
draft = Draft.find(params[:draft_id]) rescue nil
if draft
if draft.present?
params.merge!(draft.content.permit!)
end
end
true
end
end

class IssuesController

include RedmineDrafts::IssuesControllerPatch

prepend_before_action :set_draft, :only => [:new, :edit]

end

0 comments on commit 0996f4f

Please sign in to comment.