summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_controller.rb2
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/assets_controller.rb2
-rw-r--r--app/controllers/content_controller.rb2
-rw-r--r--app/controllers/events_controller.rb2
-rw-r--r--app/controllers/menu_items_controller.rb2
-rw-r--r--app/controllers/nodes_controller.rb4
-rw-r--r--app/controllers/occurrences_controller.rb2
-rw-r--r--app/controllers/pages_controller.rb2
-rw-r--r--app/controllers/revisions_controller.rb2
-rw-r--r--app/controllers/rss_controller.rb4
-rw-r--r--app/controllers/tags_controller.rb2
-rw-r--r--app/controllers/users_controller.rb6
-rw-r--r--app/models/node.rb51
-rw-r--r--app/models/occurrence.rb2
-rw-r--r--app/models/page.rb6
16 files changed, 54 insertions, 39 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index 18c4104..9e8564e 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -2,7 +2,7 @@ class AdminController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 def index 7 def index
8 @drafts = Node.where("draft_id IS NOT NULL") 8 @drafts = Node.where("draft_id IS NOT NULL")
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 4d0ed2e..32c7373 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
6 6
7 protect_from_forgery # See ActionController::RequestForgeryProtection for details 7 protect_from_forgery # See ActionController::RequestForgeryProtection for details
8 8
9 before_filter :set_locale 9 before_action :set_locale
10 10
11 protected 11 protected
12 12
diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb
index cfaf176..a11bbdd 100644
--- a/app/controllers/assets_controller.rb
+++ b/app/controllers/assets_controller.rb
@@ -2,7 +2,7 @@ class AssetsController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 layout 'admin' 7 layout 'admin'
8 8
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb
index 4248239..876bccf 100644
--- a/app/controllers/content_controller.rb
+++ b/app/controllers/content_controller.rb
@@ -2,7 +2,7 @@ class ContentController < ApplicationController
2 2
3 # Public 3 # Public
4 4
5 before_filter :find_page 5 before_action :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
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb
index 805e941..6eba476 100644
--- a/app/controllers/events_controller.rb
+++ b/app/controllers/events_controller.rb
@@ -2,7 +2,7 @@ class EventsController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 layout 'admin' 7 layout 'admin'
8 8
diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb
index 24a3d5e..4018693 100644
--- a/app/controllers/menu_items_controller.rb
+++ b/app/controllers/menu_items_controller.rb
@@ -2,7 +2,7 @@ class MenuItemsController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 layout 'admin' 7 layout 'admin'
8 8
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index 2b36b78..482d0ac 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -4,8 +4,8 @@ class NodesController < ApplicationController
4 4
5 layout 'admin' 5 layout 'admin'
6 6
7 before_filter :login_required 7 before_action :login_required
8 before_filter :find_node, :only => [ 8 before_action :find_node, :only => [
9 :show, 9 :show,
10 :edit, 10 :edit,
11 :update, 11 :update,
diff --git a/app/controllers/occurrences_controller.rb b/app/controllers/occurrences_controller.rb
index 751be40..61b42ff 100644
--- a/app/controllers/occurrences_controller.rb
+++ b/app/controllers/occurrences_controller.rb
@@ -2,7 +2,7 @@ class OccurrencesController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 # GET /occurrences 7 # GET /occurrences
8 # GET /occurrences.xml 8 # GET /occurrences.xml
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index a684327..f5609eb 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -2,7 +2,7 @@ class PagesController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 def preview 7 def preview
8 @page = Page.find(params[:id]) 8 @page = Page.find(params[:id])
diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb
index 8c16730..42d667e 100644
--- a/app/controllers/revisions_controller.rb
+++ b/app/controllers/revisions_controller.rb
@@ -2,7 +2,7 @@ class RevisionsController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 6
7 layout 'admin' 7 layout 'admin'
8 8
diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb
index be9cd2c..4b47218 100644
--- a/app/controllers/rss_controller.rb
+++ b/app/controllers/rss_controller.rb
@@ -1,7 +1,7 @@
1class RssController < ApplicationController 1class RssController < ApplicationController
2 2
3 before_filter :authenticate, :only => :recent_changes 3 before_action :authenticate, :only => :recent_changes
4 before_filter :get_host 4 before_action :get_host
5 5
6 def updates 6 def updates
7 expires_in 31.minutes, :public => true 7 expires_in 31.minutes, :public => true
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index e4ceec9..bf6a029 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -35,7 +35,7 @@ class TagsController < ApplicationController
35 end 35 end
36 else 36 else
37 respond_to do |format| 37 respond_to do |format|
38 format.html { render :nothing => true, :status => 400 } 38 format.html { head :bad_request }
39 end 39 end
40 end 40 end
41 41
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 1d85690..72e6058 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -2,9 +2,9 @@ class UsersController < ApplicationController
2 2
3 # Private 3 # Private
4 4
5 before_filter :login_required 5 before_action :login_required
6 before_filter :find_user, :only => [:show, :edit, :update, :destroy] 6 before_action :find_user, :only => [:show, :edit, :update, :destroy]
7 before_filter :verify_status, :except => [:index, :show] 7 before_action :verify_status, :except => [:index, :show]
8 8
9 layout 'admin' 9 layout 'admin'
10 10
diff --git a/app/models/node.rb b/app/models/node.rb
index 8be6daf..d760f0a 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -16,10 +16,10 @@ class Node < ActiveRecord::Base
16 after_save :update_unique_names_of_children 16 after_save :update_unique_names_of_children
17 17
18 # Validations 18 # Validations
19 validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" 19 validates_length_of :slug, :within => 1..255, :unless => -> { parent_id.nil? }
20 validates_presence_of :slug, :unless => "parent_id.nil?" 20 validates_presence_of :slug, :unless => -> { parent_id.nil? }
21 validates_uniqueness_of :slug, :scope => :parent_id, :unless => "parent_id.nil?" 21 validates_uniqueness_of :slug, :scope => :parent_id, :unless => -> { parent_id.nil? }
22 validates_presence_of :parent_id, :unless => "Node.root.nil?" 22 validates_presence_of :parent_id, :unless => -> { Node.root.nil? }
23 23
24 validate :borders # This should never ever happen. 24 validate :borders # This should never ever happen.
25 25
@@ -95,26 +95,37 @@ class Node < ActiveRecord::Base
95 end 95 end
96 96
97 def publish_draft! 97 def publish_draft!
98 # Return nil if nothing to publish and no staged changes
99 return nil unless self.draft || staged_slug || staged_parent_id
100
98 if self.draft 101 if self.draft
99 self.head = self.draft 102 self.head = self.draft
100 self.head.published_at ||= Time.now 103 self.head.published_at ||= Time.now
101 self.head.save! 104 self.head.save!
102
103 self.draft = nil 105 self.draft = nil
106 end
104 107
105 if staged_slug && (staged_slug != slug) 108 if staged_slug && (staged_slug != slug)
106 self.slug = staged_slug 109 self.slug = staged_slug
107 end 110 self.staged_slug = nil
108 111 end
109 if staged_parent_id && (staged_parent_id != parent_id)
110 self.parent_id = staged_parent_id
111 end
112 112
113 if staged_parent_id && (staged_parent_id != parent_id)
114 new_parent = Node.find(staged_parent_id)
115 self.staged_parent_id = nil
113 self.save! 116 self.save!
114 self.update_unique_name 117 self.move_to_child_of(new_parent)
115 self.unlock! 118 else
116 self 119 unless self.save
120 raise ActiveRecord::RecordInvalid.new(self)
121 end
117 end 122 end
123
124 self.reload
125 self.update_unique_name
126 self.send(:update_unique_names_of_children)
127 self.unlock!
128 self
118 end 129 end
119 130
120 # removes a draft and the lock if it is older than a day and still 131 # removes a draft and the lock if it is older than a day and still
@@ -146,7 +157,7 @@ class Node < ActiveRecord::Base
146 157
147 # returns an array with all parts of a unique_name rather than a string 158 # returns an array with all parts of a unique_name rather than a string
148 def unique_path 159 def unique_path
149 unique_name.to_s 160 unique_name.to_s.split("/")
150 end 161 end
151 162
152 # returns array with pages up to root excluding root 163 # returns array with pages up to root excluding root
@@ -228,8 +239,12 @@ class Node < ActiveRecord::Base
228 # Hopefully until no childrens occur 239 # Hopefully until no childrens occur
229 def update_unique_names_of_children 240 def update_unique_names_of_children
230 unless root? 241 unless root?
231 self.descendants.each do |descendant| 242 # Use parent_id-based traversal instead of lft/rgt descendants
232 descendant.update_unique_name 243 # due to awesome_nested_set not refreshing parent lft/rgt in memory
244 Node.where(:parent_id => self.id).each do |child|
245 child.reload
246 child.update_unique_name
247 child.send(:update_unique_names_of_children)
233 end 248 end
234 end 249 end
235 end 250 end
diff --git a/app/models/occurrence.rb b/app/models/occurrence.rb
index 0760d5e..8457ffd 100644
--- a/app/models/occurrence.rb
+++ b/app/models/occurrence.rb
@@ -26,7 +26,7 @@ class Occurrence < ActiveRecord::Base
26 # variables are set to save repetitive queries. The occurrences of the given 26 # variables are set to save repetitive queries. The occurrences of the given
27 # event are then calculated and created. 27 # event are then calculated and created.
28 def self.generate event 28 def self.generate event
29 self.delete_all(:event_id => event.id) 29 self.where(:event_id => event.id).delete_all
30 30
31 node = event.node 31 node = event.node
32 duration = (event.end_time - event.start_time) 32 duration = (event.end_time - event.start_time)
diff --git a/app/models/page.rb b/app/models/page.rb
index e2cbee5..93debf8 100644
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -83,7 +83,7 @@ class Page < ActiveRecord::Base
83 # outdated_translations? for more information. 83 # outdated_translations? for more information.
84 # Takes :locale => <locale> and :delta_time => 12.hours as options 84 # Takes :locale => <locale> and :delta_time => 12.hours as options
85 def self.find_with_outdated_translations options = {} 85 def self.find_with_outdated_translations options = {}
86 Page.all(:include => :translations).select do |page| 86 Page.includes(:translations).select do |page|
87 page.outdated_translations? options 87 page.outdated_translations? options
88 end 88 end
89 end 89 end
@@ -182,8 +182,8 @@ class Page < ActiveRecord::Base
182 182
183 translations = self.translations 183 translations = self.translations
184 184
185 default = *(translations.select {|x| x.locale == I18n.default_locale}) 185 default = translations.find {|x| x.locale.to_s == I18n.default_locale.to_s }
186 custom = *(translations.select {|x| x.locale == options[:locale]}) 186 custom = translations.find {|x| x.locale.to_s == options[:locale].to_s }
187 187
188 if translations.size > 1 && default && custom 188 if translations.size > 1 && default && custom
189 difference = (default.updated_at - custom.updated_at).to_i.abs 189 difference = (default.updated_at - custom.updated_at).to_i.abs