docbrown/app/controllers/internal/buffer_updates_controller.rb
Jess Lee ff135c7839 Give interns access to internal articles (#4016)
* add intern role and update policies

* update admin policy spec for rubocop

* add article poolicy spec

* fix spec

* switch to scoped admin role

* Finalize single resource admin

* Adjust buffer permissions
2019-09-19 11:35:49 -07:00

33 lines
1.4 KiB
Ruby

class Internal::BufferUpdatesController < Internal::ApplicationController
skip_before_action :authorize_admin # Instead, specific admin via authorize([:internal, Article])
before_action
def create
raise unless current_user.has_role?(:single_resource_admin, Article) || current_user.has_role?(:super_admin) || current_user.has_role?(:admin)
article_id = params[:article_id]
article = Article.find(article_id) if article_id.present?
fb_post = params[:fb_post]
tweet = params[:tweet]
listing_id = params[:listing_id]
listing = ClassifiedListing.find(params[:listing_id]) if listing_id.present?
case params[:social_channel]
when "main_twitter"
Bufferizer.new("article", article, tweet).main_tweet!
render body: nil
when "satellite_twitter"
Bufferizer.new("article", article, tweet).satellite_tweet!
render body: nil
when "facebook"
Bufferizer.new("article", article, fb_post).facebook_post!
render body: nil
when "listings_twitter"
Bufferizer.new("listing", listing, tweet).listings_tweet!
render body: nil
end
end
def update
raise unless current_user.has_role?(:single_resource_admin, Article) || current_user.has_role?(:super_admin) || current_user.has_role?(:admin)
BufferUpdate.upbuff!(params[:id], current_user.id, params[:body_text], params[:status])
render body: nil
end
end