From 01ae00451882aadaefd19941573755ef1e74fa13 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 8 Apr 2018 16:32:01 +0200 Subject: [PATCH] Make public stream accessible for logged out users Fixes #6564. closes #7775 --- Changelog.md | 1 + .../javascripts/app/views/stream_view.js | 2 +- app/assets/stylesheets/stream.scss | 4 + app/controllers/streams_controller.rb | 2 +- app/helpers/application_helper.rb | 4 + app/views/aspects/_aspect_stream.haml | 13 +- app/views/streams/main_stream.html.haml | 252 +++++++++--------- app/views/streams/main_stream.mobile.haml | 3 + features/desktop/keyboard_navigation.feature | 2 +- features/desktop/public_stream.feature | 4 + spec/controllers/streams_controller_spec.rb | 100 ++++--- spec/helpers/application_helper_spec.rb | 24 ++ 12 files changed, 240 insertions(+), 171 deletions(-) diff --git a/Changelog.md b/Changelog.md index 0f3e91f3c..d534ecf21 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ * Show error message when creating posts with invalid aspects [#7742](https://github.com/diaspora/diaspora/pull/7742) ## Features +* Make public stream accessible for logged out users [#7775](https://github.com/diaspora/diaspora/pull/7775) # 0.7.4.1 diff --git a/app/assets/javascripts/app/views/stream_view.js b/app/assets/javascripts/app/views/stream_view.js index 687822595..2a0fd9f9e 100644 --- a/app/assets/javascripts/app/views/stream_view.js +++ b/app/assets/javascripts/app/views/stream_view.js @@ -25,7 +25,7 @@ app.views.Stream = app.views.InfScroll.extend({ markNavSelected : function() { var activeStream = Backbone.history.fragment; - var streamSelection = $("#stream_selection"); + var streamSelection = $("#stream-selection"); streamSelection.find("[data-stream]").removeClass("selected"); streamSelection.find("[data-stream='" + activeStream + "']").addClass("selected"); diff --git a/app/assets/stylesheets/stream.scss b/app/assets/stylesheets/stream.scss index 38f8139f7..64c51974d 100644 --- a/app/assets/stylesheets/stream.scss +++ b/app/assets/stylesheets/stream.scss @@ -4,6 +4,10 @@ } } +.public-stream { + float: none; +} + .main-stream-publisher { margin-top: 20px; padding: 0; diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index 89190168c..0d0947616 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb @@ -5,7 +5,7 @@ # the COPYRIGHT file. class StreamsController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user!, except: :public before_action :save_selected_aspects, :only => :aspects layout proc { request.format == :mobile ? "application" : "with_header" } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f262b288a..213d034b6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -46,6 +46,10 @@ module ApplicationHelper current_user.services.size == AppConfig.configured_services.size end + def service_unconnected?(service) + AppConfig.show_service?(service, current_user) && current_user.services.none? {|x| x.provider == service } + end + def popover_with_close_html(without_close_html) without_close_html + link_to('×'.html_safe, "#", :class => 'close') end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 902528710..036640de3 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -2,12 +2,13 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.container-fluid.main-stream-publisher - .pull-left.hidden-xs - = owner_image_link - = render "publisher/publisher", publisher_aspects_for(stream) +- if user_signed_in? + .container-fluid.main-stream-publisher + .pull-left.hidden-xs + = owner_image_link + = render "publisher/publisher", publisher_aspects_for(stream) -- if current_user.getting_started? +- if current_user&.getting_started? .stream#main-stream{:title => popover_with_close_html("3. #{t('.stay_updated')}"), "data-content" => t(".stay_updated_explanation")} - else @@ -17,5 +18,5 @@ .loader.hidden .spinner -- if current_user.contacts.size < 2 +- if current_user && current_user.contacts.size < 2 = render 'aspects/no_contacts_message' diff --git a/app/views/streams/main_stream.html.haml b/app/views/streams/main_stream.html.haml index dd297185b..abc6f1f36 100644 --- a/app/views/streams/main_stream.html.haml +++ b/app/views/streams/main_stream.html.haml @@ -7,7 +7,7 @@ = javascript_include_tag :jsxc, id: 'jsxc', data: { endpoint: get_bosh_endpoint } -- if current_user.getting_started? +- if current_user&.getting_started? #welcome-to-diaspora .container-fluid .row @@ -22,159 +22,161 @@ .container-fluid .row - .col-md-3 - .sidebar.left-navbar - %ul#stream_selection - %li{data: {stream: "stream"}} - = link_to t("streams.multi.title"), stream_path, rel: "backbone", class: "hoverable" - %li.nested-list.my-activity{data: {stream: "activity"}} - = link_to t("streams.activity.title"), activity_stream_path, rel: "backbone", class: "hoverable" - %ul - %li{data: {stream: "liked"}} - = link_to t("streams.liked.title"), liked_stream_path, rel: "backbone", class: "hoverable selectable" - %li{data: {stream: "commented"}} - = link_to t("streams.commented.title"), commented_stream_path, - rel: "backbone", class: "hoverable selectable" - %li{data: {stream: "mentions"}} - = link_to t("streams.mentions.title"), mentioned_stream_path, rel: "backbone", class: "hoverable" - %li.nested-list.all-aspects - = render "aspects/aspect_listings", stream: @stream - %li.nested-list - = render "tags/followed_tags_listings" - %li{data: {stream: "public"}} - = link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable" + - if user_signed_in? + .col-md-3 + .sidebar.left-navbar + %ul#stream-selection + %li{data: {stream: "stream"}} + = link_to t("streams.multi.title"), stream_path, rel: "backbone", class: "hoverable" + %li.nested-list.my-activity{data: {stream: "activity"}} + = link_to t("streams.activity.title"), activity_stream_path, rel: "backbone", class: "hoverable" + %ul + %li{data: {stream: "liked"}} + = link_to t("streams.liked.title"), liked_stream_path, rel: "backbone", class: "hoverable selectable" + %li{data: {stream: "commented"}} + = link_to t("streams.commented.title"), commented_stream_path, + rel: "backbone", class: "hoverable selectable" + %li{data: {stream: "mentions"}} + = link_to t("streams.mentions.title"), mentioned_stream_path, rel: "backbone", class: "hoverable" + %li.nested-list.all-aspects + = render "aspects/aspect_listings", stream: @stream + %li.nested-list + = render "tags/followed_tags_listings" + %li{data: {stream: "public"}} + = link_to t("streams.public.title"), public_stream_path, rel: "backbone", class: "hoverable" + + .sidebar.info-bar.hidden-xs + - if AppConfig.settings.invitations.open? + .section.collapsed + .title + %h5.title-header + .entypo-triangle-right + .entypo-triangle-down + = t("shared.invitations.invite_your_friends") + .content + = render "shared/invitations" - .sidebar.info-bar.hidden-xs - - if AppConfig.settings.invitations.open? .section.collapsed .title %h5.title-header .entypo-triangle-right .entypo-triangle-down - = t("shared.invitations.invite_your_friends") + = t("aspects.index.new_here.title") .content - = render "shared/invitations" + != t("aspects.index.new_here.follow", + link: link_to("#" + t("shared.publisher.new_user_prefill.newhere"), + tag_path(name: t("shared.publisher.new_user_prefill.newhere")))) + %br + = link_to(t("aspects.index.new_here.learn_more"), + "http://wiki.diasporafoundation.org/Welcoming_Committee") - .section.collapsed - .title - %h5.title-header - .entypo-triangle-right - .entypo-triangle-down - = t("aspects.index.new_here.title") - .content - != t("aspects.index.new_here.follow", - link: link_to("#" + t("shared.publisher.new_user_prefill.newhere"), - tag_path(name: t("shared.publisher.new_user_prefill.newhere")))) - %br - = link_to(t("aspects.index.new_here.learn_more"), - "http://wiki.diasporafoundation.org/Welcoming_Committee") - - .section.collapsed - .title - %h5.title-header - .entypo-triangle-right - .entypo-triangle-down - = t("aspects.index.help.need_help") - .content - %p - = t("aspects.index.help.here_to_help") - %p - = t("aspects.index.help.do_you") - %ul - %li - != t("aspects.index.help.have_a_question", - link: link_to("#" + t("aspects.index.help.tag_question"), - tag_path(name: t("aspects.index.help.tag_question")))) - %li - != t("aspects.index.help.find_a_bug", - link: link_to(t("aspects.index.help.tag_bug"), - "https://wiki.diasporafoundation.org/How_to_report_a_bug")) - %li - != t("aspects.index.help.feature_suggestion", - link: link_to(t("aspects.index.help.tag_feature"), - "https://discourse.diasporafoundation.org/c/features-and-ideas")) - %p - != t("aspects.index.help.tutorials_and_wiki", - faq: link_to(t("_help"), help_path), - tutorial: link_to(t("aspects.index.help.tutorial_link_text"), - "https://diasporafoundation.org/tutorials", target: "_blank"), - wiki: link_to("Wiki", "http://wiki.diasporafoundation.org", - target: "_blank"), - target: "_blank") - - %p - != t("aspects.index.help.support_forum", - support_forum: link_to(t("aspects.index.help.support_forum_link"), - "https://discourse.diasporafoundation.org/c/support", target: "_blank")) - - - unless AppConfig.configured_services.blank? || all_services_connected? .section.collapsed .title %h5.title-header .entypo-triangle-right .entypo-triangle-down - = t("aspects.index.services.heading") + = t("aspects.index.help.need_help") .content - %div - = t("aspects.index.services.content") + %p + = t("aspects.index.help.here_to_help") + %p + = t("aspects.index.help.do_you") + %ul + %li + != t("aspects.index.help.have_a_question", + link: link_to("#" + t("aspects.index.help.tag_question"), + tag_path(name: t("aspects.index.help.tag_question")))) + %li + != t("aspects.index.help.find_a_bug", + link: link_to(t("aspects.index.help.tag_bug"), + "https://wiki.diasporafoundation.org/How_to_report_a_bug")) + %li + != t("aspects.index.help.feature_suggestion", + link: link_to(t("aspects.index.help.tag_feature"), + "https://discourse.diasporafoundation.org/c/features-and-ideas")) + %p + != t("aspects.index.help.tutorials_and_wiki", + faq: link_to(t("_help"), help_path), + tutorial: link_to(t("aspects.index.help.tutorial_link_text"), + "https://diasporafoundation.org/tutorials", target: "_blank"), + wiki: link_to("Wiki", "http://wiki.diasporafoundation.org", + target: "_blank"), + target: "_blank") - .right-service-icons - - AppConfig.configured_services.each do |service| - - if AppConfig.show_service?(service, current_user) - - unless current_user.services.any? {|x| x.provider == service } + %p + != t("aspects.index.help.support_forum", + support_forum: link_to(t("aspects.index.help.support_forum_link"), + "https://discourse.diasporafoundation.org/c/support", target: "_blank")) + + - unless AppConfig.configured_services.blank? || all_services_connected? + .section.collapsed + .title + %h5.title-header + .entypo-triangle-right + .entypo-triangle-down + = t("aspects.index.services.heading") + .content + %div + = t("aspects.index.services.content") + + .right-service-icons + - AppConfig.configured_services.each do |service| + - if service_unconnected?(service) = link_to(content_tag(:div, nil, class: "social-media-logos-#{service.to_s.downcase}-24x24", title: service.to_s.titleize), "/auth/#{service}") - .section.collapsed - .title - %h5.title-header - .entypo-triangle-right - .entypo-triangle-down - = t("bookmarklet.heading") - .content - != t("bookmarklet.explanation", link: link_to(t("bookmarklet.post_something"), bookmarklet_code)) - - - if donations_enabled? .section.collapsed .title %h5.title-header .entypo-triangle-right .entypo-triangle-down - = t("aspects.index.donate") + = t("bookmarklet.heading") + .content + != t("bookmarklet.explanation", link: link_to(t("bookmarklet.post_something"), bookmarklet_code)) + + - if donations_enabled? + .section.collapsed + .title + %h5.title-header + .entypo-triangle-right + .entypo-triangle-down + = t("aspects.index.donate") + .content + %p + = t("aspects.index.keep_pod_running", pod: AppConfig.pod_uri.host) + = render "shared/donatepod" + + - if AppConfig.admins.podmin_email.present? + .section.collapsed + .title + %h5.title-header + .entypo-triangle-right + .entypo-triangle-down + = t("aspects.index.help.any_problem") + .content + %p + = t("aspects.index.help.contact_podmin") + %p + = link_to t("aspects.index.help.mail_podmin"), "mailto:#{AppConfig.admins.podmin_email}" + + .excellence-box .content %p - = t("aspects.index.keep_pod_running", pod: AppConfig.pod_uri.host) - = render "shared/donatepod" + = link_to t("layouts.application.be_excellent"), "https://diasporafoundation.org/community_guidelines" - - if AppConfig.admins.podmin_email.present? - .section.collapsed - .title - %h5.title-header - .entypo-triangle-right - .entypo-triangle-down - = t("aspects.index.help.any_problem") + .info-links .content - %p - = t("aspects.index.help.contact_podmin") - %p - = link_to t("aspects.index.help.mail_podmin"), "mailto:#{AppConfig.admins.podmin_email}" + %ul + = render "shared/links" - .excellence-box - .content - %p - = link_to t("layouts.application.be_excellent"), "https://diasporafoundation.org/community_guidelines" + .powered-box + .content + .powered-by-diaspora.text-center + = link_to t("layouts.application.powered_by"), "https://diasporafoundation.org" - .info-links - .content - %ul - = render "shared/links" - - .powered-box - .content - .powered-by-diaspora.text-center - = link_to t("layouts.application.powered_by"), "https://diasporafoundation.org" - - .col-md-9 + .col-md-9{class: ("center-block public-stream" unless user_signed_in?)} .stream-container#aspect-stream-container + - unless user_signed_in? + %h2= @stream.title = render "aspects/aspect_stream", stream: @stream diff --git a/app/views/streams/main_stream.mobile.haml b/app/views/streams/main_stream.mobile.haml index 7b84c08e2..ce8eb270f 100644 --- a/app/views/streams/main_stream.mobile.haml +++ b/app/views/streams/main_stream.mobile.haml @@ -2,6 +2,9 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +- unless user_signed_in? + %h1= @stream.title + #main-stream.stream = render 'shared/stream', posts: @stream.stream_posts = render 'shared/stream_more_button' diff --git a/features/desktop/keyboard_navigation.feature b/features/desktop/keyboard_navigation.feature index f153e6e8f..b1e9078f3 100644 --- a/features/desktop/keyboard_navigation.feature +++ b/features/desktop/keyboard_navigation.feature @@ -25,7 +25,7 @@ Feature: Keyboard navigation Scenario: navigate downwards after changing the stream When I go to the activity stream page And I click on selector "[data-stream='stream'] a" - Then I should see "Stream" within "#stream_selection .selected" + Then I should see "Stream" within "#stream-selection .selected" When I press the "J" key somewhere Then post 1 should be highlighted diff --git a/features/desktop/public_stream.feature b/features/desktop/public_stream.feature index 02449b93c..8e53e1070 100644 --- a/features/desktop/public_stream.feature +++ b/features/desktop/public_stream.feature @@ -12,3 +12,7 @@ Feature: The public stream When I sign in as "alice@alice.alice" And I am on the public stream page Then I should see "Bob’s public post" + + Scenario: seeing public posts as a logged out user + When I am on the public stream page + Then I should see "Bob’s public post" diff --git a/spec/controllers/streams_controller_spec.rb b/spec/controllers/streams_controller_spec.rb index 9eb5e56ee..d46c22887 100644 --- a/spec/controllers/streams_controller_spec.rb +++ b/spec/controllers/streams_controller_spec.rb @@ -7,54 +7,80 @@ describe StreamsController, :type => :controller do include_context :gon - before do - sign_in alice - end - - describe "#public" do - it "succeeds" do - get :public - expect(response).to be_success - end - end - - describe '#multi' do - it 'succeeds' do - get :multi - expect(response).to be_success + context "with a logged in user" do + before do + sign_in alice end - it 'succeeds on mobile' do - get :multi, :format => :mobile - expect(response).to be_success + describe "#public" do + it "succeeds" do + get :public + expect(response).to be_success + end end - context "getting started" do - it "add the inviter to gon" do - user = FactoryGirl.create(:user, getting_started: true, invited_by: alice) - sign_in user - + describe "#multi" do + it "succeeds" do get :multi + expect(response).to be_success + end - expect(gon["preloads"][:mentioned_person][:name]).to eq(alice.person.name) - expect(gon["preloads"][:mentioned_person][:handle]).to eq(alice.person.diaspora_handle) + it "succeeds on mobile" do + get :multi, format: :mobile + expect(response).to be_success + end + + context "getting started" do + it "add the inviter to gon" do + user = FactoryGirl.create(:user, getting_started: true, invited_by: alice) + sign_in user + + get :multi + + expect(gon["preloads"][:mentioned_person][:name]).to eq(alice.person.name) + expect(gon["preloads"][:mentioned_person][:handle]).to eq(alice.person.diaspora_handle) + end + end + end + + streams = { + liked: Stream::Likes, + mentioned: Stream::Mention, + followed_tags: Stream::FollowedTag, + activity: Stream::Activity + } + + streams.each do |stream_path, stream_class| + describe "a GET to #{stream_path}" do + it "assigns a stream of the proper class" do + get stream_path + expect(response).to be_success + expect(assigns[:stream]).to be_a stream_class + end end end end - streams = { - :liked => Stream::Likes, - :mentioned => Stream::Mention, - :followed_tags => Stream::FollowedTag, - :activity => Stream::Activity - } - - streams.each do |stream_path, stream_class| - describe "a GET to #{stream_path}" do - it 'assigns a stream of the proper class' do - get stream_path + context "with no user signed in" do + describe "#public" do + it "succeeds" do + get :public expect(response).to be_success - expect(assigns[:stream]).to be_a stream_class + end + + it "succeeds on mobile" do + get :public, format: :mobile + expect(response).to be_success + end + end + + describe "other streams" do + it "redirects to the login page" do + %i[activity followed_tags liked mentioned multi].each do |stream_path| + get stream_path + expect(response).to be_redirect + expect(response).to redirect_to new_user_session_path + end end end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 569360e94..feb94673c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -35,6 +35,30 @@ describe ApplicationHelper, :type => :helper do end end + describe "#service_unconnected?" do + attr_reader :current_user + + before do + @current_user = alice + end + + it "returns true if the service is unconnected" do + expect(AppConfig).to receive(:show_service?).with("service", alice).and_return(true) + expect(service_unconnected?("service")).to be true + end + + it "returns false if the service is already connected" do + @current_user.services << FactoryGirl.build(:service, provider: "service") + expect(AppConfig).to receive(:show_service?).with("service", alice).and_return(true) + expect(service_unconnected?("service")).to be false + end + + it "returns false if the the service shouldn't be shown" do + expect(AppConfig).to receive(:show_service?).with("service", alice).and_return(false) + expect(service_unconnected?("service")).to be false + end + end + describe "#jquery_include_tag" do describe "with jquery cdn" do before do