Permalink
Browse files

move shared before filters to controller helper module

  • Loading branch information...
1 parent 69b077c commit d077353abbdae6c9d9f71a2b396595a61bd5a7a0 Ryan Cook committed Jan 13, 2011
@@ -5,13 +5,10 @@ module Admin
# Standard CRUD Controller
class PagesController < ::ApplicationController
- # Check that a user is authenticated
- before_filter :is_authorized?
- # Check that the user is an admin
+ include Regulate::Helpers::ControllerHelpers
+ before_filter :is_authenticated?
before_filter :is_admin?, :only => [:new, :create, :destroy]
- # Check that the user is at least an editor
before_filter :is_editor?, :not => [:new, :create, :destroy]
- # Load in our page object based on the ID
before_filter :load_page, :only => [:edit,:update,:destroy]
# POST route to create a new page
@@ -61,29 +58,6 @@ def show
render :action => :edit
end
- private
-
- def is_authorized?
- @authorized_user = instance_eval &AbstractAuth.invoke(:authenticated_user)
- @is_admin = instance_eval &AbstractAuth.invoke(:is_admin)
- # Uncomment the following line to test out admin interface
- #@is_admin = true
- @is_editor = instance_eval &AbstractAuth.invoke(:is_editor)
- end
-
- def is_editor?
- redirect_to root_path if !@is_editor
- end
-
- def is_admin?
- redirect_to regulate_admin_regulate_pages_path if !@is_admin
- end
-
- # Grab a page resource based on the ID passed to the URI
- def load_page
- @page = Regulate::Page.find(params[:id])
- end
-
end # class PagesController
end # module Admin
@@ -1,12 +1,12 @@
module Regulate
- # @todo Build out XHR-only methods for frontend inline editing
- class PagesController < ActionController::Base
+ class PagesController < ::ApplicationController
+ include Regulate::Helpers::ControllerHelpers
+ before_filter :load_page
+ before_filter :is_authenticated?
+ before_filter :is_published?
- # Show function for front-end
- def show
- @page = Regulate::Page.find(params[:id])
- end
+ def show; end
end # class PagesController
@@ -0,0 +1,10 @@
+module Regulate
+
+ module Helpers
+
+ autoload :ControllerHelpers , 'regulate/helpers/controller_helpers'
+
+ end
+
+end
+
@@ -0,0 +1,46 @@
+module Regulate
+
+ module Helpers
+
+ module ControllerHelpers
+
+ private
+
+ # Check that a user is authenticated
+ def is_authenticated?
+ @authenticated_user = instance_eval &AbstractAuth.invoke(:authenticated_user)
+ @is_admin = instance_eval &AbstractAuth.invoke(:is_admin)
+ # Uncomment the following line to test out admin interface
+ #@is_admin = true
+ @is_editor = instance_eval &AbstractAuth.invoke(:is_editor)
+ end
+
+ # Check that the user is at least an editor
+ def is_editor?
+ redirect_to root_path if !@is_editor
+ end
+
+ # Check that the user is an admin
+ def is_admin?
+ redirect_to regulate_admin_regulate_pages_path if !@is_admin
+ end
+
+ # Grab a page resource based on the ID passed to the URI
+ # Load in our page object based on the ID
+ def load_page
+ @page = Regulate::Page.find(params[:id])
+ end
+
+ # Check whether a page is published
+ def is_published?
+ if !@is_admin || !@is_editor
+ redirect_to root_path if !@page.published
+ end
+ end
+
+ end
+
+ end
+
+end
+

0 comments on commit d077353

Please sign in to comment.