diff options
Diffstat (limited to 'app/controllers/posts_controller.rb')
-rw-r--r-- | app/controllers/posts_controller.rb | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ff797a907..a65f4eee9 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -3,32 +3,39 @@ # the COPYRIGHT file. class PostsController < ApplicationController - skip_before_filter :set_invites - skip_before_filter :which_action_and_user - skip_before_filter :set_grammatical_gender - + before_filter :authenticate_user! + respond_to :html + respond_to :mobile + respond_to :json def show - @post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first - - #hax to upgrade logged in users who can comment + @post = current_user.find_visible_post_by_id params[:id] if @post - if user_signed_in? && current_user.find_visible_post_by_id(@post.id) - redirect_to "/#{@post.class.to_s.pluralize.underscore}/#{@post.id}" - return - end - @landing_page = true - @person = @post.author - if @person.owner_id - I18n.locale = @person.owner.language - render "posts/#{@post.class.to_s.underscore}", :layout => true - else - flash[:error] = I18n.t('posts.doesnt_exist') - redirect_to root_url + # mark corresponding notification as read + if notification = Notification.where(:recipient_id => current_user.id, :target_id => @post.id).first + notification.unread = false + notification.save + end + + respond_with @post + else + Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => current_user.id, :post_id => params[:id]) + flash[:error] = I18n.t('posts.show.not_found') + redirect_to :back + end + end + + def destroy + @post = current_user.posts.where(:id => params[:id]).first + if @post + current_user.retract(@post) + respond_to do |format| + format.js {render 'destroy'} + format.all {redirect_to root_url} end else - flash[:error] = I18n.t('posts.doesnt_exist') - redirect_to root_url + Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" + render :nothing => true, :status => 404 end end end |