diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 171ede5b0..89a657a37 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -22,9 +22,40 @@ class ProfilesController < ApplicationController def update # upload and set new profile photo - params[:profile] ||= {} - unless params[:profile][:tag_string].nil? || params[:profile][:tag_string] == I18n.t('profiles.edit.your_tags_placeholder') - params[:profile][:tag_string].split( " " ).each do |extra_tag| + @profile_attrs = params[:profile] || {} + + munge_tag_string + + @profile_attrs[:searchable] ||= false + + if params[:photo_id] + @profile_attrs[:photo] = Photo.where(:author_id => current_user.person.id, :id => params[:photo_id]).first + end + + if current_user.update_profile(@profile_attrs) + flash[:notice] = I18n.t 'profiles.update.updated' + else + flash[:error] = I18n.t 'profiles.update.failed' + end + + respond_to do |format| + format.js { render :nothing => true, :status => 200 } + format.html { + flash[:notice] = I18n.t 'profiles.update.updated' + if current_user.getting_started? + redirect_to getting_started_path + else + redirect_to edit_profile_path + end + } + end + end + + protected + + def munge_tag_string + unless @profile_attrs[:tag_string].nil? || @profile_attrs[:tag_string] == I18n.t('profiles.edit.your_tags_placeholder') + @profile_attrs[:tag_string].split( " " ).each do |extra_tag| extra_tag.strip! unless extra_tag == "" extra_tag = "##{extra_tag}" unless extra_tag.start_with?( "#" ) @@ -32,38 +63,6 @@ class ProfilesController < ApplicationController end end end - params[:profile][:tag_string] = (params[:tags]) ? params[:tags].gsub(',',' ') : "" - params[:profile][:searchable] ||= false - params[:profile][:photo] = Photo.where(:author_id => current_user.person.id, - :id => params[:photo_id]).first if params[:photo_id] - - if current_user.update_profile params[:profile] - respond_to do |format| - format.js { render :nothing => true, :status => 200 } - format.html { - flash[:notice] = I18n.t 'profiles.update.updated' - if current_user.getting_started? - - redirect_to getting_started_path - else - redirect_to edit_profile_path - end - } - end - - else - respond_to do |format| - format.js { render :nothing => true, :status => 200 } - format.html { - flash[:error] = I18n.t 'profiles.update.failed' - if params[:getting_started] - redirect_to getting_started_path(:step => params[:getting_started]) - else - redirect_to edit_profile_path - end - } - end - end - + @profile_attrs[:tag_string] = (params[:tags]) ? params[:tags].gsub(',',' ') : "" end end diff --git a/app/models/profile.rb b/app/models/profile.rb index f2dd39068..9bf2025c4 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -25,6 +25,7 @@ class Profile < ActiveRecord::Base xml_attr :bio xml_attr :location xml_attr :searchable + xml_attr :nsfw xml_attr :tag_string before_save :strip_names @@ -39,7 +40,7 @@ class Profile < ActiveRecord::Base validate :valid_birthday attr_accessible :first_name, :last_name, :image_url, :image_url_medium, - :image_url_small, :birthday, :gender, :bio, :location, :searchable, :date, :tag_string + :image_url_small, :birthday, :gender, :bio, :location, :searchable, :date, :tag_string, :nsfw belongs_to :person before_validation do diff --git a/app/views/profiles/_edit.haml b/app/views/profiles/_edit.haml index 77e92fdbe..6f15c4038 100644 --- a/app/views/profiles/_edit.haml +++ b/app/views/profiles/_edit.haml @@ -47,7 +47,14 @@ %p{:class=>"checkbox_select"} = label_tag 'profile[searchable]', t('profiles.edit.allow_search') = check_box_tag 'profile[searchable]', true, profile.searchable + %br + %br + %h4= t('nsfw') + %p.nsfw_explanation=profile.nsfw? ? t('.you_are_nsfw') : t('.you_are_safe_for_work') + %p{:class=>"checkbox_select"} + = check_box_tag 'profile[nsfw]', true, profile.nsfw? + = label_tag 'profile[nsfw]', "nsfw?" %br %br diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index c7a4a6162..ee7a7c095 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -33,6 +33,7 @@ en: public: "Public" limited: "Limited" search: "Search" + nsfw: "NSFW" find_people: "Find people or #tags" _home: "Home" more: "More" @@ -648,6 +649,8 @@ en: update_profile: "Update Profile" allow_search: "Allow for people to search for you within Diaspora" edit_profile: "Edit profile" + you_are_nsfw: "You have marked yourself not safe for work, your content will not show up in people who have opted out of seeing objectionable content's streams." + you_are_safe_for_work: "You have marked yourself as safe for work, this means you agree the content you post will agree with the community guidelines." update: updated: "Profile updated" failed: "Failed to update profile" diff --git a/db/migrate/20120127235102_add_nsfw_to_profiles.rb b/db/migrate/20120127235102_add_nsfw_to_profiles.rb new file mode 100644 index 000000000..582a0ecd4 --- /dev/null +++ b/db/migrate/20120127235102_add_nsfw_to_profiles.rb @@ -0,0 +1,9 @@ +class AddNsfwToProfiles < ActiveRecord::Migration + def self.up + add_column :profiles, :nsfw, :boolean, :default => false + end + + def self.down + remove_column :profiles, :nsfw + end +end diff --git a/db/schema.rb b/db/schema.rb index 268630e55..b863d086e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -343,6 +343,7 @@ ActiveRecord::Schema.define(:version => 20120203220932) do t.datetime "updated_at" t.string "location" t.string "full_name", :limit => 70 + t.boolean "nsfw", :default => false end add_index "profiles", ["full_name", "searchable"], :name => "index_profiles_on_full_name_and_searchable" diff --git a/features/not_safe_for_work.feature b/features/not_safe_for_work.feature new file mode 100644 index 000000000..ee8520c08 --- /dev/null +++ b/features/not_safe_for_work.feature @@ -0,0 +1,24 @@ +@javascript +Feature: Not safe for work + +Scenario: Setting not safe for work + Given a user named "pr0n king" with email "tommy@pr0n.xxx" + And I sign in as "tommy@pr0n.xxx" + When I go to the edit profile page + And I should see the "you are safe for work" message + And I mark myself as not safe for work + And I submit the form + Then I should be on the edit profile page + And I should see the "you are nsfw" message + + +Scenario: NSFWs users posts are nsfw + Given a nsfw user with email "tommy@pr0nking.com" + And I sign in as "tommy@pr0nking.com" + And I post "I love 0bj3ction4bl3 c0nt3nt!" + Then the post "I love 0bj3ction4bl3 c0nt3nt!" should be marked nsfw + +# And I log out +# And I log in as an office worker +# And I am folllowing "tommy@pr0n.xxx" +# Then I should not see "I love 0bj3ction4bl3 c0nt3nt!" in my stream diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 950c6ca9f..5ece903aa 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -4,11 +4,12 @@ When /^(.*) in the header$/ do |action| end end +And /^I submit the form$/ do + click_button :submit +end + And /^I expand the publisher$/ do - page.execute_script(' - $("#publisher").removeClass("closed"); - $("#publisher").find("textarea").focus(); - ') + click_publisher end When 'I click the aspects title' do diff --git a/features/step_definitions/message_steps.rb b/features/step_definitions/message_steps.rb index ded072ac1..dc8d140ad 100644 --- a/features/step_definitions/message_steps.rb +++ b/features/step_definitions/message_steps.rb @@ -9,8 +9,6 @@ Then /^I should see the "(.*)" message$/ do |message| I18n.translate('profiles.edit.you_are_safe_for_work') when 'you are nsfw' I18n.translate('profiles.edit.you_are_nsfw') - when 'hello' - "well hello there man" else raise "muriel, you don't have that message key, add one here" end diff --git a/features/step_definitions/posts_steps.rb b/features/step_definitions/posts_steps.rb index c57b7b169..4ff04041e 100644 --- a/features/step_definitions/posts_steps.rb +++ b/features/step_definitions/posts_steps.rb @@ -1,8 +1,6 @@ -When /^I post a photo with a token$/ do - json = JSON.parse < @me.authentication_token)) +Then /^the post "([^"]*)" should be marked nsfw$/ do |text| + pending + assert_nsfw(text) end Then /^I should see an uploaded image within the photo drop zone$/ do diff --git a/features/step_definitions/profile_steps.rb b/features/step_definitions/profile_steps.rb new file mode 100644 index 000000000..162364f2d --- /dev/null +++ b/features/step_definitions/profile_steps.rb @@ -0,0 +1,3 @@ +And /^I mark myself as not safe for work$/ do + check('profile[nsfw]') +end diff --git a/features/step_definitions/user_steps.rb b/features/step_definitions/user_steps.rb index 421572411..185876afc 100644 --- a/features/step_definitions/user_steps.rb +++ b/features/step_definitions/user_steps.rb @@ -7,28 +7,22 @@ Given /^a user with username "([^\"]*)" and password "([^\"]*)"$/ do |username, end Given /^a user with email "([^\"]*)"$/ do |email| - user = Factory(:user, :email => email, :password => 'password', - :password_confirmation => 'password', :getting_started => false) - user.aspects.create(:name => "Besties") - user.aspects.create(:name => "Unicorns") + create_user(:email => email) end Given /^a user with username "([^\"]*)"$/ do |username| - user = Factory(:user, :email => username + "@" + username + '.' + username, :username => username, - :password => 'password', :password_confirmation => 'password', :getting_started => false) - user.aspects.create(:name => "Besties") - user.aspects.create(:name => "Unicorns") + create_user(:email => username + "@" + username + '.' + username, :username => username) end Given /^a user named "([^\"]*)" with email "([^\"]*)"$/ do |name, email| first, last = name.split - username = "#{first}_#{last}" if first - user = Factory(:user, :email => email, :password => 'password', :username => "#{first}_#{last}", - :password_confirmation => 'password', :getting_started => false) - + user = create_user(:email => email, :username => "#{first}_#{last}") user.profile.update_attributes!(:first_name => first, :last_name => last) if first - user.aspects.create!(:name => "Besties") - user.aspects.create!(:name => "Unicorns") +end + +Given /^a nsfw user with email "([^\"]*)"$/ do |email| + user = create_user(:email => email) + user.profile.update_attributes(:nsfw => true) end Given /^I have been invited by an admin$/ do diff --git a/features/support/publishing_cuke_helpers.rb b/features/support/publishing_cuke_helpers.rb index 8441ac310..2df40dbf9 100644 --- a/features/support/publishing_cuke_helpers.rb +++ b/features/support/publishing_cuke_helpers.rb @@ -69,4 +69,4 @@ module PublishingCukeHelpers end end -World(PublishingCukeHelpers) \ No newline at end of file +World(PublishingCukeHelpers) diff --git a/features/support/user_cuke_helpers.rb b/features/support/user_cuke_helpers.rb new file mode 100644 index 000000000..a9152d760 --- /dev/null +++ b/features/support/user_cuke_helpers.rb @@ -0,0 +1,20 @@ +module UserCukeHelpers + def create_user(overrides={}) + default_attrs = { + :password => 'password', + :password_confirmation => 'password', + :getting_started => false + } + + user = Factory(:user, default_attrs.merge!(overrides)) + add_standard_aspects(user) + user + end + + def add_standard_aspects(user) + user.aspects.create(:name => "Besties") + user.aspects.create(:name => "Unicorns") + end +end + +World(UserCukeHelpers) \ No newline at end of file diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index ff6f9f31c..113f2b996 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -309,6 +309,7 @@ describe Profile do "gender", "bio", "searchable", + "nsfw", "location", "full_name"].sort end