Permalink
Browse files

add is_admin

  • Loading branch information...
1 parent e755026 commit e26516ff506cee678df471edc55f429f69388600 @xdite committed Apr 8, 2013
@@ -39,6 +39,11 @@ def generate_auto_facebook
generate 'auto_facebook:install'
end
+ def insert_admin_method_to_user
+ inject_into_file 'app/models/user.rb',
+ "\n\n def admin?\n Setting.admin_emails.include?(email)\n end\n", :after => '# attr_accessible :title, :body'
+ end
+
def replace_email_sender_for_devise
replace_in_file 'config/initializers/devise.rb', /config\.mailer_sender = \".+\"/ , "config.mailer_sender = Setting.email_sender"
end
@@ -99,7 +99,7 @@ def configure_app
build :setup_devise
build :build_auto_facebook
build :build_settings_from_config
-
+ build :build_admin_method_to_user
end
def create_initializers
@@ -116,6 +116,10 @@ def build_auto_facebook
build :generate_auto_facebook
end
+ def build_admin_method_to_user
+ build :insert_admin_method_to_user
+ end
+
def customize_error_pages
say 'Customizing the 500/404/422 pages'
build :customize_error_pages
@@ -1,3 +1,3 @@
module Bootstrappers
- VERSION = "0.2.1"
+ VERSION = "0.2.2"
end
@@ -19,4 +19,10 @@ class ApplicationController < ActionController::Base
end
+ def require_is_admin
+ unless (current_user && current_user.admin?)
+ redirect_to root_path, :flash => { :error => "no permission" }
+ end
+ end
+
end

0 comments on commit e26516f

Please sign in to comment.