diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42abc665c..e581613f3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,16 +10,6 @@ class ApplicationController < ActionController::Base before_filter :count_requests before_filter :set_invites - layout :layout_by_resource - - def layout_by_resource - if devise_controller? - "session_wall" - else - "application" - end - end - def set_friends_and_status if current_user if params[:aspect] == nil || params[:aspect] == 'all' diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 549ee6096..6887e4bee 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,6 +11,10 @@ class AspectsController < ApplicationController def index @posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @aspect = :all + + if current_user.getting_started == true + redirect_to getting_started_path + end end def create @@ -43,7 +47,6 @@ class AspectsController < ApplicationController def show @aspect = current_user.aspect_by_id params[:id] - @friends_not_in_aspect = current_user.friends_not_in_aspect(@aspect) unless @aspect render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @@ -86,7 +89,11 @@ class AspectsController < ApplicationController flash[:error] = I18n.t 'aspects.add_to_aspect.failure' end - redirect_to aspect_path(params[:aspect_id]) + if params[:manage] + redirect_to aspects_manage_path + else + redirect_to aspect_path(params[:aspect_id]) + end end def remove_from_aspect diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 498ca8157..f76f1c6e6 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -41,6 +41,12 @@ class PeopleController < ApplicationController end def update + # convert date selector into proper timestamp + birthday = params[:date] + if birthday + params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}") + end + prep_image_url(params[:person]) if current_user.update_profile params[:person][:profile] @@ -49,7 +55,11 @@ class PeopleController < ApplicationController flash[:error] = "Failed to update profile" end - redirect_to edit_person_path + if params[:getting_started] + redirect_to getting_started_path(:step => params[:getting_started].to_i+1) + else + redirect_to edit_person_path + end end private diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 4a10821aa..ffc845c93 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -44,7 +44,12 @@ class RequestsController < ApplicationController else raise e end - respond_with :location => aspect + + if params[:getting_started] + redirect_to getting_started_path(:step=>params[:getting_started]) + else + respond_with :location => aspect + end return end @@ -61,16 +66,29 @@ class RequestsController < ApplicationController else raise e end - respond_with :location => aspect + + if params[:getting_started] + redirect_to getting_started_path(:step=>params[:getting_started]) + else + respond_with :location => aspect + end return end if @request flash[:notice] = I18n.t 'requests.create.success',:destination_url => @request.destination_url - respond_with :location => aspect + if params[:getting_started] + redirect_to getting_started_path(:step=>params[:getting_started]) + else + respond_with :location => aspect + end else flash[:error] = I18n.t 'requests.create.horribly_wrong' - respond_with :location => aspect + if params[:getting_started] + redirect_to getting_started_path(:step=>params[:getting_started]) + else + respond_with :location => aspect + end end end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 7c5da42a7..d5fd50c83 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -31,7 +31,6 @@ class ServicesController < ApplicationController :uid => auth['uid']) end - flash[:notice] = "Authentication successful." redirect_to services_url end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c5121784a..79d33940a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -20,18 +20,26 @@ class UsersController < ApplicationController def update @user = current_user - params[:user].delete(:password) if params[:user][:password].blank? - params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? - if params[:user][:password] && params[:user][:password_confirmation] - if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation]) - flash[:notice] = "Password Changed" - else - flash[:error] = "Password Change Failed" + if params[:user][:getting_started] + boolean = params[:user][:getting_started] == "true" + @user.update_attributes( :getting_started => boolean ) + redirect_to root_path + + else + params[:user].delete(:password) if params[:user][:password].blank? + params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? + + if params[:user][:password] && params[:user][:password_confirmation] + if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation]) + flash[:notice] = "Password Changed" + else + flash[:error] = "Password Change Failed" + end end - end - redirect_to edit_user_path(@user) + redirect_to edit_user_path(@user) + end end def destroy @@ -55,6 +63,19 @@ class UsersController < ApplicationController end end + def getting_started + @aspect = :getting_started + @user = current_user + @person = @user.person + @profile = @user.profile + @photos = @user.visible_posts(:person_id => current_user.person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' + @services = @user.services + + @step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1 + @step ||= 1 + render "users/getting_started" + end + def export exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) send_data exporter.execute(current_user), :filename => "#{current_user.username}_diaspora_data.xml", :type => :xml diff --git a/app/models/comment.rb b/app/models/comment.rb index 540b44f2e..e6686efce 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,6 +2,14 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +class HandleValidator < ActiveModel::Validator + def validate(document) + unless document.diaspora_handle == document.person.diaspora_handle + document.errors[:base] << "Diaspora handle and person handle must match" + end + end +end + class Comment include MongoMapper::Document include ROXML @@ -10,18 +18,21 @@ class Comment include Diaspora::Socketable xml_accessor :text - xml_accessor :person, :as => Person + xml_reader :diaspora_handle xml_accessor :post_id xml_accessor :_id key :text, String key :post_id, ObjectId key :person_id, ObjectId + key :diaspora_handle, String belongs_to :post, :class_name => "Post" belongs_to :person, :class_name => "Person" - validates_presence_of :text + validates_presence_of :text, :diaspora_handle + validates_with HandleValidator + timestamps! diff --git a/app/models/person.rb b/app/models/person.rb index 58e637557..c79a62955 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -60,7 +60,11 @@ class Person end def real_name - "#{profile.first_name.to_s} #{profile.last_name.to_s}" + if profile.first_name.nil? || profile.first_name.empty? + self.diaspora_handle + else + "#{profile.first_name.to_s} #{profile.last_name.to_s}" + end end def owns?(post) diff --git a/app/models/profile.rb b/app/models/profile.rb index baab495d7..8848cd823 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -9,15 +9,20 @@ class Profile include ROXML xml_reader :person_id - xml_accessor :first_name - xml_accessor :last_name - xml_accessor :image_url + xml_reader :first_name + xml_reader :last_name + xml_reader :image_url + xml_reader :birthday + xml_reader :gender + xml_reader :bio key :first_name, String key :last_name, String key :image_url, String + key :birthday, Date + key :gender, String + key :bio, String - validates_presence_of :first_name, :last_name after_validation :strip_names before_save :strip_names diff --git a/app/models/user.rb b/app/models/user.rb index 82d103034..071abfcb0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,6 +40,8 @@ class User key :invite_messages, Hash + key :getting_started, Boolean, :default => true + before_validation :strip_username, :on => :create validates_presence_of :username validates_uniqueness_of :username, :case_sensitive => false @@ -87,10 +89,6 @@ class User self.person.send(method, *args) end - def real_name - "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" - end - ######### Aspects ###################### def aspect(opts = {}) aspect = Aspect.new(opts) @@ -275,7 +273,7 @@ class User def build_comment(text, options = {}) raise "must comment on something!" unless options[:on] - comment = Comment.new(:person_id => self.person.id, :text => text, :post => options[:on]) + comment = Comment.new(:person_id => self.person.id, :diaspora_handle => self.person.diaspora_handle, :text => text, :post => options[:on]) comment.creator_signature = comment.sign_with_key(encryption_key) if comment.save comment @@ -409,12 +407,15 @@ class User ###Helpers############ def self.build(opts = {}) + opts[:person] ||= {} + opts[:person][:profile] ||= Profile.new opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" opts[:person][:url] = APP_CONFIG[:pod_url] opts[:serialized_private_key] = generate_key opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key + u = User.new(opts) u end diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index a49030d34..77ca7750d 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -22,6 +22,10 @@ - else - for request in @remote_requests %li.person.request{:data=>{:guid=>request.id, :person_id=>request.person.id}} + .delete + .x + X + .circle = person_image_tag(request.person) %h3 Remove from Aspect @@ -63,6 +67,6 @@ .fancybox_content %div{:id => "add_request_pane_#{aspect.id}"} - = render "requests/new_request", :aspect => aspect + = render "requests/new_request", :aspect => aspect, :manage => true diff --git a/app/views/devise/passwords/new.html.haml b/app/views/devise/passwords/new.html.haml index 1d877b70e..d9431bbb8 100644 --- a/app/views/devise/passwords/new.html.haml +++ b/app/views/devise/passwords/new.html.haml @@ -1,9 +1,12 @@ -%h2 Forgot your password? -= form_for(resource, :as => resource_name, :url => password_path(resource_name)) do |f| - = devise_error_messages! - %p - = f.label :email - = f.text_field :email - %p - = f.submit "Send me reset password instructions" -= render :partial => "devise/shared/links" +.span-12.prepend-6.last + .floating + %h3 + Forgot your password? + = form_for(resource, :as => resource_name, :url => password_path(resource_name)) do |f| + = devise_error_messages! + %p + = f.label :email + = f.text_field :email + %p + = f.submit "Send me reset password instructions" + = render :partial => "devise/shared/links" diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 5803415b4..852a8afd5 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -1,26 +1,33 @@ -%h1 - This is a technology preview, do not provide any private information. -%h3 - your account may be deleted until we move into a more stable development period. -%h3 - USE AT YOUR OWN RISK!! -= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| - #user - %p.username - = f.label :username - = f.text_field :username - %p.user_network - ="@#{APP_CONFIG[:terse_pod_url]}" +.span-10.append-1.last + .floating + %h3 Login + = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| + #user + %p.username + = f.label :username + = f.text_field :username + %p.user_network + ="@#{APP_CONFIG[:terse_pod_url]}" + %p + = f.label :password + = f.password_field :password + /%p + /- if devise_mapping.rememberable? + / = f.check_box :remember_me + / = f.label :remember_me + = f.submit "Sign in" + %p - = f.label :password - = f.password_field :password - /%p - /- if devise_mapping.rememberable? - / = f.check_box :remember_me - / = f.label :remember_me - = f.submit "Sign in" - = link_to "Have a problem? Find an answer here", 'http://diaspora.shapado.com/' - %p -= render :partial => "devise/shared/links" + = render :partial => "devise/shared/links" + %p + = link_to "Have a problem? Find an answer here", 'http://diaspora.shapado.com/' + +.span-13.last + %h1 + This is a technology preview, do not provide any private information. + %h3 + your account may be deleted until we move into a more stable development period. + %h3 + USE AT YOUR OWN RISK!! diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7f6cf94cf..c7deeda8e 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -31,7 +31,8 @@ = javascript_include_tag 'view', 'image_picker', 'stream' - = render 'js/websocket_js' + - if current_user + = render 'js/websocket_js' = csrf_meta_tag = yield(:head) @@ -43,24 +44,25 @@ %header .container{:style => "position:relative;"} #diaspora_text{:href => root_path} - = link_to "DIASPORA*", root_path + = link_to "DIASPORA*", (current_user ? root_path : new_user_session_path) %span.sub_text PREVIEW - #global_search - = form_tag(people_path, :method => 'get') do - = text_field_tag 'q', nil, :placeholder => "Search", :type => 'search', :results => 5 + - if current_user + #global_search + = form_tag(people_path, :method => 'get') do + = text_field_tag 'q', nil, :placeholder => "Search", :type => 'search', :results => 5 - %ul#user_menu - .avatar - = owner_image_tag - = link_to current_user.real_name, '#' - %li= link_to "view profile", current_user.person - %li= link_to "edit profile", edit_person_path(current_user.person) - %li= link_to "account settings", edit_user_path(current_user) - %li= link_to t('.logout.'), destroy_user_session_path + %ul#user_menu + .avatar + = owner_image_tag + = link_to current_user.real_name, '#' + %li= link_to "view profile", current_user.person + %li= link_to "edit profile", edit_person_path(current_user.person) + %li= link_to "account settings", edit_user_path(current_user) + %li= link_to t('.logout.'), destroy_user_session_path - = render "shared/aspect_nav" + = render "shared/aspect_nav" .container .span-24.last @@ -68,3 +70,4 @@ .span-24.last = render "posts/debug" + diff --git a/app/views/layouts/session_wall.html.haml b/app/views/layouts/session_wall.html.haml deleted file mode 100644 index bc15063d6..000000000 --- a/app/views/layouts/session_wall.html.haml +++ /dev/null @@ -1,53 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -!!! -%html - %head - %title - DIASPORA | login - %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } - - = stylesheet_link_tag "sessions" - /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" - = javascript_include_tag 'jquery142' - = javascript_include_tag 'jquery.infieldlabel' - - :javascript - $(document).ready(function(){ - $("#user_username").focus(); - $("label").inFieldLabels(); - }); - - = csrf_meta_tag - = yield(:head) - - %body - - :plain - - - - flash.each do |name, msg| - = content_tag :div, msg, :id => "flash_#{name}" - %div#huge_text - DIASPORA* - = yield - - /= link_to "signup", "/signup" diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index 8db35bb3e..29e10d757 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -12,56 +12,58 @@ %li=link_to 'Services', services_path .span-19.prepend-5.last - %h2 Profile = form_for @person do |person| + %h3 + Your Profile + .description + This info will be available to whomever you connect with on Diaspora. + = person.error_messages - = person.fields_for :profile do |p| + = person.fields_for :profile do |profile| + %h4 + Your name + = profile.text_field :first_name, :value => @profile.first_name, :placeholder => "First name" + = profile.text_field :last_name, :value => @profile.last_name, :placeholder => "Last name" - %h3="#{t('.picture')}" - %div#image_picker - = p.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' + %h4 + Your gender + %br + = select_tag 'person[profile][gender]', options_for_select(["","Female","Male"], @person.profile.gender) - - unless @photos.nil? || @photos.empty? - - for photo in @photos - - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) - %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} - = check_box_tag 'checked_photo', true, true - = link_to image_tag(photo.url(:thumb_medium)), "#" - - else - %div.small_photo{:id => photo.url(:thumb_medium)} - = check_box_tag 'checked_photo' - = link_to image_tag(photo.url(:thumb_medium)), "#" + %h4 + Your birthday + %br + = select_date @person.profile.birthday, :order => [:month, :day, :year], :start_year => 1930, :end_year => 2000 - - else - =t('.you_dont_have_any_photos') - = link_to t('.albums'), albums_path(:aspect => 'all') - =t('.page_to_upload_some') + %h4 + Your bio + = profile.text_area :bio, :value => @profile.bio, :rows => 5, :placeholder => "Fill me out" - =will_paginate @photos + %h4 + Your photo + %div#image_picker + = profile.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' - %br + - unless @photos.nil? || @photos.empty? + - for photo in @photos + - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) + %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} + = check_box_tag 'checked_photo', true, true + = link_to image_tag(photo.url(:thumb_medium)), "#" + - else + %div.small_photo{:id => photo.url(:thumb_medium)} + = check_box_tag 'checked_photo' + = link_to image_tag(photo.url(:thumb_medium)), "#" - %h3="#{t('.info')}" + - else + =t('.you_dont_have_any_photos') + = link_to t('.albums'), albums_path(:aspect => 'all') + =t('.page_to_upload_some') - %p - %b - ="#{t('.diaspora_username')}:" - = @person.diaspora_handle - - %p - = p.label :first_name - = p.text_field :first_name, :value => @profile.first_name - %p - = p.label :last_name - = p.text_field :last_name, :value => @profile.last_name + =will_paginate @photos .submit_block = link_to t('.cancel'), edit_user_path(current_user) = t('.or') = person.submit t('.update_profile') - - #content_bottom - .back - = link_to "⇧ #{t('.home')}", root_path - diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index cea31ff78..ea0be2b75 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -1,50 +1,42 @@ -= image_tag "http://needcoffee.cachefly.net/needcoffee/uploads/2009/02/predator-arnold-schwarzenegger.jpg" - -= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| - %p - = f.label :username - = f.text_field :username - %p - = f.label :email - = f.text_field :email - %p - = f.label :password - = f.password_field :password - %p - = f.label :password_confirmation - = f.password_field :password_confirmation - - = f.fields_for :person do |p| - = p.fields_for :profile do |pr| +.span-12.prepend-6.last + .floating + %h3 + Sign up for Diaspora + = image_tag "http://needcoffee.cachefly.net/needcoffee/uploads/2009/02/predator-arnold-schwarzenegger.jpg" + = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %p - = pr.label :first_name - = pr.text_field :first_name + = f.label :username + = f.text_field :username %p - = pr.label :last_name - = pr.text_field :last_name - = f.submit t('.sign_up') -= render :partial => "devise/shared/links" + = f.label :email + = f.text_field :email + %p + = f.label :password + = f.password_field :password + %p + = f.label :password_confirmation + = f.password_field :password_confirmation + + = f.submit t('.sign_up') -%br -%br + .floating + %h3 + Upload an existing Diaspora account -%h2 or, upload yourself + = form_tag '/users/import', :multipart => true do + %p + = label_tag 'user[email]' + = text_field_tag 'user[email]' + %p + = label_tag 'user[password]' + = password_field_tag 'user[password]' + %p + = label_tag 'user[password_confirmation]' + = password_field_tag 'user[password_confirmation]' -= form_tag '/users/import', :multipart => true do - - %p - = label_tag 'user[email]' - = text_field_tag 'user[email]' - %p - = label_tag 'user[password]' - = password_field_tag 'user[password]' - %p - = label_tag 'user[password_confirmation]' - = password_field_tag 'user[password_confirmation]' - - %label Select File - = file_field 'upload', 'file' - = submit_tag "Upload" + %label Select File + = file_field 'upload', 'file' + = submit_tag "Upload" diff --git a/app/views/requests/_new_request.haml b/app/views/requests/_new_request.haml index c67bc61b9..0ec66d163 100644 --- a/app/views/requests/_new_request.haml +++ b/app/views/requests/_new_request.haml @@ -8,12 +8,7 @@ =t('.add_a_new_friend_to') %i= aspect.name - - if @friends_not_in_aspect - = render('shared/add_friend_dropdown', :aspect => @aspect, :friends => @friends_not_in_aspect) - - - - + = render 'shared/add_friend_dropdown', :aspect => aspect, :friends => current_user.friends_not_in_aspect(aspect), :manage => defined?(manage) = form_for Request.new do |fr_request| = fr_request.error_messages @@ -26,5 +21,11 @@ = fr_request.label :destination_url, t(".friends_username") = fr_request.text_field :destination_url = fr_request.hidden_field :aspect_id, :value => aspect.id + + - if defined?(getting_started) + = hidden_field_tag :getting_started, getting_started + - if defined?(manage) + = hidden_field_tag :manage, true + = fr_request.submit diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index 8d00f8eb3..ee298eb34 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -14,7 +14,7 @@ %h2 Services - %ul#stream + %ul - for service in @services %h3 %b= service.provider diff --git a/app/views/shared/_add_friend_dropdown.html.haml b/app/views/shared/_add_friend_dropdown.html.haml index ee39fc6ad..062f534b8 100644 --- a/app/views/shared/_add_friend_dropdown.html.haml +++ b/app/views/shared/_add_friend_dropdown.html.haml @@ -2,4 +2,6 @@ = form_tag '/aspects/add_to_aspect', :id => 'add_to_aspect' do = select_tag :friend_id, options_from_collection_for_select(friends, "id", "real_name"), :include_blank => true = hidden_field_tag :aspect_id, aspect.id + - if defined?(manage) && manage + = hidden_field_tag :manage, true = submit_tag "add to #{aspect.name}" diff --git a/app/views/shared/_aspect_friends.haml b/app/views/shared/_aspect_friends.haml index f4b2f06f7..c7137b025 100644 --- a/app/views/shared/_aspect_friends.haml +++ b/app/views/shared/_aspect_friends.haml @@ -16,7 +16,7 @@ = person_image_link(friend) -unless (@aspect == :all) - = link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :id => 'add_request_button' + = link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :class => 'add_request_button' .fancybox_content #add_request_pane diff --git a/app/views/users/getting_started.html.haml b/app/views/users/getting_started.html.haml new file mode 100644 index 000000000..5edb3e67a --- /dev/null +++ b/app/views/users/getting_started.html.haml @@ -0,0 +1,51 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +- content_for :head do + :javascript + $("#new_aspect").live("ajax:success", function(data,stat,xhr){ + window.location.reload(); + }); + + $(".aspects li").find(".delete").live("click", function(){ + var aspectElement = $(this).parent("li"); + aspectElement.fadeOut(300, function(){aspectElement.remove();}); + }); + + - if current_user.getting_started == true + :javascript + $("#getting_started_skip").live("click", function(evt){ + evt.preventDefault(); + $.ajax({ + type: "PUT", + url: "/users/#{current_user.id}", + data: {"user":{"getting_started":'false'}}, + success: function() { window.location = "#{root_path}"} + }) + }); + +.span-8.append-1.last + %h1{:style => "text-align:right;"} + = "Welcome to Diaspora!" + .description + Do the stuff below to further complete some things. + + %h3{:style => "text-align:right;"} + = link_to "Edit your profile", getting_started_path(:step => 1) + %br + = link_to "Define your aspects", getting_started_path(:step => 2) + %br + = link_to "Connect your services", getting_started_path(:step => 3) + %br + +.span-15.last + .floating{:style=>"min-height:500px;"} + = render "users/getting_started/step_#{@step}", :current_user => current_user + + - if @step > 1 + = link_to "Back", getting_started_path(:step => @step-1), :class => "button", :id => "previous_step" + +.bottom_notification + = link_to "skip getting started →", '#', :id => "getting_started_skip" diff --git a/app/views/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml new file mode 100644 index 000000000..7778a39f8 --- /dev/null +++ b/app/views/users/getting_started/_step_1.html.haml @@ -0,0 +1,61 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + += form_for @person do |person| + %h3 + Your Profile + .description + This info will be available to whomever you connect with on Diaspora. + + = person.error_messages + + = person.fields_for :profile do |profile| + %h4 + Your name + = profile.text_field :first_name, :value => @profile.first_name, :placeholder => "First name" + = profile.text_field :last_name, :value => @profile.last_name, :placeholder => "Last name" + + %h4 + Your gender + %br + = select_tag 'person[profile][gender]', options_for_select(["","Female","Male"], @person.profile.gender) + + %h4 + Your birthday + %br + = select_date @person.profile.birthday, :order => [:month, :day, :year], :start_year => 1930, :end_year => 2000 + + %h4 + Your bio + = profile.text_area :bio, :value => @profile.bio, :rows => 5, :placeholder => "Fill me out" + + %h4 + Your photo + %div#image_picker + = profile.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' + + - unless @photos.nil? || @photos.empty? + - for photo in @photos + - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) + %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} + = check_box_tag 'checked_photo', true, true + = link_to image_tag(photo.url(:thumb_medium)), "#" + - else + %div.small_photo{:id => photo.url(:thumb_medium)} + = check_box_tag 'checked_photo' + = link_to image_tag(photo.url(:thumb_medium)), "#" + + - else + =t('.you_dont_have_any_photos') + = link_to t('.albums'), albums_path(:aspect => 'all') + =t('.page_to_upload_some') + + =will_paginate @photos + + = hidden_field_tag :getting_started, @step + + .submit_block + = person.submit "Save and continue →" + diff --git a/app/views/users/getting_started/_step_2.html.haml b/app/views/users/getting_started/_step_2.html.haml new file mode 100644 index 000000000..bed14bd33 --- /dev/null +++ b/app/views/users/getting_started/_step_2.html.haml @@ -0,0 +1,38 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +%h3 + Your aspects + .description + Diaspora aspects are mappings of your real-life aspects. You can manage these later by clicking the manage tab on the top right. Your aspects are unique to you, and not visible by others. + +%h4 + Aspect name + - form_for Aspect.new, :remote => true, :format => :json do |aspect| + = aspect.text_field :name, :style => "display:inline;" + = aspect.submit "Add" + +%ul.aspects + - for aspect in @aspects + %li{:style=>"position:relative;"} + = aspect + .friend_pictures.horizontal + - for friend in aspect.person_objects + = person_image_link(friend) + + = link_to (image_tag('add_friend_button.png', :title => "add to #{aspect}")), "#add_request_pane", :class => 'add_request_button' + + .fancybox_content + #add_request_pane + = render "requests/new_request", :aspect => aspect, :getting_started => 2 + + = link_to "x", aspect_path(aspect), :confirm => "are you sure?", :method => :delete, :remote => true, :class => "delete right" + +%br +%br + +.submit_block + = link_to "Save and continue →", getting_started_path(:step => 3), :class => "button" + diff --git a/app/views/users/getting_started/_step_3.html.haml b/app/views/users/getting_started/_step_3.html.haml new file mode 100644 index 000000000..18789da19 --- /dev/null +++ b/app/views/users/getting_started/_step_3.html.haml @@ -0,0 +1,23 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +%h3 + Your services + .description + Connect your existing social networks to your Diaspora account. You will be able to post publically through your Everyone tab when you select "public." +%ul#stream + - for service in @services + %h3 + %b= service.provider + logged in as + %b= service.nickname + = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete + +%h4= link_to "Connect to twitter", "/auth/twitter" if SERVICES['twitter']['consumer_key']!= "" +%h4= link_to "Connect to facebook", "/auth/facebook" if SERVICES['facebook']['app_id'] !="" + +.submit_block + = link_to "Save and continue →", getting_started_path(:step => 4), :class => "button" + diff --git a/app/views/users/getting_started/_step_4.html.haml b/app/views/users/getting_started/_step_4.html.haml new file mode 100644 index 000000000..b5ca7b274 --- /dev/null +++ b/app/views/users/getting_started/_step_4.html.haml @@ -0,0 +1,44 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +- if current_user.getting_started == true + :javascript + $.ajax({ + type: "PUT", + url: "/users/#{current_user.id}", + data: {"user":{"getting_started":'false'}} + }) + +%h1 + = "You're all set up, #{current_user.person.profile.first_name}!" + .description + You're now ready to start sharing with + %ul.inline_aspect_listing + - for aspect in @aspects + %li= aspect + +%br +%br + +%h3 + = link_to "Continue on to your everyone page, an overview of all of your aspects.", root_path + +%br +%br +%br + +%p + You can change your profile any time by clicking + %b edit profile + in your user menu (top right). +%p + You can connect/disconnect your services any time by clicking + %b edit account + in your user menu (top right). +%p + You can manage your aspects any time by clicking the + %b manage + tab. Your contacts can also be added while on a particular aspect page, as well. + diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 33c3d62bd..7071d13d4 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -121,6 +121,12 @@ en: edit: editing_profile: "Editing profile" destroy: "Account successfully closed." + getting_started: + 'step_1': + albums: "Albums" + you_dont_have_any_photos: "You don't have any photos! Go to the" + page_to_upload_some: "page to upload some." + or: "or" comments: comment: ago: "ago" diff --git a/config/routes.rb b/config/routes.rb index e46a65b0a..c72ed855f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,11 +17,12 @@ Diaspora::Application.routes.draw do :password => "devise/passwords", :invitations => "invitations"} # added public route to user - match 'public/:username', :to => 'users#public' - match 'users/export', :to => 'users#export' - match 'users/import', :to => 'users#import' - match 'users/export_photos', :to => 'users#export_photos' - resources :users, :except => [:create, :new, :show] + match 'public/:username', :to => 'users#public' + match 'getting_started', :to => 'users#getting_started', :as => 'getting_started' + match 'users/export', :to => 'users#export' + match 'users/import', :to => 'users#import' + match 'users/export_photos', :to => 'users#export_photos' + resources :users, :except => [:create, :new, :show] match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect' diff --git a/lib/diaspora/user/receiving.rb b/lib/diaspora/user/receiving.rb index bcf8897f1..19732552f 100644 --- a/lib/diaspora/user/receiving.rb +++ b/lib/diaspora/user/receiving.rb @@ -44,6 +44,7 @@ module Diaspora elsif object.is_a? Profile sender = Diaspora::Parser.owner_id_from_xml xml elsif object.is_a?(Comment) + object.person = Person.by_webfinger(object.diaspora_handle) sender = (owns?(object.post))? object.person : object.post.person else sender = object.person @@ -82,14 +83,13 @@ module Diaspora end def receive_comment comment, xml - comment.person = Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if comment.person.nil? raise "In receive for #{self.real_name}, signature was not valid on: #{comment.inspect}" unless comment.post.person == self.person || comment.verify_post_creator_signature self.visible_people = self.visible_people | [comment.person] self.save Rails.logger.debug("The person parsed from comment xml is #{comment.person.inspect}") unless comment.person.nil? comment.person.save Rails.logger.debug("From: #{comment.person.inspect}") if comment.person - comment.save + comment.save! unless owns?(comment) dispatch_comment comment end diff --git a/public/404.html b/public/404.html index 13597a69a..02624c38a 100644 --- a/public/404.html +++ b/public/404.html @@ -18,9 +18,7 @@ -
-

