From ae7944418cacae3e44783fa631d33f73acfe07e8 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 2 Nov 2011 17:57:43 -0700 Subject: [PATCH] DH DG; made privacy page; can now unblock a user; users are actually being blockocked in ajaxed streams --- app/controllers/application_controller.rb | 2 +- app/controllers/blocks_controller.rb | 8 +++-- app/controllers/users_controller.rb | 4 +++ app/helpers/stream_element_helper.rb | 9 +++--- app/helpers/stream_helper.rb | 7 ++--- app/models/post.rb | 6 ++-- app/models/user.rb | 2 +- app/views/aspects/_aspect_stream.haml | 8 ++--- app/views/shared/_settings_nav.haml | 1 + app/views/users/privacy_settings.html.haml | 23 +++++++++++++++ config/locales/diaspora/en.yml | 10 ++++++- config/routes.rb | 13 ++++---- db/schema.rb | 1 + lib/stream/base.rb | 2 +- public/javascripts/widgets/stream-element.js | 16 ++++++---- spec/controllers/blocks_controller_spec.rb | 31 +++++++++++++++----- spec/controllers/users_controller_spec.rb | 17 +++++++---- spec/models/user_spec.rb | 8 ++--- 18 files changed, 116 insertions(+), 52 deletions(-) create mode 100644 app/views/users/privacy_settings.html.haml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35b2c4f2d..1314686d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -154,7 +154,7 @@ class ApplicationController < ActionController::Base @stream = stream_klass.new(current_user, :max_time => max_time, :order => sort_order) if params[:only_posts] - render :partial => 'shared/stream', :locals => {:posts => @stream.posts} + render :partial => 'shared/stream', :locals => {:posts => @stream.stream_posts} else render 'aspects/index' end diff --git a/app/controllers/blocks_controller.rb b/app/controllers/blocks_controller.rb index c8c82217b..7eda12fd7 100644 --- a/app/controllers/blocks_controller.rb +++ b/app/controllers/blocks_controller.rb @@ -3,7 +3,11 @@ class BlocksController < ApplicationController def create current_user.blocks.create(params[:block]) - redirect_to :back, :notice => "that person sucked anyways..." end -end \ No newline at end of file + + def destroy + current_user.blocks.find(params[:id]).delete + redirect_to :back, :notice => "MAKE UP YOUR MIND." + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 0628ce12f..505f3c8ed 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -20,6 +20,10 @@ class UsersController < ApplicationController end end + def privacy_settings + @blocks = current_user.blocks.includes(:person) + end + def update password_changed = false @user = current_user diff --git a/app/helpers/stream_element_helper.rb b/app/helpers/stream_element_helper.rb index 7b7da572e..c908eba60 100644 --- a/app/helpers/stream_element_helper.rb +++ b/app/helpers/stream_element_helper.rb @@ -2,19 +2,18 @@ module StreamElementHelper def block_user_control(author) if user_signed_in? link_to image_tag('deletelabel.png'), blocks_path(:block => {:person_id => author.id}), - :class => 'block_button stream_element_delete', + :class => 'block_user delete', :confirm => t('are_you_sure'), :title => 'block user', :method => :post - end end def delete_or_hide_button(post) if user_signed_in? && current_user.owns?(post) - link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete') + link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete remove_post", :title => t('delete') else - link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete vis_hide", :title => t('.hide_and_mute') + link_to image_tag('deletelabel.png'), share_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete remove_post vis_hide", :title => t('.hide_and_mute') end end -end \ No newline at end of file +end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 6144989bb..a91515420 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -28,15 +28,14 @@ module StreamHelper end def time_for_scroll(ajax_stream, stream) - if ajax_stream || stream.posts.empty? + if ajax_stream || stream.stream_posts.empty? (Time.now() + 1).to_i else - stream.posts.last.send(stream.order.to_sym).to_i + stream.stream_posts.last.send(stream.order.to_sym).to_i end - end - def time_for_sort post + def time_for_sort(post) if controller.instance_of?(AspectsController) post.send(session[:sort_order].to_sym) else diff --git a/app/models/post.rb b/app/models/post.rb index 0948ffc0b..e161f8fca 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -21,13 +21,13 @@ class Post < ActiveRecord::Base after_create :cache_for_author #scopes - scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message + scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message def self.excluding_blocks(user) - people = user.blocks.map { |x| x.person_id } + people = user.blocks.includes(:person).map{|b| b.person} if people.present? - where("posts.author_id NOT IN (?)", people) + where("posts.author_id NOT IN (?)", people.map { |person| person.id }) else scoped end diff --git a/app/models/user.rb b/app/models/user.rb index 69f888618..8871b2371 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,7 +18,7 @@ class User < ActiveRecord::Base before_validation :strip_and_downcase_username before_validation :set_current_language, :on => :create - + validates :username, :presence => true, :uniqueness => true validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/ validates_length_of :username, :maximum => 32 diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 4aa415ddd..1b1986018 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -19,10 +19,10 @@ #gs-shim{:title => "3. #{t('.stay_updated')}", 'data-content' => t('.stay_updated_explanation')} #main_stream.stream{:data => {:guids => stream.aspect_ids.join(','), :time_for_scroll => time_for_scroll(stream.ajax_stream?, stream)}} - - if !stream.ajax_stream? && stream.stream_posts.length > 0 - = render 'shared/stream', :posts => stream.stream_posts - #pagination - =link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?), :class => 'paginate') +- if !stream.ajax_stream? && stream.stream_posts.length > 0 + = render 'shared/stream', :posts => stream.stream_posts +#pagination + =link_to(t('more'), next_page_path(:ajax_stream => stream.ajax_stream?), :class => 'paginate') - if current_user.contacts.size < 2 = render 'aspects/no_contacts_message' diff --git a/app/views/shared/_settings_nav.haml b/app/views/shared/_settings_nav.haml index fec8cf1a2..fcde8f046 100644 --- a/app/views/shared/_settings_nav.haml +++ b/app/views/shared/_settings_nav.haml @@ -1,5 +1,6 @@ %ul#settings_nav %li= link_to_unless_current t('profile'), edit_profile_path %li= link_to_unless_current t('account'), edit_user_path + %li= link_to_unless_current t('privacy'), privacy_settings_path %li= link_to_unless_current t('_services'), services_path %li= link_to_unless_current t('_applications'), authorizations_path diff --git a/app/views/users/privacy_settings.html.haml b/app/views/users/privacy_settings.html.haml new file mode 100644 index 000000000..683ea4270 --- /dev/null +++ b/app/views/users/privacy_settings.html.haml @@ -0,0 +1,23 @@ +-# Copyright (c) 2010-2011, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +- content_for :page_title do + = t('.title') + +#section_header + %h2 + = t('privacy') + = render 'shared/settings_nav' + +.span-12.prepend-5.last + %h3 + = t('.blocked_users') + + - @blocks.each do |block| + = block.person.name + \- + = link_to t('.unblock'), block_path(block), + :confirm => t('are_you_sure'), + :method => :delete + diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 25c08ff57..2b18216d4 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -9,6 +9,7 @@ en: settings: "Settings" profile: "Profile" account: "Account" + privacy: "Privacy" _services: "Services" _applications: "Applications" _photos: "photos" @@ -605,7 +606,7 @@ en: permalink: "permalink" not_found: "Sorry, we couldn't find that post." - post_visibilites: + share_visibilites: update: post_hidden_and_muted: "%{name}'s post has been hidden, and notifications have been muted." see_it_on_their_profile: "If you want to see updates on this post, visit %{name}'s profile page." @@ -891,6 +892,7 @@ en: simply_visit: "Simply visit" on_your_mobile_device: "on your mobile device to access Diaspora* mobile." works_on_modern: "Works on all modern smartphones" + edit: export_data: "Export Data" photo_export_unavailable: "Photo exporting currently unavailable" @@ -919,6 +921,12 @@ en: show_community_spotlight: "Show Community Spotlight in Stream?" show_getting_started: 'Re-enable Getting Started' getting_started: 'New User Prefrences' + + privacy_settings: + title: "Privacy Settings" + blocked_users: "Blocked Users" + unblock: "Unblock" + destroy: "Your account has been locked. It may take 20 minutes for us to finish closing your account. Thank you for trying Diaspora." getting_started: well_hello_there: "Well, hello there!" diff --git a/config/routes.rb b/config/routes.rb index 4f3299818..1be9714a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -76,10 +76,11 @@ Diaspora::Application.routes.draw do end controller :users do - get 'public/:username' => :public, :as => 'users_public' - match 'getting_started' => :getting_started, :as => 'getting_started' + get 'public/:username' => :public, :as => 'users_public' + match 'getting_started' => :getting_started, :as => 'getting_started' + match 'privacy' => :privacy_settings, :as => 'privacy_settings' get 'getting_started_completed' => :getting_started_completed - get 'confirm_email/:token' => :confirm_email, :as => 'confirm_email' + get 'confirm_email/:token' => :confirm_email, :as => 'confirm_email' end # This is a hack to overide a route created by devise. @@ -109,9 +110,9 @@ Diaspora::Application.routes.draw do resources :contacts, :except => [:update, :create] do get :sharing, :on => :collection end - resources :aspect_memberships, :only => [:destroy, :create, :update] - resources :share_visibilities, :only => [:update] - resources :blocks, :only => :create + resources :aspect_memberships, :only => [:destroy, :create, :update] + resources :share_visibilities, :only => [:update] + resources :blocks, :only => [:create, :destroy] get 'spotlight' => 'community_spotlight#index', :as => 'spotlight' diff --git a/db/schema.rb b/db/schema.rb index 1e4c27f76..4a3992302 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -252,6 +252,7 @@ ActiveRecord::Schema.define(:version => 20111101202137) do add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true create_table "photos", :force => true do |t| + t.integer "tmp_old_id" t.integer "author_id", :null => false t.boolean "public", :default => false, :null => false t.string "diaspora_handle" diff --git a/lib/stream/base.rb b/lib/stream/base.rb index cd8076e34..27b64b8cf 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -47,7 +47,7 @@ class Stream::Base end def stream_posts - self.posts.for_a_stream(max_time, order, user) + self.posts.for_a_stream(max_time, order, self.user) end # @return [ActiveRecord::Association] AR association of people within stream's given aspects diff --git a/public/javascripts/widgets/stream-element.js b/public/javascripts/widgets/stream-element.js index ac431f891..a042da3a7 100644 --- a/public/javascripts/widgets/stream-element.js +++ b/public/javascripts/widgets/stream-element.js @@ -13,7 +13,8 @@ timeAgo: self.instantiate("TimeAgo", element.find(".timeago a abbr.timeago")), content: element.find(".content .collapsible"), - deletePostLink: element.find("a.stream_element_delete"), + blockUserLink: element.find(".block_user"), + deletePostLink: element.find(".remove_post"), focusCommentLink: element.find("a.focus_comment_textarea"), hidePostLoader: element.find("img.hide_loader"), hidePostUndo: element.find("a.stream_element_hide_undo"), @@ -22,8 +23,11 @@ }); // twipsy tooltips - self.deletePostLink.twipsy(); - self.postScope.twipsy(); + $([ + self.blockUserLink, + self.deletePostLink, + self.postScope + ]).map(function() { this.twipsy(); }); // collapse long posts self.content.expander({ @@ -40,8 +44,10 @@ self.deletePostLink.click(function(evt) { evt.preventDefault(); - self.deletePostLink.toggleClass("hidden"); - self.hidePostLoader.toggleClass("hidden"); + $([ + self.deletePostLink, + self.hidePostLoader + ]).toggleClass("hidden"); }); self.focusCommentLink.click(function(evt) { diff --git a/spec/controllers/blocks_controller_spec.rb b/spec/controllers/blocks_controller_spec.rb index 445cfb482..fb9567c98 100644 --- a/spec/controllers/blocks_controller_spec.rb +++ b/spec/controllers/blocks_controller_spec.rb @@ -1,18 +1,18 @@ require 'spec_helper' describe BlocksController do - describe "#create" do - before do - sign_in alice - end + before do + sign_in alice + end - it "should create a block" do + describe "#create" do + it "creates a block" do expect { post :create, :block => { :person_id => 2 } }.should change { alice.blocks.count }.by(1) end - it "should redirect to back" do + it "redirects back" do post :create, :block => { :person_id => 2 } response.should be_redirect @@ -24,4 +24,21 @@ describe BlocksController do flash.should_not be_empty end end -end \ No newline at end of file + + describe "#destroy" do + before do + @block = alice.blocks.create(:person => eve.person) + end + + it "redirects back" do + delete :destroy, :id => @block.id + response.should be_redirect + end + + it "removes a block" do + expect { + delete :destroy, :id => @block.id + }.should change { alice.blocks.count }.by(-1) + end + end +end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 4f3b48483..f20ef2057 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -159,6 +159,13 @@ describe UsersController do end end + describe '#privacy_settings' do + it "returns a 200" do + get 'privacy_settings' + response.status.should == 200 + end + end + describe '#edit' do it "returns a 200" do get 'edit', :id => @user.id @@ -220,15 +227,13 @@ describe UsersController do describe 'getting_started' do it 'does not fail miserably' do - get :getting_started - response.should be_success - + get :getting_started + response.should be_success end it 'does not fail miserably on mobile' do - get :getting_started, :format => :mobile - response.should be_success - + get :getting_started, :format => :mobile + response.should be_success end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6902db86b..8ac6489b8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -158,7 +158,7 @@ describe User do alice.username = "hexagooooooooooooooooooooooooooon" alice.should_not be_valid end - + it "cannot be one of the blacklist names" do ['hostmaster', 'postmaster', 'root', 'webmaster'].each do |username| alice.username = username @@ -382,9 +382,7 @@ describe User do end end - describe '.find_or_create_by_invitation' do - - end + describe '.find_or_create_by_invitation' describe '.create_from_invitation!' do before do @@ -400,7 +398,6 @@ describe User do it 'sets the email if the service is email' do @user.email.should == @inv.identifier end - end describe 'update_user_preferences' do @@ -551,7 +548,6 @@ describe User do alice.remove_all_traces end - it 'should remove mentions' do alice.should_receive(:remove_mentions) alice.remove_all_traces