app/controllers/concerns/adminpanel/facebook_actions.rb in adminpanel-2.1.7 vs app/controllers/concerns/adminpanel/facebook_actions.rb in adminpanel-2.2.0

- old
+ new

@@ -1,11 +1,11 @@ module Adminpanel module FacebookActions extend ActiveSupport::Concern included do - before_filter :set_auths_count, only:[:index, :create, :update, :destroy, :show] + before_filter :set_fb_auths_count, only:[:index, :create, :update, :destroy, :show] end def fb_choose_page access_token = Koala::Facebook::OAuth.new( Adminpanel.fb_app_id, @@ -26,33 +26,35 @@ def fb_save_token page_selected = Koala::Facebook::API.new( params[model_name][:fb_page_access_key] ) - update_facebook_auth(page_selected.get_object('me')['name']) + update_fb_auth(page_selected.get_object('me')['name']) flash[:success] = I18n.t('fb.saved_token') redirect_to resource end def fb_publish + authorize! :publish, resource + page_graph = Koala::Facebook::API.new(Auth.find_by_key('facebook').value) page_graph.put_wall_post( params[model_name][:fb_message], { - link: resource.fb_link, + link: resource.share_link, name: resource.name } ) flash[:success] = I18n.t('fb.posted', user: page_graph.get_object('me')['name']) redirect_to resource end private - def set_auths_count + def set_fb_auths_count @fb_auths_count = Auth.where(key: 'facebook').count end - def update_facebook_auth(account_selected_name) + def update_fb_auth(account_selected_name) auths = Auth.where(key: 'facebook', name: account_selected_name) if auths.count == 0 Auth.create( key: 'facebook', name: account_selected_name,