The page you were looking for doesn't exist.

-

You should try going outside.

-
+ + diff --git a/public/images/404.png b/public/images/404.png new file mode 100644 index 000000000..f7a872532 Binary files /dev/null and b/public/images/404.png differ diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 26b3fea55..730358083 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -27,7 +27,7 @@ $(document).ready(function(){ //buttons////// $(".add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false }); - $("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); + $(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".remove_person_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); @@ -73,10 +73,14 @@ $(document).ready(function(){ $(".reshare_box").hide(); }; }); + + //$("#slider").easySlider({speed:400}); + $("img", "#left_pane").tipsy({live:true}); $(".add_aspect_button", "#aspect_nav").tipsy({gravity:'w'}); $(".person img", ".dropzone").tipsy({live:true}); + $(".avatar", ".aspects").tipsy({live:true}); });//end document ready @@ -123,8 +127,8 @@ $(".make_profile_photo").live("click", function(){ $.ajax({ type: "PUT", - url: '/users/'+user_id, - data: {"user":{"profile":{ "image_url": photo_url }}}, + url: '/people/'+user_id, + data: {"person":{"profile":{ "image_url": photo_url }}}, success: function(){ $("img[data-person_id='"+ person_id +"']").each( function() { $(this).attr('src', photo_url); @@ -133,3 +137,10 @@ $(".make_profile_photo").live("click", function(){ }); }); +$(".getting_started_box").live("click",function(evt){ + $(this).animate({ + left: parseInt($(this).css('left'),30) == 0 ? + -$(this).outerWidth() : + 0 + },function(evt){ $(this).css('left', '1000px')}); +}); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 3c468e659..e28eaaa4a 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -397,10 +397,11 @@ li.message form :position relative - :font - :size 120% - :margin 1em - :left 0em + input, + textarea, + label + :font + :size 14px #user_name :margin @@ -450,7 +451,6 @@ form > li :background none :border none - #stream ul.comments :display none @@ -461,6 +461,10 @@ form :margin :right 10px + form + :margin + :right 12px + input.comment_submit :display none :margin @@ -599,10 +603,7 @@ li.message .from .right h5 :color #ccc - -input[type='text'], -input[type='password'], -input[type="search"], +input:not([type='submit']), textarea :font :family 'Arial', 'Helvetica', sans-serif @@ -617,12 +618,12 @@ textarea :-webkit-border-radius 5px :-moz-border-radius 5px +input[type='checkbox'] + :width auto .submit_block :text :align right - :font - :size 12px form p :position relative @@ -647,7 +648,6 @@ label :width 100% :margin :bottom 10px - :top -14px :border :bottom 2px #777 solid @@ -686,20 +686,21 @@ label :bottom -2px input[type='submit'] :position absolute - :right -13px + :right 0 :top 5px :width 75px + input + :display inline .public_toggle - :width 300px - :margin - :left -3px :font :size smaller :style italic :display inline #image_picker + :margin + :top 5px .small_photo :height 100px :position relative @@ -1087,16 +1088,6 @@ ul#settings_nav :width 30px :height 30px -.friend_pictures.horizontal - :display inline - :margin - :left 20px - - img - :width 30px - :height 30px - :margin-right -4px - #thumbnails :line-height 14px @@ -1143,6 +1134,21 @@ ul#settings_nav :size 80px :display inline-block +h1,h2,h3,h4 + .description + :font + :size 70% + :weight 100 + :color #ccc + :margin + :top 0.5em + +h2,h3,h4 + .description + :font + :size 80% + :weight 200 + input[type="search"] :-webkit-appearance textfield @@ -1243,3 +1249,119 @@ ul#breadcrumb &:last-child &:after :content '' + +ul.aspects + :margin 0 + :padding 0 + :list-style none + :color #999 + :font + :size 24px + + > li + :padding 12px 0 + :border + :bottom 1px solid #eee + + &:hover + :background + :color #fafafa + + + .right + :top 12px + :right 12px + + .delete + :background + :color #eee + :width 20px + :height 20px + + :-webkit-border-radius 10px + + :line-height 16px + :text-indent 6px + :font-size 16px + +.inline + :display inline + +.floating + :position relative + :padding 12px + :background + :color rgb(255,255,255) + :-webkit-box-shadow 0 1px 3px #333 + :border-radius 2px + :border + :bottom 1px solid #ccc + :top 1px solid #fff + + .submit_block + :position absolute + :bottom 13px + :right 12px + + form + :display relative + +.bottom_notification + :position fixed + :bottom 0 + :left 0 + :width 100% + :background + :color rgba(16,127,201,0.8) + + :text + :align center + :font + :size 14px + :weight bold + :color #fff + :padding 12px + :bottom 10px + + a + :color #fafafa + :background + :color rgb(16,127,201) + :padding 8px + :border-radius 10px + + &:hover + :background + :color #22AAE0 + + +.inline_aspect_listing + :margin 0 + :padding 0 + :list + :style none + :display inline + > li + :display inline + :font + :weight normal + + &:after + :content ", " + + &:last-child + &:before + :content "and " + &:after + :content "." + +#previous_step + :position absolute + :left 12px + :bottom 12px + +#user_photo_uploader + .avatar + :border-radius 5px + :height 100px + :width 100px diff --git a/public/stylesheets/sass/ui.sass b/public/stylesheets/sass/ui.sass index e064b3fcf..ff4b3c099 100644 --- a/public/stylesheets/sass/ui.sass +++ b/public/stylesheets/sass/ui.sass @@ -10,7 +10,7 @@ :display inline - :padding 4px + :padding 5px :font-size 12px :line-height 100% @@ -27,9 +27,9 @@ :left 1px solid #ccc :right 1px solid #ccc - :border-radius 3px - :-moz-border-radius 3px - :-webkit-border-radius 3px + :border-radius 8px + :-moz-border-radius 8px + :-webkit-border-radius 8px :cursor pointer diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 3c9bbde07..942e8f5c9 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -14,11 +14,7 @@ describe RegistrationsController do @valid_params = {"user" => {"username" => "jdoe", "email" => "jdoe@example.com", "password" => "password", - "password_confirmation" => "password", - "person" => { - "profile" => { - "first_name" => "John", - "last_name" => "Doe"}}}} + "password_confirmation" => "password"}} end describe "#create" do @@ -41,7 +37,7 @@ describe RegistrationsController do end context "with invalid parameters" do before do - @valid_params["user"]["person"]["profile"].delete("first_name") + @valid_params["user"]["password_confirmation"] = "baddword" @invalid_params = @valid_params end it "does not create a user" do diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 4ee82da6b..db980cf6f 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -13,31 +13,18 @@ describe Diaspora::Parser do let(:person) { user3.person } describe "parsing compliant XML object" do - it 'should be able to correctly handle comments with person in db' do + it 'should be able to correctly parse comment fields' do post = user.post :status_message, :message => "hello", :to => aspect.id - comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!") + comment = Factory.create(:comment, :post => post, :person => person, :diaspora_handle => person.diaspora_handle, :text => "Freedom!") comment.delete xml = comment.to_diaspora_xml + puts xml comment_from_xml = Diaspora::Parser.from_xml(xml) - comment_from_xml.text.should == "Freedom!" - comment_from_xml.person.should == person + comment_from_xml.diaspora_handle person.diaspora_handle comment_from_xml.post.should == post - end - - it 'should be able to correctly handle person on a comment with person not in db' do - friend_users(user, aspect, user2, aspect2) - post = user.post :status_message, :message => "hello", :to => aspect.id - comment = user2.comment "Fool!", :on => post - - xml = comment.to_diaspora_xml - user2.delete - user2.person.delete - - parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml) - parsed_person.save.should be true - parsed_person.diaspora_handle.should == user2.person.diaspora_handle - parsed_person.profile.should_not be_nil + comment_from_xml.text.should == "Freedom!" + comment_from_xml.should_not be comment end it 'should accept retractions' do diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 66056789d..70b99582a 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -11,6 +11,13 @@ describe Comment do let(:user2) {Factory.create(:user)} let(:aspect2) {user2.aspect(:name => "Lame-faces")} + it 'validates that the handle belongs to the person' do + user_status = user.post(:status_message, :message => "hello", :to => aspect.id) + comment = Comment.new(:person_id => user2.person.id, :text => "hey", :post => user_status) + comment.valid? + comment.errors.full_messages.should include "Diaspora handle and person handle must match" + end + describe 'User#comment' do before do @status = user.post(:status_message, :message => "hello", :to => aspect.id) @@ -52,28 +59,6 @@ describe Comment do user.reload end - it 'should receive a comment from a person not on the pod' do - user3 = Factory.create(:user) - aspect3 = user3.aspect(:name => "blah") - - friend_users(user, aspect, user3, aspect3) - - comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => @user_status) - comment.creator_signature = comment.sign_with_key(user3.encryption_key) - comment.post_creator_signature = comment.sign_with_key(user.encryption_key) - - xml = user.salmon(comment).xml_for(user2) - - user3.person.delete - user3.delete - - @user_status.reload - @user_status.comments.should == [] - user2.receive_salmon(xml) - @user_status.reload - @user_status.comments.include?(comment).should be true - end - it "should send a user's comment on a person's post to that person" do User::QUEUE.should_receive(:add_post_request) user.comment "yo", :on => @person_status @@ -86,8 +71,9 @@ describe Comment do end it 'should send a comment a person made on your post to all people' do - comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status) + comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status) User::QUEUE.should_receive(:add_post_request).twice + Person.should_receive(:by_webfinger).and_return(@person) user.receive comment.to_diaspora_xml, @person end @@ -103,13 +89,13 @@ describe Comment do end it 'should not send a comment a person made on his own post to anyone' do User::QUEUE.should_not_receive(:add_post_request) - comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status) + comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) user.receive comment.to_diaspora_xml, @person end it 'should not send a comment a person made on a person post to anyone' do User::QUEUE.should_not_receive(:add_post_request) - comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status) + comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) user.receive comment.to_diaspora_xml, @person end after(:all) do @@ -119,7 +105,7 @@ describe Comment do it 'should not clear the aspect post array on receiving a comment' do aspect.post_ids.include?(@user_status.id).should be true - comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status) + comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status) user.receive comment.to_diaspora_xml, @person @@ -128,14 +114,16 @@ describe Comment do end end describe 'serialization' do - it 'should serialize the commenter' do + it 'should serialize the handle and not the sender' do commenter = Factory.create(:user) commenter_aspect = commenter.aspect :name => "bruisers" friend_users(user, aspect, commenter, commenter_aspect) post = user.post :status_message, :message => "hello", :to => aspect.id comment = commenter.comment "Fool!", :on => post comment.person.should_not == user.person - comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true + xml = comment.to_diaspora_xml + xml.include?(commenter.person.id.to_s).should be false + xml.include?(commenter.diaspora_handle).should be true end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index fa89610af..e1c70b82f 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,22 +13,6 @@ describe Person do @aspect2 = @user2.aspect(:name => "Abscence of Babes") end - describe "validation" do - describe "of associated profile" do - it "fails if the profile isn't valid" do - person = Factory.build(:person) - person.should be_valid - - person.profile.update_attribute(:first_name, nil) - person.profile.should_not be_valid - person.should_not be_valid - - person.errors.count.should == 1 - person.errors.full_messages.first.should =~ /first name/i - end - end - end - describe '#diaspora_handle' do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do @@ -54,6 +38,27 @@ describe Person do end end + context '#real_name' do + let!(:user) { Factory(:user) } + let!(:person) { user.person } + let!(:profile) { person.profile } + + context 'with first name' do + it 'should return their name for real name' do + person.real_name.should match /#{profile.first_name}|#{profile.last_name}/ + end + end + + context 'without first name' do + it 'should display their diaspora handle' do + person.profile.first_name = nil + person.profile.last_name = nil + person.save! + person.real_name.should == person.diaspora_handle + end + end + end + describe 'xml' do before do @xml = @person.to_xml.to_s @@ -91,8 +96,8 @@ describe Person do status_message = Factory.create(:status_message, :person => @person) - Factory.create(:comment, :person_id => person.id, :text => "i love you", :post => status_message) - Factory.create(:comment, :person_id => @person.id, :text => "you are creepy", :post => status_message) + Factory.create(:comment, :person_id => person.id, :diaspora_handle => person.diaspora_handle, :text => "i love you", :post => status_message) + Factory.create(:comment, :person_id => @person.id,:diaspora_handle => @person.diaspora_handle, :text => "you are creepy", :post => status_message) lambda {person.destroy}.should_not change(Comment, :count) end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index de2eb6955..fed124726 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -7,16 +7,6 @@ require 'spec_helper' describe Profile do describe 'validation' do describe "of first_name" do - it "requires first name" do - profile = Factory.build(:profile, :first_name => nil) - profile.should_not be_valid - profile.first_name = "Hortense" - profile.should be_valid - end - it "requires non-empty first name" do - profile = Factory.build(:profile, :first_name => " ") - profile.should_not be_valid - end it "strips leading and trailing whitespace" do profile = Factory.build(:profile, :first_name => " Shelly ") profile.should be_valid @@ -24,16 +14,6 @@ describe Profile do end end describe "of last_name" do - it "requires a last name" do - profile = Factory.build(:profile, :last_name => nil) - profile.should_not be_valid - profile.last_name = "Shankar" - profile.should be_valid - end - it "requires non-empty last name" do - profile = Factory.build(:profile, :last_name => " ") - profile.should_not be_valid - end it "strips leading and trailing whitespace" do profile = Factory.build(:profile, :last_name => " Ohba ") profile.should be_valid diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index 36a586647..db5c613a2 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -79,29 +79,5 @@ describe "attack vectors" do user2.reload user2.profile.first_name.should == first_name end - - it 'should not overwrite another persons profile through comment' do - pending - user_status = user.post(:status_message, :message => "hi", :to => 'all') - comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status) - - comment.creator_signature = comment.sign_with_key(user3.encryption_key) - comment.post_creator_signature = comment.sign_with_key(user.encryption_key) - - person = user3.person - original_url = person.url - original_id = person.id - puts original_url - - comment.person.url = "http://bad.com/" - user3.delete - person.delete - - comment.to_diaspora_xml.include?("bad.com").should be true - user2.receive_salmon(user.salmon(comment).xml_for(user2.person)) - - comment.person.url.should == original_url - Person.first(:id => original_id).url.should == original_url - end end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index e339c56fc..1ff2012e8 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -94,36 +94,47 @@ describe User do describe 'comments' do before do friend_users(user, aspect, user3, aspect3) + @post = user.post :status_message, :message => "hello", :to => aspect.id + + user2.receive @post.to_diaspora_xml, user.person + user3.receive @post.to_diaspora_xml, user.person + + @comment = user3.comment('tada',:on => @post) + @comment.post_creator_signature = @comment.sign_with_key(user.encryption_key) + @xml = user.salmon(@comment).xml_for(user2.person) + @comment.delete end + it 'should correctly attach the user already on the pod' do + local_person = user3.person + + user2.reload.raw_visible_posts.size.should == 1 + post_in_db = user2.raw_visible_posts.first + post_in_db.comments.should == [] + user2.receive_salmon(@xml) + post_in_db.reload + + post_in_db.comments.include?(@comment).should be true + post_in_db.comments.first.person.should == local_person + end + it 'should correctly marshal a stranger for the downstream user' do + remote_person = user3.person + remote_person.delete + user3.delete - post = user.post :status_message, :message => "hello", :to => aspect.id + Person.should_receive(:by_webfinger).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save + user.person; else; remote_person.save; remote_person; end } - user2.receive post.to_diaspora_xml, user.person - user3.receive post.to_diaspora_xml, user.person - - comment = user2.comment('tada',:on => post) - user.receive comment.to_diaspora_xml, user2.person - user.reload - - commenter_id = user2.person.id - - user2.person.delete - user2.delete - comment_id = comment.id - - comment.delete - comment.post_creator_signature = comment.sign_with_key(user.encryption_key) - user3.receive comment.to_diaspora_xml, user.person - user3.reload - - new_comment = Comment.find_by_id(comment_id) - new_comment.should_not be_nil - new_comment.person.should_not be_nil - new_comment.person.profile.should_not be_nil - - user3.visible_person_by_id(commenter_id).should_not be_nil + + user2.reload.raw_visible_posts.size.should == 1 + post_in_db = user2.raw_visible_posts.first + post_in_db.comments.should == [] + user2.receive_salmon(@xml) + post_in_db.reload + + post_in_db.comments.include?(@comment).should be true + post_in_db.comments.first.person.should == remote_person end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 6dcc153ae..a9530093f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -148,7 +148,7 @@ describe User do :username => "ohai", :email => "ohai@example.com", :password => "password", - :password_confirmation => "password", + :password_confirmation => "wrongpasswordz", :person => {:profile => {:first_name => "", :last_name => ""}}} end it "raises no error" do