Skip to content

Commit

Permalink
Merge pull request #411 from reshetov/feature/implemented-compatibili…
Browse files Browse the repository at this point in the history
…ty-with-redmine5

Implemented compatibility with Redmine 5+
  • Loading branch information
alexbevi authored Oct 5, 2024
2 parents be8441a + 68552f1 commit 4445eab
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 302 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gem 'redmine_crm'
gem 'redmineup'
gem 'ya2yaml'
gem 'awesome_nested_set'
4 changes: 1 addition & 3 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class ArticlesController < ApplicationController
unloadable

helper :attachments
include AttachmentsHelper
helper :knowledgebase
Expand Down Expand Up @@ -131,7 +129,7 @@ def edit
@categories=@project.categories.all

# @page is used when using redmine_wysiwyg_editor plugin to show added attachments in menu
@page = @article
@page = @article
# don't keep previous comment
@article.version_comments = nil
@article.version = params[:version]
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class CategoriesController < ApplicationController
unloadable

menu_item :articles
helper :knowledgebase
include KnowledgebaseHelper
Expand All @@ -9,7 +7,7 @@ class CategoriesController < ApplicationController

before_action :find_project_by_project_id, :authorize
before_action :get_category, :only => [:show, :edit, :update, :destroy, :index]
accept_rss_auth :show
Rails.version > '5.0' ? accept_atom_auth(:show) : accept_rss_auth(:show)

rescue_from ActiveRecord::RecordNotFound, :with => :force_404

Expand Down
3 changes: 1 addition & 2 deletions app/helpers/knowledgebase_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module KnowledgebaseHelper
include Redmine::Export::PDF
include KnowledgebaseSettingsHelper
include ActionView::Helpers::NumberHelper
include RedmineCrm::TagsHelper
include Redmineup::TagsHelper

def format_article_summary(article, format, options = {})
output = case format
Expand Down Expand Up @@ -189,4 +189,3 @@ def get_article_thumbnail_url_absolute( article )


end

12 changes: 4 additions & 8 deletions app/models/kb_article.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
require 'acts_as_viewed'
require 'acts_as_rated'
require 'acts_as_versioned'
require 'diff'
require Rails.version > '5.0' ? 'redmine/string_array_diff/diff' : 'diff'

class KbArticle < ActiveRecord::Base
unloadable
class KbArticle < ApplicationRecord
include Redmine::SafeAttributes

self.locking_column = 'version'
Expand All @@ -18,9 +14,9 @@ class KbArticle < ActiveRecord::Base
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
belongs_to :updater, :class_name => 'User', :foreign_key => 'updater_id'

rcrm_acts_as_viewed
up_acts_as_viewed
acts_as_rated :no_rater => true
rcrm_acts_as_taggable
up_acts_as_taggable
acts_as_attachable
acts_as_watchable

Expand Down
3 changes: 1 addition & 2 deletions app/models/kb_category.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class KbCategory < ActiveRecord::Base
unloadable
class KbCategory < ApplicationRecord
include Redmine::SafeAttributes

self.table_name = "kb_categories"
Expand Down
3 changes: 1 addition & 2 deletions app/models/kb_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class KbMailer < Mailer

add_template_helper(KnowledgebaseHelper)
helper KnowledgebaseHelper

def article_create(_user = User.current, article)
redmine_headers 'Project' => article.project.identifier
Expand Down
3 changes: 1 addition & 2 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@


<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => { :key => User.current.rss_key } %>
<%= f.link_to 'Atom', :url => { :key => User.current.atom_key } %>
<% end %>
<% end %>

3 changes: 1 addition & 2 deletions app/views/categories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => { :key => User.current.rss_key } %>
<%= f.link_to 'Atom', :url => { :key => User.current.atom_key } %>
<% end %>
<% end %>

11 changes: 6 additions & 5 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require 'redmine'
require 'macros'
require 'concerns/knowledgebase_project_extension'
require 'helpers/knowledgebase_link_helper'
require 'helpers/knowledgebase_settings_helper'

if (Rails.configuration.respond_to?(:autoloader) && Rails.configuration.autoloader == :zeitwerk) || Rails.version > '7.0'
Rails.autoloaders.each { |loader| loader.ignore(File.dirname(__FILE__) + '/lib') }
end
require File.dirname(__FILE__) + '/lib/redmine_knowledgebase'

Project.send :include, KnowledgebaseProjectExtension
SettingsHelper.send :include, KnowledgebaseSettingsHelper
ApplicationHelper.send :include, RedmineCrm::TagsHelper
ApplicationHelper.send :include, Redmineup::TagsHelper

Rails.configuration.to_prepare do
Redmine::Activity.register :kb_articles
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class << self
end

class_eval do
has_many :versions, version_association_options do
versions_block = Proc.new do ||
# finds earliest version of this record
def earliest
@earliest ||= order('version').first
Expand All @@ -224,6 +224,13 @@ def latest
@latest ||= order('version desc').first
end
end

if RUBY_VERSION >= '3.0'
has_many :versions, **version_association_options, &versions_block
else
has_many :versions, version_association_options, &versions_block
end

before_save :set_new_version
after_create :save_version_on_create
after_update :save_version
Expand Down
Loading

0 comments on commit 4445eab

Please sign in to comment.