From 9a23c92f8e4e6254fea03215536a8d7c47cb4e45 Mon Sep 17 00:00:00 2001 From: augier <christophe@c-henry.fr> Date: Fri, 24 Jul 2015 18:47:53 +0200 Subject: [PATCH] Show author of NSFW post --- app/assets/javascripts/mobile/mobile.js | 2 +- app/assets/stylesheets/mobile/mobile.scss | 20 ++++-- app/views/reshares/_reshare.mobile.haml | 15 +++-- app/views/shared/_nsfw_shield.mobile.haml | 6 ++ app/views/shared/_post_info.mobile.haml | 2 +- app/views/shared/_stream_element.mobile.haml | 19 +++--- features/mobile/not_safe_for_work.feature | 71 ++++++++++++++++++++ features/step_definitions/posts_steps.rb | 26 +++++++ features/step_definitions/stream_steps.rb | 4 ++ spec/integration/mobile_posts_spec.rb | 2 +- 10 files changed, 142 insertions(+), 25 deletions(-) create mode 100644 app/views/shared/_nsfw_shield.mobile.haml create mode 100644 features/mobile/not_safe_for_work.feature diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index 596bfa6735..783fb2ab74 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -25,7 +25,7 @@ $(document).ready(function(){ $('.shield a').click(function(){ - $(this).parents('.shield_wrapper').remove(); + $(this).parents(".stream_element").removeClass("shield-active"); return false; }); var showLoader = function(link){ diff --git a/app/assets/stylesheets/mobile/mobile.scss b/app/assets/stylesheets/mobile/mobile.scss index fe20a5ce7d..9d171d26e3 100644 --- a/app/assets/stylesheets/mobile/mobile.scss +++ b/app/assets/stylesheets/mobile/mobile.scss @@ -78,20 +78,28 @@ h3 { margin-top: 0; } .photo_attachments{ margin-top: 6px; } .timeago{ font-weight: normal; } } + .shield{ padding: 10px; font-size: larger; } -.shield_wrapper{ +.nsfw-shield{ height: 100%; width: 100%; background-color: LightGrey; - position: absolute; - border-radius: 5px; + border-radius: 0; z-index: 2; } +.stream_element:not(.shield-active) .shield{ + display: none; +} + +.stream_element.shield-active .nsfw-hidden{ + display: none; +} + .new_comment { padding: 10px; } @@ -459,7 +467,7 @@ h3 { margin-top: 0; } width: 20px; padding: 0; margin-left: 15px; - + &:last-child{ margin-right: 5px; } @@ -572,10 +580,10 @@ select { .reshare_via { width: 100%; position: absolute; - bottom: -7px; + bottom: -10px; text-align: center; span { - padding: 2px 10px; + padding: 0 10px; font-weight: bold; color: $text-grey; background: { diff --git a/app/views/reshares/_reshare.mobile.haml b/app/views/reshares/_reshare.mobile.haml index 36ee8c2e6b..16d0934689 100644 --- a/app/views/reshares/_reshare.mobile.haml +++ b/app/views/reshares/_reshare.mobile.haml @@ -4,17 +4,22 @@ .reshare - if post - = render 'shared/photo_area', :post => post + .nsfw-hidden + = render "shared/photo_area", post: post .content - = render 'shared/post_info', :post => post + = render "shared/post_info", post: post + + - unless post.is_a?(Reshare) + = render "shared/nsfw_shield", post: post - if !post.activity_streams? - = render 'status_messages/status_message', :post => post, :photos => post.photos + .nsfw-hidden + = render "status_messages/status_message", post: post, photos: post.photos - else .content - = t('.deleted') + = t(".deleted") .reshare_via %span - = t('.reshared_via') + = t(".reshared_via") diff --git a/app/views/shared/_nsfw_shield.mobile.haml b/app/views/shared/_nsfw_shield.mobile.haml new file mode 100644 index 0000000000..6fa3eb4e5a --- /dev/null +++ b/app/views/shared/_nsfw_shield.mobile.haml @@ -0,0 +1,6 @@ +- if post.respond_to?(:nsfw) && post.nsfw + .nsfw-shield + .shield + %strong #NSFW + | + = link_to t("javascripts.stream.show_nsfw_post"), "#", class: "toggle_nsfw_state" diff --git a/app/views/shared/_post_info.mobile.haml b/app/views/shared/_post_info.mobile.haml index 03d6aa5041..174b91b11d 100644 --- a/app/views/shared/_post_info.mobile.haml +++ b/app/views/shared/_post_info.mobile.haml @@ -31,5 +31,5 @@ - else = t('limited') - if !post.is_a?(Reshare) and post.location - .location + .location.nsfw-hidden = t("posts.show.location", location: post.location.address) diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml index eda9c75ab5..778384320c 100644 --- a/app/views/shared/_stream_element.mobile.haml +++ b/app/views/shared/_stream_element.mobile.haml @@ -2,26 +2,24 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.stream_element{data: {guid: post.id}} - - if post.respond_to?(:nsfw) && post.nsfw - .shield_wrapper - .shield - %strong #NSFW - | - = link_to t("javascripts.stream.show_nsfw_post"), "#" - +.stream_element{data: {guid: post.id}, class: post.respond_to?(:nsfw) && post.nsfw ? "shield-active" : ""} - if post.is_a?(Reshare) = render "reshares/reshare", reshare: post, post: post.absolute_root - = render "shared/photo_area", post: post + .nsfw-hidden + = render "shared/photo_area", post: post .content = render "shared/post_info", post: post + - unless post.is_a?(Reshare) + = render "shared/nsfw_shield", post: post + + .nsfw-hidden - if post.is_a?(StatusMessage) = render "status_messages/status_message", post: post, photos: post.photos - .bottom_bar + .bottom_bar.nsfw-hidden .floater = mobile_reshare_icon(post) = mobile_comment_icon(post) @@ -31,4 +29,3 @@ - if defined?(expanded_info) && expanded_info = render partial: "shared/post_stats", locals: {post: @post} - diff --git a/features/mobile/not_safe_for_work.feature b/features/mobile/not_safe_for_work.feature new file mode 100644 index 0000000000..bbebf8e870 --- /dev/null +++ b/features/mobile/not_safe_for_work.feature @@ -0,0 +1,71 @@ +@javascript @mobile +Feature: Not safe for work + Background: + Given a nsfw user with email "tommy@nsfw.example.com" + And a user with email "laura@office.example.com" + And a user with email "laura@office.example.com" is connected with "tommy@nsfw.example.com" + + Scenario: Setting not safe for work + + And I sign in as "tommy@nsfw.example.com" + When I go to the edit profile page + And I mark myself as not safe for work + And I submit the form + Then I should be on the edit profile page + And the "profile[nsfw]" checkbox should be checked + When I go to the edit profile page + And I mark myself as safe for work + And I submit the form + Then I should be on the edit profile page + And the "profile[nsfw]" checkbox should not be checked + + Scenario: Toggling nsfw state + #Nsfw users posts are marked nsfw + And "tommy@nsfw.example.com" has a public post with text "I love 0bj3ction4bl3 c0nt3nt!" and a poll + And "tommy@nsfw.example.com" has a public post with text "I love 0bj3ction4bl3 c0nt3nt!" and a location + And "tommy@nsfw.example.com" has a public post with text "I love 0bj3ction4bl3 c0nt3nt!" and a picture + + #toggling nsfw state + When I sign in as "laura@office.example.com" + Then I should not see "I love 0bj3ction4bl3 c0nt3nt!" + And I should not see "What do you think about 1 ninjas?" + And I should not see "Posted from:" + And I should not see any picture in my stream + When I toggle all nsfw posts + Then I should see "I love 0bj3ction4bl3 c0nt3nt!" + And I should see "What do you think about 1 ninjas?" + And I should see "Posted from:" + And I should see 1 pictures in my stream + + Scenario: Resharing a nsfw post with poll + And "tommy@nsfw.example.com" has a public post with text "Sexy Senators Gone Wild!" and a poll + And I sign in as "laura@office.example.com" + And I toggle all nsfw posts + And I follow "Reshare" + And I confirm the alert + And I go to the home page + Then I should not see "Sexy Senators Gone Wild!" + And I should not see "What do you think about 1 ninjas?" + And I should have 2 nsfw posts + + Scenario: Resharing a nsfw post with location + And "tommy@nsfw.example.com" has a public post with text "Sexy Senators Gone Wild!" and a location + And I sign in as "laura@office.example.com" + And I toggle all nsfw posts + And I follow "Reshare" + And I confirm the alert + And I go to the home page + Then I should not see "Sexy Senators Gone Wild!" + And I should not see "Posted from:" + And I should have 2 nsfw posts + + Scenario: Resharing a nsfw post with picture + And "tommy@nsfw.example.com" has a public post with text "Sexy Senators Gone Wild!" and a picture + And I sign in as "laura@office.example.com" + And I toggle all nsfw posts + And I follow "Reshare" + And I confirm the alert + And I go to the home page + Then I should not see "Sexy Senators Gone Wild!" + And I should not see any picture in my stream + And I should have 2 nsfw posts diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index 10c04b8abc..1a0d22e5a8 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -18,6 +18,14 @@ Then /^I should not see any posts in my stream$/ do page.assert_selector(".stream_element", count: 0) end +Then /^I should not see any picture in my stream$/ do + expect(page).to have_selector(".photo_area img", count: 0) +end + +Then /^I should see (\d+) pictures in my stream$/ do |count| + expect(page).to have_selector(".photo_area img", count: count) +end + Then /^I should not be able to submit the publisher$/ do expect(publisher_submittable?).to be false end @@ -27,6 +35,24 @@ Given /^"([^"]*)" has a public post with text "([^"]*)"$/ do |email, text| user.post(:status_message, :text => text, :public => true, :to => user.aspect_ids) end +Given /^"([^"]*)" has a public post with text "([^"]*)" and a poll$/ do |email, text| + user = User.find_by(email: email) + post = user.post(:status_message, text: text, public: true, to: user.aspect_ids) + FactoryGirl.create(:poll, status_message: post) +end + +Given /^"([^"]*)" has a public post with text "([^"]*)" and a location$/ do |email, text| + user = User.find_by(email: email) + post = user.post(:status_message, text: text, public: true, to: user.aspect_ids) + FactoryGirl.create(:location, status_message: post) +end + +Given /^"([^"]*)" has a public post with text "([^"]*)" and a picture/ do |email, text| + user = User.find_by(email: email) + post = user.post(:status_message, text: text, public: true, to: user.aspect_ids) + FactoryGirl.create(:photo, status_message: post) +end + Given /^there are (\d+) public posts from "([^"]*)"$/ do |n_posts, email| user = User.find_by_email(email) (1..n_posts.to_i).each do |n| diff --git a/features/step_definitions/stream_steps.rb b/features/step_definitions/stream_steps.rb index 9e38191e5c..830d9de827 100644 --- a/features/step_definitions/stream_steps.rb +++ b/features/step_definitions/stream_steps.rb @@ -14,6 +14,10 @@ When /^I toggle nsfw posts$/ do find(".toggle_nsfw_state", match: :first).click end +When /^I toggle all nsfw posts$/ do + all("a.toggle_nsfw_state").each &:click +end + Then /^I should have (\d+) nsfw posts$/ do |num_posts| page.should have_css(".nsfw-shield", count: num_posts.to_i) end diff --git a/spec/integration/mobile_posts_spec.rb b/spec/integration/mobile_posts_spec.rb index d743e61f73..54cc2e60c8 100644 --- a/spec/integration/mobile_posts_spec.rb +++ b/spec/integration/mobile_posts_spec.rb @@ -29,7 +29,7 @@ describe PostsController, type: :request do get "/posts/#{sm.id}", format: :mobile expect(response.status).to eq(200) - expect(response.body).to match(/div class='location'/) + expect(response.body).to match(/'location nsfw-hidden'/) expect(response.body).to match(/#{I18n.t("posts.show.location", location: sm.location.address)}/) end end -- GitLab