Skip to content

Commit

Permalink
Merge pull request #1058 from denny/refactor/admin-post-controllers
Browse files Browse the repository at this point in the history
Minor refactoring in Posts controllers/concern
  • Loading branch information
denny authored Apr 8, 2021
2 parents bbabf9a + 2fe4911 commit dc1d892
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
module ShinyBlog
# Admin area controller for ShinyBlog plugin for ShinyCMS
class Admin::BlogPostsController < AdminController
include ShinyCMS::Admin::WithDateTimeInputs
include ShinyCMS::Admin::WithDiscussions
include ShinyCMS::Admin::WithPosts
include ShinyCMS::Admin::WithTags

before_action :set_post_for_create, only: :create
before_action :set_post, only: %i[ edit update destroy ]

helper_method :admin_tag_list
helper_method :load_html_editor?

def index
authorize Post

Expand Down Expand Up @@ -111,10 +105,5 @@ def strong_params_for_update

combine_date_and_time_params( temp_params, :posted_at )
end

# Return true if the page we're on might need a WYSIWYG HTML editor
def load_html_editor?
action_name == 'new' || action_name == 'edit'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_discussion_or_update_flags( resource, show, lock )
if resource.discussion.present?
resource.discussion.update!( show_on_site: show, locked: lock )
elsif show
ShinyCMS::Discussion.create!( resource: @post, show_on_site: show, locked: lock )
ShinyCMS::Discussion.create!( resource: resource, show_on_site: show, locked: lock )
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions plugins/ShinyCMS/app/public/concerns/shinycms/admin/with_posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ module Admin
module WithPosts
extend ActiveSupport::Concern

include ShinyCMS::Admin::WithDateTimeInputs
include ShinyCMS::Admin::WithDiscussions
include ShinyCMS::Admin::WithTags

included do
helper_method :admin_tag_list
helper_method :load_html_editor?

def enforce_change_author_capability_for_create( category )
params[ :post ][ :user_id ] = current_user.id unless current_user.can? :change_author, category
end

def enforce_change_author_capability_for_update( category )
params[ :post ].delete( :user_id ) unless current_user.can? :change_author, category
end

# Return true if the page we're on might need a WYSIWYG HTML editor
def load_html_editor?
action_name == 'new' || action_name == 'edit'
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
module ShinyNews
# Admin area controller for ShinyNews plugin for ShinyCMS
class Admin::NewsPostsController < AdminController
include ShinyCMS::Admin::WithDateTimeInputs
include ShinyCMS::Admin::WithDiscussions
include ShinyCMS::Admin::WithPosts
include ShinyCMS::Admin::WithTags

before_action :set_post_for_create, only: :create
before_action :set_post, only: %i[ edit update destroy ]

helper_method :admin_tag_list
helper_method :load_html_editor?

def index
authorize Post

Expand Down Expand Up @@ -111,10 +105,5 @@ def strong_params_for_update

combine_date_and_time_params( temp_params, :posted_at )
end

# Return true if the page we're on might need a WYSIWYG HTML editor
def load_html_editor?
action_name == 'new' || action_name == 'edit'
end
end
end

0 comments on commit dc1d892

Please # to comment.