summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorCharlie Root <root@web.ccc.local>2025-01-28 22:47:15 +0100
committerCharlie Root <root@web.ccc.local>2025-01-28 22:47:15 +0100
commitc4296b59a7f9d667d295f9c37b71f7849b818fb3 (patch)
treeccbace3a183c075991a0dfeb1dd9e6f25e901cf3 /app/controllers
parentdfbaadf0210b02a8bb54380c2c50302413dcf6d6 (diff)
Big overhaul patch and style changes
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_controller.rb11
-rw-r--r--app/controllers/application_controller.rb10
-rw-r--r--app/controllers/content_controller.rb26
-rw-r--r--app/controllers/tags_controller.rb45
4 files changed, 53 insertions, 39 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 1d1a1ca..cdfe564 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -20,13 +20,17 @@ class AdminController < ApplicationController
20 end 20 end
21 21
22 def search 22 def search
23 @results = Node.search params[:search_term] 23 @results = Node.search params[:search_term], :per_page => 1000
24 24
25 respond_to do |format| 25 respond_to do |format|
26 format.html 26 format.html do
27 render :template => 'admin/search_results.html'
28 end
27 format.js do 29 format.js do
28 render( :json => @results.map do |node| 30 render( :json => @results.map do |node|
29 {:id => node.id, :title => node.title, :edit_path => node_path(node)} 31 if node
32 {:id => node.id, :title => node.title, :edit_path => node_path(node)}
33 end
30 end 34 end
31 ) 35 )
32 36
@@ -46,7 +50,6 @@ class AdminController < ApplicationController
46 render :partial => 'admin/menu_search_results' 50 render :partial => 'admin/menu_search_results'
47 end 51 end
48 52
49
50 format.js do 53 format.js do
51 render( :json => @results.map do |node| 54 render( :json => @results.map do |node|
52 {:node_id => node.id, :title => node.title, :unique_name => node.unique_name} 55 {:node_id => node.id, :title => node.title, :unique_name => node.unique_name}
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index bce0c71..89cd330 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,20 +2,20 @@
2# Likewise, all the methods added will be available for all controllers. 2# Likewise, all the methods added will be available for all controllers.
3 3
4class ApplicationController < ActionController::Base 4class ApplicationController < ActionController::Base
5 5
6 include ExceptionNotifiable 6 include ExceptionNotifiable
7 include AuthenticatedSystem 7 include AuthenticatedSystem
8 8
9 helper :all # include all helpers, all the time 9 helper :all # include all helpers, all the time
10 protect_from_forgery # See ActionController::RequestForgeryProtection for details 10 protect_from_forgery # See ActionController::RequestForgeryProtection for details
11 11
12 # Scrub sensitive parameters from your log 12 # Scrub sensitive parameters from your log
13 filter_parameter_logging :password, :password_confirmation 13 filter_parameter_logging :password, :password_confirmation
14 14
15 before_filter :set_locale 15 before_filter :set_locale
16 16
17 protected 17 protected
18 18
19 def set_locale 19 def set_locale
20 if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym) 20 if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
21 I18n.locale = params[:locale].to_sym 21 I18n.locale = params[:locale].to_sym
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb
index 1b13456..c62b726 100644
--- a/app/controllers/content_controller.rb
+++ b/app/controllers/content_controller.rb
@@ -1,30 +1,30 @@
1class ContentController < ApplicationController 1class ContentController < ApplicationController
2 2
3 # Public 3 # Public
4 4
5 before_filter :find_page 5 before_filter :find_page
6 6
7 # This is the method that renders most of the the public content. It recieves 7 # This is the method that renders most of the the public content. It recieves
8 # a :locale and a :page_path parameter through the params hash. It looks up 8 # a :locale and a :page_path parameter through the params hash. It looks up
9 # the node with the corresponding unique_name attribute. The method doesn't 9 # the node with the corresponding unique_name attribute. The method doesn't
10 # return a node though, the node is really a proxy object for pages. It 10 # return a node though, the node is really a proxy object for pages. It
11 # returns the most recent page associated to this node instead. 11 # returns the most recent page associated to this node instead.
12 def render_page 12 def render_page
13 13
14 expires_in 20.minutes, :public => true 14 expires_in 20.minutes, :public => true
15 15
16 if @page and @page.public? 16 if @page and @page.public?
17 render( 17 render(
18 :file => @page.valid_template, 18 :file => @page.valid_template,
19 :layout => true 19 :layout => true
20 ) 20 )
21 else 21 else
22 render( 22 render(
23 :file => File.join(RAILS_ROOT, 'public', '404.html'), 23 :file => File.join(RAILS_ROOT, 'public', '404.html'),
24 :status => 404 24 :status => 404
25 ) 25 )
26 end 26 end
27 27
28 end 28 end
29 29
30 def render_gallery 30 def render_gallery
@@ -35,10 +35,14 @@ class ContentController < ApplicationController
35 render :nothing => true, :status => 404 35 render :nothing => true, :status => 404
36 end 36 end
37 end 37 end
38 38
39 private 39 private
40 def find_page 40 def find_page
41 path = params[:page_path].join('/') 41 path = params[:page_path].join('/')
42 @page = Node.find_page(path) 42 if path =~ /^[a-zA-Z\:\/\/\.\-\d_]+$/
43 @page = Node.find_page(path)
44 else
45 @page = nil
46 end
43 end 47 end
44end 48end
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 565cdd4..bf64b73 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -1,33 +1,40 @@
1class TagsController < ApplicationController 1class TagsController < ApplicationController
2 2
3 # Public 3 # Public
4 4
5 def index 5 def index
6 @page = Page.new :title => "Tags" 6 @page = Page.new :title => "Tags"
7 7
8 @tags = Tag.all(:limit => 500) 8 @tags = Tag.all(:limit => 500)
9 end 9 end
10 10
11 def show 11 def show
12 @tag = Tag.find_by_name(params[:id]) 12 tag_name = params[:id]
13 13
14 @tag = @tag ? @tag.name : params[:id] 14 if tag_name.match(/^[a-zA-Z0-9_\w\s\-\.\']+$/)
15 15 @tag = Tag.find_by_name(tag_name)
16 @page = Page.new 16 @tag = @tag ? @tag.name : tag_name
17 @page = Page.new
17 18
18 params[:page] = ( params[:page].is_a?(Fixnum) ? params[:page] : 1 ) 19 params[:page] = ( params[:page].is_a?(Fixnum) ? params[:page] : 1 )
19 20
20 @pages = Page.heads.paginate( 21 @pages = Page.heads.paginate(
21 Page.find_options_for_find_tagged_with(@tag).merge( 22 Page.find_options_for_find_tagged_with(@tag).merge(
22 :order => 'published_at DESC', 23 :order => 'published_at DESC',
23 :page=>params[:page], 24 :page=>params[:page],
24 :per_page => 23 25 :per_page => 23
26 )
25 ) 27 )
26 ) 28
27 29 respond_to do |format|
28 respond_to do |format| 30 format.html {}
29 format.html {} 31 end
32 else
33 respond_to do |format|
34 format.html { render :nothing => true, :status => 400 }
35 end
30 end 36 end
37
31 end 38 end
32 39
33end 40end