From 9789e25c996a18442af432efa1278d95abf53395 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Wed, 26 Oct 2011 17:32:02 -0700 Subject: [PATCH] fix oembed spec; prevent people from commenting on posts that wont federate --- app/controllers/posts_controller.rb | 16 ++++++++++++++++ app/views/shared/_stream_element.html.haml | 5 ++++- config/locales/diaspora/en.yml | 2 ++ spec/helpers/o_embed_helper_spec.rb | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 39b502e2e..5d43d159c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -19,8 +19,10 @@ class PostsController < ApplicationController if user_signed_in? @post = current_user.find_visible_shareable_by_id(Post, params[:id], :key => key) + @commenting_disabled = user_can_not_comment_on_post? else @post = Post.where(key => params[:id], :public => true).includes(:author, :comments => :author).first + @commenting_disabled = true end if @post @@ -65,4 +67,18 @@ class PostsController < ApplicationController def set_format_if_malformed_from_status_net request.format = :html if request.format == 'application/html+xml' end + + private + + def user_can_not_comment_on_post? + if @post.public && @post.author.local? + false + elsif current_user.contact_for(@post.author) + false + elsif current_user.owns?(@post) + false + else + true + end + end end diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 970793f3a..0db759119 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -70,7 +70,10 @@ – - - unless commenting_disabled?(post) + - if commenting_disabled?(post) + %span.federated_person{:title => "#{t('.federated_account')}"} + =t('.currently_unavailable') + - else %span.like_action = like_action(post, current_user) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index e600911d4..e67c65297 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -776,6 +776,8 @@ en: all_contacts: "All contacts" stream_element: viewable_to_anyone: "This post is viewable to anyone on the web" + federated_account: "Remote users who you are not connected to can not currently receive your likes and comments" + currently_unavailable: 'currently unavailable' via: "via %{link}" hide_and_mute: "Hide and Mute" like: "Like" diff --git a/spec/helpers/o_embed_helper_spec.rb b/spec/helpers/o_embed_helper_spec.rb index b984e8d51..c7333dd19 100644 --- a/spec/helpers/o_embed_helper_spec.rb +++ b/spec/helpers/o_embed_helper_spec.rb @@ -109,7 +109,7 @@ describe OEmbedHelper do real_data = data['oembed_data'] cache = OEmbedCache.new(:url => data['link_url']) cache.data = real_data - formatted = o_embed_html(cache) + formatted = o_embed_html(cache).gsub('https', 'http') case type when 'photo' formatted.should =~ /#{data['oembed_data']['url']}/