facebookpublish,themen fixes

This commit is contained in:
2014-06-20 00:15:45 +05:30
parent 61510a8891
commit 2df0d89b61
16 changed files with 158 additions and 37 deletions

View File

@@ -14,6 +14,12 @@ class HomeController < ApplicationController
@neuigkeiten = Neuigkeit.intern.recent
@themengruppen=Themengruppe.intern
end
def admin
authorize! :doadmin, User
end
def startdev
render 'setup_fetsite_dev'
end

View File

@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
class NeuigkeitenController < ApplicationController
before_filter :load_toolbar_elements, :only=>[:show,:find_link]
before_filter :load_toolbar_elements_edit, :only=>[:edit]
@@ -61,9 +62,19 @@ class NeuigkeitenController < ApplicationController
if params[:verwalten]
redirect_to verwalten_rubrik_path(@neuigkeit.rubrik)
end
redirect_to rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit)
redirect_to rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit)
end
def publish_to_facebook
@neuigkeit = Neuigkeit.find(params[:id])
unless @neuigkeit.published?
redirect_to [@neuigkeit.rubrik,@neuigkeit], notice: 'Neuigkeit muss veröffentlicht sein um sie auf Facebook zu posten.'
else
page=YAML.load_file("#{::Rails.root.to_s}/tmp/page.yml")
page.feed!(:access_token=>page.access_token, :message=>@neuigkeit.text_first_words, :name=>@neuigkeit.title, :link=>rubrik_neuigkeit_url(@neuigkeit.rubrik, @neuigkeit)+".html")
redirect_to [@neuigkeit.rubrik,@neuigkeit], notice: 'Neuigkeit auf Facebook gepostet'
end
end
def edit
@neuigkeit = Neuigkeit.find(params[:id])
@@ -137,9 +148,13 @@ private
def load_toolbar_elements
@neuigkeit=Neuigkeit.find(params[:id])
@toolbar_elements=[]
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:publish, @neuigkeit) && @neuigkeit.published?
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:unpublish, @neuigkeit) && !@neuigkeit.published?
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
@toolbar_elements << {:hicon=>'icon-plus', :text=> I18n.t('neuigkeit.publish'),:path => publish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:publish, @neuigkeit) && !@neuigkeit.published?
@toolbar_elements << {:hicon=>'icon-facebook', :text=> I18n.t('neuigkeit.publish')+" to facebook",:path => publish_to_facebook_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:publish, @neuigkeit)
@toolbar_elements << {:hicon=>'icon-minus', :text=> I18n.t('neuigkeit.unpublish'),:path => unpublish_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:confirm=>'Sure?' } if can?(:unpublish, @neuigkeit) && @neuigkeit.published?
@toolbar_elements << {:text=>I18n.t('common.edit'),:path=>edit_rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:icon=>:pencil} if can? :edit, @neuigkeit.rubrik
@versions= @neuigkeit.translation.versions.select([:created_at]).reverse
@toolbar_elements <<{:path=>rubrik_neuigkeit_path(@neuigkeit.rubrik,@neuigkeit),:method=>:versions,:versions=>@versions}

View File

@@ -57,13 +57,14 @@ class ThemenController < ApplicationController
# GET /themen/1/edit
def edit
@thema = Thema.find(params[:id])
unless ( @thema.wikiname.nil? || @thema.wikiname.empty? )
if @thema.is_wiki?
redirect_to edit_wiki_path(Wiki.find(@thema.id))
return
end
respond_to do |format|
format.html
format.js
format.js { @themen= @thema.themengruppe.themen }
end
end
@@ -72,13 +73,15 @@ class ThemenController < ApplicationController
def create
@thema = Thema.new(params[:thema])
@themen = @thema.themengruppe.themen.order(:priority).reverse
respond_to do |format|
if @thema.save
@themen = @thema.themengruppe.themen.order(:priority).reverse
format.html { redirect_to @thema, notice: 'Thema was successfully created.' }
format.json { render json: @thema, status: :created, location: @thema }
format.js {render action: "update"}
else
@themen = @thema.themengruppe.themen.order(:priority).reverse
format.html { render action: "new" }
format.json { render json: @thema.errors, status: :unprocessable_entity }
format.js { render action: "edit" }
@@ -105,8 +108,10 @@ class ThemenController < ApplicationController
def update
@thema = Thema.find(params[:id])
@themen = @thema.themengruppe.themen.order(:priority).reverse
@thema.assign_attributes(params[:thema])
@thema.fix_links(request.host_with_port)
respond_to do |format|
if @thema.update_attributes(params[:thema])
if @thema.save
format.html { redirect_to @thema, notice: 'Thema was successfully updated.' }
format.json { head :no_content }
format.js
@@ -123,7 +128,7 @@ class ThemenController < ApplicationController
def destroy
@thema = Thema.find(params[:id])
@thema.destroy
@themen = @thema.themengruppe.themen.order(:priority).reverse
respond_to do |format|
format.html { redirect_to themengruppe_path(@thema.themengruppe) }
format.json { head :no_content }

View File

@@ -48,7 +48,8 @@ class ThemengruppenController < ApplicationController
@themengruppe = Themengruppe.find(params[:id])
end
def verwalten_all
@themengruppen =Themengruppe.order(:priority).reverse
@themengruppen =Themengruppe.public.order(:priority).reverse
@themengruppen_intern =Themengruppe.intern.order(:priority).reverse
@toolbar_elements = [{:icon=>:plus, :hicon=>'icon-plus-sign', :text=>I18n.t('themengruppe.new'), :path=>new_themengruppe_path()}]
end

View File

@@ -1,15 +1,17 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
def failure
# flash[:notice] = "Failure #{Hash.new(request.env)} #{Hash.new(params)}"
#redirect_to new_user_registration_url , :notice=>"Omniauth Login failed"
super
end
def facebook
skip_before_filter :verify_authenticity_token
def failure
# flash[:notice] = "Failure #{Hash.new(request.env)} #{Hash.new(params)}"
#redirect_to new_user_registration_url , :notice=>"Omniauth Login failed"
super
end
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)
data=request.env["omniauth.auth"]
session[:fbuser_access_token]=data.credentials.token
if @user
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated

View File

@@ -12,9 +12,19 @@ class UsersController < ApplicationController
end
redirect_to users_url
end
def fb_set_default_publish_page
if params["page"].nil? || !(current_user.provider=="facebook")
redirect_to intern_home_index_path
else
@fbu=FbGraph::User.new(current_user.uid.to_s).fetch(:access_token=>session["fbuser_access_token"])
File.open("tmp/page.yml",'w'){|f| f.write(@fbu.accounts(:access_token=>session["fbuser_access_token"]).select { |p| p.name == params["page"] }.first.to_yaml)}
logger.debug @fbu.to_s
redirect_to admin_home_index_path
end
end
def all_update
params[:users].each do |id,u|
user=User.find(id)
user.fetprofile = Fetprofile.find(u[:fetprofile_id].to_i) if u[:fetprofile_id].to_i>0
@@ -26,7 +36,6 @@ class UsersController < ApplicationController
def do_confirm
@user= User.find(params[:id])
@user.confirm!
redirect_to users_url
end
end