a user can mark themselves as nsfw
This commit is contained in:
parent
efd99344eb
commit
558ceec92a
15 changed files with 122 additions and 63 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
9
db/migrate/20120127235102_add_nsfw_to_profiles.rb
Normal file
9
db/migrate/20120127235102_add_nsfw_to_profiles.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
24
features/not_safe_for_work.feature
Normal file
24
features/not_safe_for_work.feature
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
When /^I post a photo with a token$/ do
|
||||
json = JSON.parse <<JSON
|
||||
{"activity":{"actor":{"url":"http://cubbi.es/daniel","displayName":"daniel","objectType":"person"},"published":"2011-05-19T18:12:23Z","verb":"save","object":{"objectType":"photo","url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","image":{"url":"http://i658.photobucket.com/albums/uu308/R3b3lAp3/Swagger_dog.jpg","width":637,"height":469}},"provider":{"url":"http://cubbi.es/","displayName":"Cubbi.es"}}}
|
||||
JSON
|
||||
page.driver.post(activity_streams_photos_path, json.merge!(:auth_token => @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
|
||||
|
|
|
|||
3
features/step_definitions/profile_steps.rb
Normal file
3
features/step_definitions/profile_steps.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
And /^I mark myself as not safe for work$/ do
|
||||
check('profile[nsfw]')
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
20
features/support/user_cuke_helpers.rb
Normal file
20
features/support/user_cuke_helpers.rb
Normal file
|
|
@ -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)
|
||||
|
|
@ -309,6 +309,7 @@ describe Profile do
|
|||
"gender",
|
||||
"bio",
|
||||
"searchable",
|
||||
"nsfw",
|
||||
"location",
|
||||
"full_name"].sort
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue