Skip to content

Instantly share code, notes, and snippets.

@alexbevi
Created September 23, 2012 21:15
Show Gist options
  • Save alexbevi/3773063 to your computer and use it in GitHub Desktop.
Save alexbevi/3773063 to your computer and use it in GitHub Desktop.
Redmine + Knowledgebase Patches for Global Search (proposed)
diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb
index 6bae37b..8057da6 100644
--- a/app/controllers/articles_controller.rb
+++ b/app/controllers/articles_controller.rb
@@ -83,7 +83,7 @@ class ArticlesController < KnowledgebaseController
end
def tagged
- @tag = params[:id]
+ @tag = params[:article_id] || params[:id]
@list = KbArticle.tagged_with(@tag)
end
@@ -115,6 +115,7 @@ private
end
def get_article
+ params[:id] = params[:article_id] || params[:id]
@article = KbArticle.where(:id => params[:id])
@article = @article.first if @article.is_a?(ActiveRecord::Relation)
end
diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index eaa99e1..c9bcd0e 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -3,6 +3,7 @@ class CategoriesController < KnowledgebaseController
#Authorize against global permissions defined in init.rb
before_filter :authorize_global
+ default_search_scope :KbCategory
def show
@category = KbCategory.find(params[:id])
diff --git a/app/controllers/knowledgebase_controller.rb b/app/controllers/knowledgebase_controller.rb
index 3f3af69..3706cfa 100644
--- a/app/controllers/knowledgebase_controller.rb
+++ b/app/controllers/knowledgebase_controller.rb
@@ -1,5 +1,6 @@
class KnowledgebaseController < ApplicationController
unloadable
+ #default_search_scope :KbArticle
#Authorize against global permissions defined in init.rb
before_filter :authorize_global, :unless => :allow_anonymous_access?
diff --git a/app/models/kb_article.rb b/app/models/kb_article.rb
index 8e03c8a..02d3476 100644
--- a/app/models/kb_article.rb
+++ b/app/models/kb_article.rb
@@ -1,9 +1,12 @@
class KbArticle < ActiveRecord::Base
unloadable
+ # this is required for articles to be visible
+ # modify to your needs
+ scope :visible, lambda {{ :include => :category }}
self.table_name = "kb_articles"
- validates_presence_of :title
+ validates_presence_of :title, :category
validates_presence_of :category_id
belongs_to :project # XXX association added to allow searching to work
@@ -15,11 +18,11 @@ class KbArticle < ActiveRecord::Base
acts_as_taggable
acts_as_attachable
- acts_as_searchable :columns => [ "kb_articles.title", "kb_articles.content"],
+ acts_as_searchable :columns => [ "kb_articles.title", "kb_articles.content" ],
:include => [ :project ],
:order_column => "kb_articles.id",
- :date_column => "kb_articles.created_at",
- :permission => nil
+ :date_column => "kb_articles.created_at" #, TODO: how to restrict access and yet be able to find articles?
+ #:permission => nil
acts_as_event :title => Proc.new { |o| "#{l(:label_title_articles)} ##{o.id}: #{o.title}" },
:description => Proc.new { |o| "#{o.content}" },
diff --git a/app/views/articles/_form.html.erb b/app/views/articles/_form.html.erb
index 76b2aa5..cbb50d6 100644
--- a/app/views/articles/_form.html.erb
+++ b/app/views/articles/_form.html.erb
@@ -13,4 +13,4 @@
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div>
-<%= wikitoolbar_for 'article_content' %>
\ No newline at end of file
+<%= wikitoolbar_for 'article_content' %>
diff --git a/config/routes.rb b/config/routes.rb
index 6a2204e..7adff00 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,7 +1,9 @@
match "/knowledgebase", :to => "knowledgebase#index", :via => :get
-scope "/knowledgebase" do
+resource :articles, :path => '/knowledgebase/articles', :via => [:get, :post]
+
+scope :knowledgebase do
resources :categories, :via => [:get, :post]
- resources :articles do
+ resources :articles, :path => '/articles', :via => [:get, :post] do
get "rate"
collection do
get "tagged"
diff --git a/init.rb b/init.rb
index 342c264..2b18dfd 100644
--- a/init.rb
+++ b/init.rb
@@ -70,5 +70,4 @@ Redmine::Plugin.register :redmine_knowledgebase do
Setting['plugin_redmine_knowledgebase']['knowledgebase_anonymous_access'].to_i == 1
}
- Redmine::Search.available_search_types << 'kb_articles'
end
diff --git a/redmine/lib/redmine.rb b/redmine/lib/redmine.rb.new
index 6b74af7..1fd6c5a 100644
--- a/redmine/lib/redmine.rb
+++ b/redmine/lib/redmine.rb.new
@@ -219,6 +219,7 @@ Redmine::Activity.map do |activity|
activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
activity.register :messages, :default => false
activity.register :time_entries, :default => false
+ activity.register :KbArticle
end
Redmine::Search.map do |search|
@@ -229,6 +230,7 @@ Redmine::Search.map do |search|
search.register :wiki_pages
search.register :messages
search.register :projects
+ search.register :KbArticle
end
Redmine::WikiFormatting.map do |format|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment