Module: ConcurrentDraft::AdminControllerExtensions
- Defined in:
- lib/concurrent_draft/admin_controller_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorized_user? ⇒ Boolean
- #check_for_promote_now ⇒ Object
- #schedule_draft_promotion ⇒ Object
- #unpublish ⇒ Object
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/concurrent_draft/admin_controller_extensions.rb', line 2 def self.included(base) base.class_eval do helper_method :model helper_method :model_class public :model, :model_class only_allow_access_to :schedule_draft_promotion, :unpublish, :when => [:publisher, :admin], :denied_message => "You must have publisher privileges to execute this action.", :denied_url => {:action => 'edit'} after_filter :check_for_promote_now, :only => [:create, :update] end end |
Instance Method Details
#authorized_user? ⇒ Boolean
15 16 17 |
# File 'lib/concurrent_draft/admin_controller_extensions.rb', line 15 def (current_user.publisher? || current_user.admin?) end |
#check_for_promote_now ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/concurrent_draft/admin_controller_extensions.rb', line 19 def check_for_promote_now if params[:promote] && model.promote_draft! flash[:notice] = "The existing draft #{model_class.to_s.downcase} has been saved and promoted, and is now live." flash.keep end end |
#schedule_draft_promotion ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/concurrent_draft/admin_controller_extensions.rb', line 27 def schedule_draft_promotion self.model = model_class.find(params[:id]) case params[:commit] when model_class.promote_now_text model.promote_draft! flash[:notice] = "The existing draft #{model_class.to_s.downcase} has been promoted and is now live." when model_class.schedule_promotion_text if model.update_attributes(params[model.class.name.underscore.intern]) flash[:notice] = "The draft #{model_class.to_s.downcase} will be promoted on #{model.draft_promotion_scheduled_at.to_s(:long_civilian)}." else flash[:error] = model.errors..to_sentence end when model_class.cancel_promotion_text model.cancel_promotion! flash[:notice] = "The scheduled draft #{model_class.to_s.downcase} promotion has been cancelled." end redirect_to :action => "edit" end |
#unpublish ⇒ Object
46 47 48 49 50 51 |
# File 'lib/concurrent_draft/admin_controller_extensions.rb', line 46 def unpublish self.model = model_class.find(params[:id]) model.unpublish! flash[:notice] = "#{model_class} has been unpublished and reset to draft mode -- no draft promotion scheduled." redirect_to :action => "edit" end |