diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index b29887112..ec9bd7f1b 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -3,21 +3,18 @@ # the COPYRIGHT file. class RegistrationsController < Devise::RegistrationsController - def new - super - end - def create begin user = User.instantiate!(params[:user]) rescue MongoMapper::DocumentNotValid => e - user = nil flash[:error] = e.message + redirect_to new_user_registration_path end - if user + if user.save flash[:notice] = I18n.t 'registrations.create.success' sign_in_and_redirect(:user, user) else + flash[:error] = user.errors.full_messages.join(', ') redirect_to new_user_registration_path end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index b4bc9fe94..bbae0fbf8 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,15 +9,11 @@ class StatusMessagesController < ApplicationController respond_to :json, :only => :show def create - params[:status_message][:to] = params[:aspect_ids] - data = clean_hash params[:status_message] - if logged_into_fb? && params[:status_message][:public] == '1' id = 'me' type = 'feed' - Rails.logger.info("Sending a message: #{params[:status_message][:message]} to Facebook") EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{params[:status_message][:message]}&access_token=#{@access_token}").post end diff --git a/app/helpers/aspects_helper.rb b/app/helpers/aspects_helper.rb index 88dfe0d6b..c19fb4ac4 100644 --- a/app/helpers/aspects_helper.rb +++ b/app/helpers/aspects_helper.rb @@ -9,7 +9,7 @@ module AspectsHelper def remove_link( aspect ) if aspect.people.size == 0 - link_to I18n.t('aspects.helper.remove'), aspect, :method => :delete + link_to I18n.t('aspects.helper.remove'), aspect, :method => :delete, :confirm => "Are you sure you want to delete this aspect?" else "#{I18n.t('aspects.helper.remove')}" end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 2dfbd31cc..4131ccaf0 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -10,4 +10,14 @@ module StatusMessagesHelper return I18n.t('status_messages.helper.no_message_to_display') end end + + def make_links(message) + # If there should be some kind of bb-style markup, email/diaspora highlighting, it could go here. + + # next line is important due to XSS! (h is rail's make_html_safe-function) + message = h(message).html_safe + message.gsub!(/( |^)(www\.[^ ]+\.[^ ])/, '\1http://\2'); + return message.gsub(/(http|ftp):\/\/([^ ]+)/, '\2'); + end + end diff --git a/app/models/person.rb b/app/models/person.rb index 230ad20f1..1359b82df 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -15,11 +15,11 @@ class Person xml_accessor :profile, :as => Profile xml_reader :exported_key - key :url, String + key :url, String key :diaspora_handle, String, :unique => true key :serialized_public_key, String - key :owner_id, ObjectId + key :owner_id, ObjectId one :profile, :class_name => 'Profile' many :albums, :class_name => 'Album', :foreign_key => :person_id @@ -31,28 +31,29 @@ class Person before_validation :clean_url validates_presence_of :url, :profile, :serialized_public_key validates_format_of :url, :with => - /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix + /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix def self.search(query) return Person.all if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") - full_query_text = Regexp.escape( query.to_s.strip ) - + full_query_text = Regexp.escape(query.to_s.strip) + p = [] - + query_tokens.each do |token| - q = Regexp.escape( token.to_s.strip ) - p = Person.all('profile.first_name' => /^#{q}/i) \ - | Person.all('profile.last_name' => /^#{q}/i) \ - | p + q = Regexp.escape(token.to_s.strip) + p = Person.all('profile.first_name' => /^#{q}/i) \ + | Person.all('profile.last_name' => /^#{q}/i) \ + | p end - return p + return p end def real_name "#{profile.first_name.to_s} #{profile.last_name.to_s}" end + def owns?(post) self.id == post.person.id end @@ -71,7 +72,7 @@ class Person end def public_key - OpenSSL::PKey::RSA.new( serialized_public_key ) + OpenSSL::PKey::RSA.new(serialized_public_key) end def exported_key @@ -83,38 +84,38 @@ class Person @serialized_public_key = new_key end - def self.by_webfinger( identifier, opts = {}) + def self.by_webfinger(identifier, opts = {}) #need to check if this is a valid email structure, maybe should do in JS - local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s.downcase) + local_person = Person.first(:diaspora_handle => identifier.gsub('acct:', '').to_s) - if local_person - Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") - local_person - elsif !identifier.include?("localhost") && !opts[:local] - begin + if local_person + Rails.logger.info("Do not need to webfinger, found a local person #{local_person.real_name}") + local_person + elsif !identifier.include?("localhost") && !opts[:local] + begin Rails.logger.info("Webfingering #{identifier}") f = Redfinger.finger(identifier) - rescue SocketError => e - raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ - rescue Errno::ETIMEDOUT => e - raise "Connection timed out to Diaspora server for #{identifier}" - end - raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty? - Person.from_webfinger_profile(identifier, f ) - end + rescue SocketError => e + raise "Diaspora server for #{identifier} not found" if e.message =~ /Name or service not known/ + rescue Errno::ETIMEDOUT => e + raise "Connection timed out to Diaspora server for #{identifier}" + end + raise "No webfinger profile found at #{identifier}" if f.nil? || f.links.empty? + Person.from_webfinger_profile(identifier, f) + end end - def self.from_webfinger_profile( identifier, profile) + def self.from_webfinger_profile(identifier, profile) new_person = Person.new - public_key_entry = profile.links.select{|x| x.rel == 'diaspora-public-key'} + public_key_entry = profile.links.select { |x| x.rel == 'diaspora-public-key' } return nil unless public_key_entry pubkey = public_key_entry.first.href new_person.exported_key = Base64.decode64 pubkey - guid = profile.links.select{|x| x.rel == 'http://joindiaspora.com/guid'}.first.href + guid = profile.links.select { |x| x.rel == 'http://joindiaspora.com/guid' }.first.href new_person.id = guid new_person.diaspora_handle = identifier @@ -151,12 +152,12 @@ class Person self.url ||= "http://localhost:3000/" if self.class == User if self.url self.url = 'http://' + self.url unless self.url.match('http://' || 'https://') - self.url = self.url + '/' if self.url[-1,1] != '/' + self.url = self.url + '/' if self.url[-1, 1] != '/' end end private def remove_all_traces - Post.all(:person_id => id).each{|p| p.delete} + Post.all(:person_id => id).each { |p| p.delete } end end diff --git a/app/models/user.rb b/app/models/user.rb index ec7107fc3..7d29fd7df 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,47 +17,56 @@ end class User include MongoMapper::Document - plugin MongoMapper::Devise include Diaspora::UserModules include Encryptor::Private + + plugin MongoMapper::Devise + QUEUE = MessageHandler.new devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - key :username, :unique => true - key :serialized_private_key, String - key :invites, Integer, :default => 5 - key :invitation_token, String - key :invitation_sent_at, DateTime - key :inviter_ids, Array - key :friend_ids, Array + key :username + key :serialized_private_key, String + key :invites, Integer, :default => 5 + key :invitation_token, String + key :invitation_sent_at, DateTime + key :inviter_ids, Array + key :friend_ids, Array key :pending_request_ids, Array - key :visible_post_ids, Array - key :visible_person_ids, Array + key :visible_post_ids, Array + key :visible_person_ids, Array + + before_validation :strip_username, :on => :create + validates_presence_of :username + validates_uniqueness_of :username, :case_sensitive => false + validates_format_of :username, :without => /\s/ + + validates_with InvitedUserValidator one :person, :class_name => 'Person', :foreign_key => :owner_id - many :inviters, :in => :inviter_ids, :class_name => 'User' - many :friends, :in => :friend_ids, :class_name => 'Person' - many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go - many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' - many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' - + many :inviters, :in => :inviter_ids, :class_name => 'User' + many :friends, :in => :friend_ids, :class_name => 'Person' + many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go + many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' + many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect' after_create :seed_aspects - before_validation :downcase_username, :on => :create - validates_with InvitedUserValidator - before_destroy :unfriend_everyone, :remove_person - def self.find_for_authentication(conditions={}) + def strip_username + if username.present? + username.strip! + end + end + + def self.find_for_authentication(conditions={}) if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex conditions[:email] = conditions.delete(:username) - else - conditions[:username].downcase! end super end @@ -74,12 +83,12 @@ class User end ######### Aspects ###################### - def aspect( opts = {} ) + def aspect(opts = {}) opts[:user] = self Aspect.create(opts) end - def drop_aspect( aspect ) + def drop_aspect(aspect) if aspect.people.size == 0 aspect.destroy else @@ -87,7 +96,7 @@ class User end end - def move_friend( opts = {}) + def move_friend(opts = {}) return true if opts[:to] == opts[:from] friend = Person.first(:_id => opts[:friend_id]) if self.friend_ids.include?(friend.id) @@ -98,7 +107,7 @@ class User to_aspect.people << friend to_aspect.posts << posts_to_move from_aspect.person_ids.delete(friend.id.to_id) - posts_to_move.each{ |x| from_aspect.post_ids.delete(x.id)} + posts_to_move.each { |x| from_aspect.post_ids.delete(x.id) } from_aspect.save to_aspect.save return true @@ -111,8 +120,8 @@ class User def post(class_name, options = {}) if class_name == :photo raise ArgumentError.new("No album_id given") unless options[:album_id] - aspect_ids = aspects_with_post( options[:album_id] ) - aspect_ids.map!{ |aspect| aspect.id } + aspect_ids = aspects_with_post(options[:album_id]) + aspect_ids.map! { |aspect| aspect.id } else aspect_ids = options.delete(:to) end @@ -129,7 +138,7 @@ class User post end - def update_post( post, post_hash = {} ) + def update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) end @@ -155,7 +164,7 @@ class User aspect_ids end - def build_post( class_name, options = {}) + def build_post(class_name, options = {}) options[:person] = self.person model_class = class_name.to_s.camelize.constantize post = model_class.instantiate(options) @@ -165,18 +174,18 @@ class User post end - def push_to_aspects( post, aspect_ids ) + def push_to_aspects(post, aspect_ids) if aspect_ids == :all || aspect_ids == "all" aspects = self.aspects elsif aspect_ids.is_a?(Array) && aspect_ids.first.class == Aspect aspects = aspect_ids else - aspects = self.aspects.find_all_by_id( aspect_ids ) + aspects = self.aspects.find_all_by_id(aspect_ids) end #send to the aspects target_people = [] - aspects.each{ |aspect| + aspects.each { |aspect| aspect.posts << post aspect.save target_people = target_people | aspect.people @@ -189,15 +198,15 @@ class User def push_to_people(post, people) salmon = salmon(post) - people.each{|person| + people.each { |person| xml = salmon.xml_for person - push_to_person( person, xml) + push_to_person(person, xml) } end - def push_to_person( person, xml ) + def push_to_person(person, xml) Rails.logger.debug("#{self.real_name} is adding xml to message queue to #{person.receive_url}") - QUEUE.add_post_request( person.receive_url, xml ) + QUEUE.add_post_request(person.receive_url, xml) QUEUE.process end @@ -206,7 +215,7 @@ class User QUEUE.add_hub_notification(APP_CONFIG[:pubsub_server], self.public_url) end - def salmon( post ) + def salmon(post) created_salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml) created_salmon end @@ -221,7 +230,7 @@ class User comment end - def build_comment( text, options = {}) + 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.creator_signature = comment.sign_with_key(encryption_key) @@ -233,7 +242,7 @@ class User end end - def dispatch_comment( comment ) + def dispatch_comment(comment) if owns? comment.post comment.post_creator_signature = comment.sign_with_key(encryption_key) comment.save @@ -245,9 +254,9 @@ class User end ######### Posts and Such ############### - def retract( post ) - aspect_ids = aspects_with_post( post.id ) - aspect_ids.map!{|aspect| aspect.id.to_s} + def retract(post) + aspect_ids = aspects_with_post(post.id) + aspect_ids.map! { |aspect| aspect.id.to_s } post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) @@ -266,7 +275,7 @@ class User end ###Invitations############ - def invite_user( opts = {} ) + def invite_user(opts = {}) if self.invites > 0 aspect_id = opts.delete(:aspect_id) @@ -276,9 +285,9 @@ class User raise "Must invite to your aspect" end request = Request.instantiate( - :to => "http://local_request.example.com", - :from => self.person, - :into => aspect_id + :to => "http://local_request.example.com", + :from => self.person, + :into => aspect_id ) invited_user = User.invite!(:email => opts[:email], :request => request, :inviter => self) @@ -316,7 +325,7 @@ class User invitable end - def accept_invitation!( opts = {} ) + def accept_invitation!(opts = {}) if self.invited? self.username = opts[:username] self.password = opts[:password] @@ -338,7 +347,7 @@ class User end ###Helpers############ - def self.instantiate!( opts = {} ) + def self.instantiate!(opts = {}) opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" opts[:person][:url] = APP_CONFIG[:pod_url] @@ -356,17 +365,13 @@ class User "#{self.username}@#{APP_CONFIG[:terse_pod_url]}" end - def downcase_username - username.downcase! if username - end - def as_json(opts={}) { :user => { - :posts => self.raw_visible_posts.each{|post| post.as_json}, - :friends => self.friends.each {|friend| friend.as_json}, - :aspects => self.aspects.each {|aspect| aspect.as_json}, - :pending_requests => self.pending_requests.each{|request| request.as_json}, + :posts => self.raw_visible_posts.each { |post| post.as_json }, + :friends => self.friends.each { |friend| friend.as_json }, + :aspects => self.aspects.each { |aspect| aspect.as_json }, + :pending_requests => self.pending_requests.each { |request| request.as_json }, } } end @@ -377,9 +382,9 @@ class User end def encryption_key - OpenSSL::PKey::RSA.new( serialized_private_key ) + OpenSSL::PKey::RSA.new(serialized_private_key) end - + protected def remove_person @@ -387,11 +392,11 @@ class User end def unfriend_everyone - friends.each{ |friend| + friends.each { |friend| if friend.owner? friend.owner.unfriended_by self.person - else - self.unfriend friend + else + self.unfriend friend end } end diff --git a/app/views/albums/edit.html.haml b/app/views/albums/edit.html.haml index 4969227e4..e979b1a77 100644 --- a/app/views/albums/edit.html.haml +++ b/app/views/albums/edit.html.haml @@ -2,19 +2,15 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.back= link_to "⇧ #{@album.name}", @album -%h1.big_text - = "#{t('.editing')} #{@album.name}" +%h2= "#{t('.editing')} #{@album.name}" -.sub_header - ="#{t('.updated')} #{how_long_ago(@album)}" +- form_for @album do |album| + = album.error_messages -- form_for @album do |a| - = a.error_messages - %p - %b album name: - = a.text_field :name + %h4 + Album name + = album.text_field :name - for photo in @album.photos .photo_edit_block= image_tag photo.url(:thumb_medium) @@ -22,11 +18,8 @@ .submit_block = link_to t('.cancel'), root_path or - = a.submit + = album.submit .button.delete = link_to t('.delete_album'), @album, :confirm => t('.are_you_sure'), :method => :delete -#content_bottom - .back - = link_to "⇧ #{@album.name}", @album diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml index 4b76d38e1..cd4f93ab3 100644 --- a/app/views/albums/index.html.haml +++ b/app/views/albums/index.html.haml @@ -17,7 +17,7 @@ .right = link_to t('.new_album'), '#new_album_pane', {:class => "button", :id => "add_album_button"} -.yo{:style => "display:none;" } +.fancybox_content #new_album_pane = render "albums/new_album", :aspect => params[:aspect] diff --git a/app/views/aspects/_new_aspect.haml b/app/views/aspects/_new_aspect.haml index 8c3c45f4d..151ab07d4 100644 --- a/app/views/aspects/_new_aspect.haml +++ b/app/views/aspects/_new_aspect.haml @@ -3,9 +3,9 @@ -# the COPYRIGHT file. %h1=t('.add_a_new_aspect') -= form_for Aspect.new do |f| - = f.error_messages += form_for Aspect.new do |aspect| + = aspect.error_messages %p - = f.label :name - = f.text_field :name - = f.submit t('.create'), :class => 'button' + = aspect.label :name + = aspect.text_field :name + = aspect.submit t('.create'), :class => 'button' diff --git a/app/views/aspects/manage.html.haml b/app/views/aspects/manage.html.haml index a188787af..73b2bac29 100644 --- a/app/views/aspects/manage.html.haml +++ b/app/views/aspects/manage.html.haml @@ -42,7 +42,6 @@ %ul.tools %li= link_to t('.add_a_new_friend'), "#add_request_pane_#{aspect.id}", :class => 'add_request_button' - %li= link_to t('.show'), aspect_path(aspect) %li!= remove_link(aspect) %ul.dropzone{:id => aspect.id} @@ -57,8 +56,8 @@ = person_image_tag(person) .name = link_to person.real_name, person - .yo{:style => 'display:none'} + + .fancybox_content %div{:id => "add_request_pane_#{aspect.id}"} = render "requests/new_request", :aspect => aspect -#content_bottom diff --git a/app/views/aspects/public.html.haml b/app/views/aspects/public.html.haml deleted file mode 100644 index 95c185761..000000000 --- a/app/views/aspects/public.html.haml +++ /dev/null @@ -1,22 +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. - - -- content_for :page_title do - = link_to "photos", albums_path(:aspect => @aspect) - -- content_for :left_pane do - = render "shared/aspect_friends" - -- content_for :publish do - - if - = render "shared/publisher", :aspect_ids => :all - -%ul#stream - - for post in @posts - = render type_partial(post), :post => post unless post.class == Album - -#pagination - = will_paginate @posts - diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 2c95d4385..bb8719ee7 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -2,10 +2,12 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_for Comment.new, :remote => true do |f| += form_for Comment.new, :remote => true do |comment| %p - %label{:for => "comment_text_on_#{post.id}"} Comment - = f.text_area :text, :rows => 1, :id => "comment_text_on_#{post.id}", :class => "comment_box" - = f.hidden_field :post_id, :value => post.id + = label_tag "comment_text_on_#{post.id}", "Comment" + = comment.text_area :text, :rows => 1, :id => "comment_text_on_#{post.id}", :class => "comment_box" + + = comment.hidden_field :post_id, :value => post.id + %p{:style => "text-align:right;"} - = f.submit t('.comment'), :class => "comment_submit button" + = comment.submit t('.comment'), :class => "comment_submit button" diff --git a/app/views/invitations/_new.haml b/app/views/invitations/_new.haml index 36b0dacac..9cd41f05f 100644 --- a/app/views/invitations/_new.haml +++ b/app/views/invitations/_new.haml @@ -1,11 +1,13 @@ %h2 Send invitation -= form_for User.new, :url => invitation_path(User) do |f| += form_for User.new, :url => invitation_path(User) do |invite| %p - = f.label :email - = f.text_field :email - To - - if @aspect == :all - = f.select(:aspects, @aspects_dropdown_array) - - else - = f.select(:aspects, @aspects_dropdown_array, :selected => [@aspect.to_s, @aspect_id]) - %p= f.submit "Send an invitation" + = invite.label :email + = invite.text_field :email + To + - if @aspect == :all + = invite.select(:aspects, @aspects_dropdown_array) + - else + = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) + + %p= invite.submit "Send an invitation" + diff --git a/app/views/people/new.html.haml b/app/views/people/new.html.haml deleted file mode 100644 index 7685a8933..000000000 --- a/app/views/people/new.html.haml +++ /dev/null @@ -1,30 +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. - -- title=t('.new_person') - -= form_for @person do |f| - = f.error_messages - %p - = f.label :diaspora_handle - %br - = f.text_field :diaspora_handle - %p - = f.label :url - %br - = f.text_field :url - - =f.fields_for :profile do |p| - %p - = p.label :first_name - %br - = p.text_field :first_name - - %p - = p.label :last_name - %br - = p.text_field :last_name - = f.submit - -%p= link_to t('.back_to_list'), people_path diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 3e1fc31e6..1038d7d94 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -27,7 +27,6 @@ = link_to t('.remove_friend'), @person, :confirm => t('.are_you_sure'), :method => :delete, :class => "button" .span-20.last - .span-19.last - if @posts %ul#stream diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml index 78186d248..08e6dae0a 100644 --- a/app/views/photos/edit.html.haml +++ b/app/views/photos/edit.html.haml @@ -2,20 +2,16 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -%h1.big_text - .back - = link_to "⇧ #{@album.name}", album_path(@album) - = "#{t('.editing')} #{@photo.image}" +%h2= "#{t('.editing')} #{@photo.image}" %div{:id => @photo.id} - #show_photo = linked_scaled_photo @photo, @album - = form_for @photo do |p| - = p.label :caption - = p.text_field :caption, :value => @photo.caption - = p.submit + = form_for @photo do |photo| + = photo.label :caption + = photo.text_field :caption, :value => @photo.caption + = photo.submit %div{:class => 'clear'} #content_bottom diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 58c363240..8d0e66471 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -30,7 +30,6 @@ //show form to add description $(".edit-desc").click(function(){ $(".edit_photo").toggle(); - //$(".caption").toggle(); }); //Add a description with ajax request @@ -40,7 +39,6 @@ var url = $(".edit_photo").attr("action"); var data = $(".edit_photo").serialize(); $(".description").text($("#photo_caption").val()); - //$(".caption").toggle(); $(".edit_photo").toggle(); $.ajax({ @@ -66,11 +64,11 @@ %h1 = @photo.image - = link_to "<< #{t('.prev')}", url_to_prev(@photo, @album) + = link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch' | = link_to "#{t('.full_size')}", @photo.url | - = link_to "#{t('.next')} >>", url_to_next(@photo, @album) + = link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch' .right -if current_user.owns? @album @@ -80,13 +78,13 @@ #show_photo = linked_scaled_photo @photo, @album .caption - -if current_user.owns? @album + -if current_user.owns? @photo -if @photo.caption and @photo.caption != "" = link_to 'Edit','javascript:void(0)', :id => "edit-desc", :class => "edit-desc" .description = @photo.caption - -if current_user.owns? @album + -if current_user.owns? @photo %div{:class => 'clear'} -if !@photo.caption or @photo.caption == "" = link_to 'Add a description','javascript:void(0)', :id => "add-description", :class => "edit-desc" diff --git a/app/views/requests/_new_request.haml b/app/views/requests/_new_request.haml index ced50fd54..68ee5922e 100644 --- a/app/views/requests/_new_request.haml +++ b/app/views/requests/_new_request.haml @@ -6,16 +6,16 @@ =t('.add_a_new_friend_to') %i= aspect.name -= form_for Request.new do |f| - = f.error_messages += form_for Request.new do |fr_request| + = fr_request.error_messages =t('.enter_a_diaspora_username') %br %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle %p - = f.label :destination_url, t(".friends_username") - = f.text_field :destination_url - = f.hidden_field :aspect_id, :value => aspect.id - = f.submit + = fr_request.label :destination_url, t(".friends_username") + = fr_request.text_field :destination_url + = fr_request.hidden_field :aspect_id, :value => aspect.id + = fr_request.submit diff --git a/app/views/shared/_aspect_friends.haml b/app/views/shared/_aspect_friends.haml index 6ca3a29af..d50a369d3 100644 --- a/app/views/shared/_aspect_friends.haml +++ b/app/views/shared/_aspect_friends.haml @@ -13,10 +13,10 @@ - @fb_friends = MiniFB.get(@access_token, 'me', :type => "friends") - @fb_friends[:data].each do |friend| = image_tag( "http://graph.facebook.com/#{friend[:id]}/picture" ) - -unless (@aspect == :all) || (@aspect == :public) + -unless (@aspect == :all) = link_to (image_tag('add_friend_button.png', :height => "50px", :width => "50px")), "#add_request_pane", :id => 'add_request_button' - .yo{:style => 'display:none'} + .fancybox_content #add_request_pane = render "requests/new_request", :aspect => @aspect -else diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index a6f1bd92c..5400d15d1 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -3,7 +3,6 @@ -# the COPYRIGHT file. :javascript - $("div.public_toggle input").live("click", function(evt){ if("#{@logged_in}" == "false" && $(this).attr('checked') == true){ $(".question_mark").click(); @@ -13,31 +12,26 @@ #publisher = owner_image_tag - = form_for StatusMessage.new, :remote => true do |f| - = f.error_messages + = form_for StatusMessage.new, :remote => true do |status| + = status.error_messages %p - %label{:for => "status_message_message"} Message - = f.text_area :message, :rows => 2, :value => params[:prefill] - - %ul.aspect_selector{ :style => "display:none;"} - going to... - - for aspect in @aspects - %li - = check_box_tag("aspect_ids[]", aspect.id, @aspect == :all || current_aspect?(aspect) ) - = aspect.name + = status.label :message, "Post a message to #{@aspect}" + = status.text_area :message, :rows => 2, :value => params[:prefill] + = status.hidden_field :to, :value => (@aspect == :all ? @aspect : @aspect.id) - if @aspect == :all .public_toggle - = f.check_box( :public, :value => false ) + = status.check_box( :public, :value => false ) make public = link_to '(?)', "#question_mark_pane", :class => 'question_mark' - .yo{:style => "display:none;"} + + .fancybox_content #question_mark_pane = render 'shared/public_explain' - .buttons - - if @aspect == :all - = f.submit t('.share'), :title => "Share with all aspects" - - else - = f.submit t('.share'), :title => "Share with #{@aspect.name}" + + - if @aspect == :all + = status.submit t('.share'), :title => "Share with all aspects" + - else + = status.submit t('.share'), :title => "Share with #{@aspect}" diff --git a/app/views/shared/_sub_header.haml b/app/views/shared/_sub_header.haml index 781b38629..50c80da53 100644 --- a/app/views/shared/_sub_header.haml +++ b/app/views/shared/_sub_header.haml @@ -8,8 +8,6 @@ %h2 - if @aspect == :all = link_to "Everyone", root_path - - elsif @aspect == :public - = "Public" - elsif @aspect == :manage = link_to t('.manage_aspects'), root_path - else diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 8a7b6cbba..8b2437ae9 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -23,7 +23,7 @@ = render "shared/reshare", :post => post, :current_user => current_user = link_to t('.delete'), status_message_path(post), :confirm => t('.are_you_sure'), :method => :delete, :remote => true, :class => "delete" - = post.message + = make_links(post.message) .info %span.time= link_to(how_long_ago(post), object_path(post)) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 9d438feec..10bfa9070 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -6,6 +6,15 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: + activemodel: + errors: + models: + user: + attributes: + username: + taken: "is already taken" + email: + taken: "is already taken" hello: "Hello world" application: helper: diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index 346730a3a..8060df3a6 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -1,8 +1,6 @@ ## Diaspora RPM tools -NOTE: This does not work ATM, see discussions on Gemfile.lock in -attached to a commit 12/10 (yea, I know, you calll it 10/12, but you -are wrong ;) +NOTE: This does not work ATM, see http://bugs.joindiaspora.com/issues/372 Creates diaspora source tarballs and RPM packages @@ -89,6 +87,19 @@ The source tarball is as retrieved from diaspora with following differences: - The file .bundle/config is patched. Remove before doing *bundle install* +./make-dist.sh bundle|source occasionally fails on bad Gemfile.lock. The +root cause is a bad Gemfile in the git repo. Possible fixes includes +using a older version known to work: + + % ./make-dist.sh -c c818885b6 bundle + % ./make-dist.sh -c c818885b6 source + +or forcing a complete update of Gemfile.lock using 'bundle update' (a +potential problematic operation): + + % ./make-dist.sh -f bundle + + Routines uses last available version from master branch at github. The version contains a time stamp and an abbreviated git commit id. Using -c, a specific commit can be used for source build. diff --git a/pkg/fedora/diaspora-bundle.spec b/pkg/fedora/diaspora-bundle.spec index 6f04cff2f..5e66dcc75 100644 --- a/pkg/fedora/diaspora-bundle.spec +++ b/pkg/fedora/diaspora-bundle.spec @@ -73,7 +73,7 @@ pushd bundle/ruby/1.8/ chmod 755 gems/thin-1.2.7/example/async_tailer.ru chmod 644 gems/i18n-0.4.1/MIT-LICENSE chmod 755 gems/abstract-1.0.0/abstract.gemspec - chmod 644 gems/mini_magick-2.1/MIT-LICENSE + chmod 644 gems/mini_magick-2.1/MIT-LICENSE || : chmod 755 gems/thin-1.2.7/lib/thin/controllers/service.sh.erb chmod 644 gems/treetop-1.4.8/spec/compiler/test_grammar.tt popd @@ -201,8 +201,8 @@ pushd bundle/ruby/1.8/gems/selenium-webdriver-0.0.28/lib/selenium/webdriver/ popd } -mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/master/vendor -cp -ar bundle $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/master/vendor +mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/ +cp -ar bundle $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle/ find %{buildroot}/%{_libdir}/diaspora-bundle \ -type d -fprintf dirs '%%%dir "%%p"\n' @@ -220,7 +220,7 @@ cat files >> dirs && cp dirs files %files -f files %defattr(-, diaspora, diaspora, 0755) -%doc COPYRIGHT Gemfile AUTHORS GNU-AGPL-3.0 +%doc COPYRIGHT Gemfile Gemfile.lock AUTHORS GNU-AGPL-3.0 %files -f dev-files devel %defattr(-, root, root, 0644) diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index b4bd62b5d..4c0cca719 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -1,5 +1,9 @@ +# Turn off the brp-python-bytecompile script +%global __os_install_post %(echo '%{__os_install_post}' | \ + sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g') %global debug_package %{nil} -%define git_release 1010092232_b313272 + +%define git_release HEAD Summary: A social network server Name: diaspora @@ -13,19 +17,30 @@ Source: %{name}-%{version}-%{git_release}.tar.gz Source1: diaspora-wsd Source2: diaspora-setup Source3: diaspora.logconf -Source4: make_rel_symlink.py +Source4: make_rel_symlink.py BuildArch: noarch BuildRoot: %{_rmpdir}/not-used-in-fedora/ Requires: mongodb-server Requires: ruby(abi) = 1.8 -Requires: diaspora-bundle = 0.0-1.1010081636_d1a4ee0.fc13 +Requires: diaspora-bundle = %{version} %description A privacy aware, personally controlled, do-it-all and open source social network server. +%package wsd +Summary: Sys V init script for diaspora websocket daemon +Group: Applications/Communications +Requires: %{name} = %{version} + +%description wsd +Tools to use the diaspora websocket daemon as a service e. g., when +using papche passenger or system-wide installed thin server to run +diaspora. + + %prep %setup -q -n %{name}-%{version}-%{git_release} @@ -34,12 +49,13 @@ find . -perm /u+x -type f -exec \ %build rm -rf master/vendor/bundle +mkdir master/tmp || : %install rm -fr $RPM_BUILD_ROOT sed -i \ - '/BUNDLE_PATH/s|:.*|: %{_libdir}/diaspora-bundle/master/vendor/bundle|' \ + '/BUNDLE_PATH/s|:.*|: %{_libdir}/diaspora-bundle/bundle|' \ master/.bundle/config cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . @@ -55,6 +71,9 @@ cp %SOURCE3 $RPM_BUILD_ROOT/%{_sysconfdir}/logrotate.d/diaspora mkdir -p $RPM_BUILD_ROOT/%{_datadir}/diaspora cp -ar master $RPM_BUILD_ROOT/%{_datadir}/diaspora +cp -ar master/.bundle $RPM_BUILD_ROOT/%{_datadir}/diaspora/master +mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/uploads +mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp cp %SOURCE2 $RPM_BUILD_ROOT/%{_datadir}/diaspora mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora @@ -79,11 +98,10 @@ sed -i -e '\|.*/master/config.ru"$|d' \ files -%post -/sbin/chkconfig --add diaspora-wsd +%post wsd +/sbin/chkconfig --add diaspora-wsd || : - -%preun +%preun wsd if [ $1 -eq 0 ] ; then service diaspora-wsd stop &>/dev/null || : /sbin/chkconfig --del diaspora-wsd @@ -102,15 +120,19 @@ rm -fr $RPM_BUILD_ROOT %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp + %{_datadir}/diaspora/master/tmp %{_datadir}/diaspora/master/public/uploads %{_datadir}/diaspora/master/log + %config(noreplace) %{_sysconfdir}/logrotate.d/diaspora + +%files wsd +%defattr(-, root, root, 0755) %{_sysconfdir}/init.d/diaspora-wsd %changelog -* Fri Sep 24 2010 Alec Leamas 0.0-1.1010092232_b313272.fc13 - +* Fri Sep 24 2010 Alec Leamas 0.0-1.1009280542_859ec2d - Initial attempt to create a spec fi+le # rubygem-term-ansicolor in repo (1.0.5) diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 2ab4ccac5..18dbfff9b 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -126,7 +126,8 @@ function checkout() git clone --quiet $GIT_REPO; ( cd diaspora; - git remote add upstream $GIT_REPO + git remote add upstream \ + git://github.com/diaspora/diaspora.git for p in ../../*.patch; do git apply --whitespace=fix $p > /dev/null done &> /dev/null || : @@ -166,9 +167,6 @@ function make_src find $PWD -name .git\* | xargs rm -rf rm -rf .bundle /usr/bin/patch -p1 -s <../../../add-bundle.diff - for p in ../../../*.patch; do - /usr/bin/patch -p1 -s < $p - done &> /dev/null || : ) tar czf ${RELEASE_DIR}.tar.gz ${RELEASE_DIR} && \ rm -rf ${RELEASE_DIR} @@ -183,6 +181,7 @@ function make_bundle() # Usage: make_bundle [ commit, defaults to HEAD] # { +set -x checkout ${1:-'HEAD'} >/dev/null bundle_id=$( git_id dist/diaspora/Gemfile) bundle_name="diaspora-bundle-$VERSION-$bundle_id" @@ -192,11 +191,14 @@ function make_bundle() rm -rf $bundle_name mkdir -p $bundle_name/bundle pushd diaspora > /dev/null + if [ "$BUNDLE_FIX" = 'yes' ]; then + bundle update + fi bundle install --deployment \ --path="../$bundle_name/bundle" \ --without=test rdoc - cp -ar AUTHORS Gemfile GNU-AGPL-3.0 COPYRIGHT \ + cp -ar AUTHORS Gemfile Gemfile.lock GNU-AGPL-3.0 COPYRIGHT \ "../$bundle_name" popd > /dev/null tar czf $bundle_name.tar.gz $bundle_name @@ -204,8 +206,7 @@ function make_bundle() cd .. } echo - echo "Repo: $GIT_REPO" - echo "Bundle: dist/$bundle_name.tar.gz" + echo "Bundle: dist/$bundle_name.tar.gz" } @@ -269,6 +270,8 @@ function usage() -r release Mark with specified release, defaults to 1. -u uri Git repository URI, defaults to $GIT_REPO. + -f For bundle, fix dependencies by running 'bundle update' + before 'bundle install' source Build a diaspora application tarball. bundle Build a bundler(1) bundle for diaspora. @@ -280,8 +283,10 @@ function usage() EOF } + commit='HEAD' -while getopts ":r:c:u:h" opt +BUNDLE_FIX='no' +while getopts ":r:c:fh" opt do case $opt in u) GIT_REPO="$OPTARG" @@ -290,6 +295,8 @@ do ;; r) RELEASE="$OPTARG:" ;; + f) BUNDLE_FIX='yes' + ;; h) usage exit 0 ;; @@ -300,7 +307,7 @@ do done shift $(($OPTIND - 1)) -typeset -r GIT_REPO RELEASE +typeset -r GIT_REPO RELEASE BUNDLE_FIX export LANG=C test $# -gt 1 -o $# -eq 0 && { @@ -310,7 +317,7 @@ test $# -gt 1 -o $# -eq 0 && { case $1 in - "bundle") make_bundle $commit + "bundle") make_bundle $commit $BUNDLE_FIX ;; 'source') make_src $commit ;; diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index b676ebf0c..ee78f6df7 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -1,9 +1,6 @@ ## Package-oriented install for ubuntu. -NOTE: This does not work ATM, see discussions on Gemfile.lock in -attached to a commit 12/10 (yea, I know, you calll it 10/12, but you -are wrong ;) - +NOTE: This does not work ATM, see http://bugs.joindiaspora.com/issues/372 Here are somediaspora-installdiaspora-install scripts to install diaspora on Ubuntu. They are designed to work as a first step towards packaging, but should be usable as is. @@ -52,6 +49,16 @@ OK to use. If it's not, it will build a new. ### Notes +./make-dist.sh bundle|source occasionally fails on bad Gemfile.lock. The +root cause is a bad Gemfile.lock in the git repo. Possible fixes includes +using a older version known to work: + % ./make-dist.sh -c c818885b6 bundle + % ./make-dist.sh -c c818885b6 source + +or forcing a complete update of Gemfile.lock using 'bundle update' (a +potential problematic operation): + % ./make-dist.sh -f bundle + The application lives in /usr/share/diaspora/master. All writable areas (log, uploads, tmp) are links to /var/lib/diaspora. The config file lives in /etc/diaspora. All files in /usr/share are read-only, owned by root. @@ -59,7 +66,7 @@ in /etc/diaspora. All files in /usr/share are read-only, owned by root. The bundle lives in /usr/lib/diaspora-bundle, readonly, owned by root. Application finds it through the patched .bundle/config in root dir. -Once diaspora ins installed ,makedist.sh et. al. are available in +Once diaspora is installed, makedist.sh et. al. are available in /usr/share/diaspora/master/pkg/ubuntu, so there's no need to checkout the stuff using git in this case. diff --git a/public/javascripts/view.js b/public/javascripts/view.js index dec170a07..67cdcce5e 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -47,9 +47,9 @@ $(document).ready(function(){ } ); - $("#publisher textarea").keydown( function(e) { + $("#publisher textarea, .comment textarea").keydown( function(e) { if (e.keyCode == 13) { - $("#publisher form").submit(); + $(this).closest("form").submit(); } }); diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 91bbf60f3..6db368b34 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -115,7 +115,6 @@ header a :color #CCC - :text-shadow 0 1px 0 #444 &:hover :background none @@ -130,6 +129,9 @@ header :color #fff ul#user_menu + a + :text-shadow 0 1px 0 #444 + :z-index 10 :font :size 14px @@ -246,7 +248,6 @@ li.message :background #eee .content - :max-width 610px :margin :top -4px :padding @@ -448,16 +449,13 @@ ul.comment_set :top 1em :padding 0 :list-style none - :max-width 610px + :background + :color rgba(10,81,109,0.05) textarea :width 100% li.comment - :margin - :bottom 0.5em - :background - :color rgba(10,81,109,0.05) :padding 0.6em :border :bottom 1px solid #ddd @@ -466,8 +464,10 @@ ul.comment_set :color #777 :margin :top -2px + :bottom -2px :padding :left 45px + :right 20px .from a :color #444 @@ -475,7 +475,7 @@ ul.comment_set :size 12px :line - :height 18px + :height 16px div.time :color #bbb @@ -629,20 +629,14 @@ label :display inline input[type='submit'] - :display block + :float right :margin :right 20px - :width 100% textarea :width 570px :height 42px - :margin - :top 0 - :bottom 0 - - .buttons - :float right + :margin 0 .public_toggle :position absolute @@ -1057,3 +1051,9 @@ input[type="search"] header input[type="search"] :width 200px + +.fancybox_content + :display none + +.edit_photo + :display none diff --git a/spec/controllers/dev_utilities_controller_spec.rb b/spec/controllers/dev_utilities_controller_spec.rb index 61a56f8e1..deb7b1975 100644 --- a/spec/controllers/dev_utilities_controller_spec.rb +++ b/spec/controllers/dev_utilities_controller_spec.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, "spec", "spec_helper") +require File.join(File.dirname(__FILE__), "..", "spec_helper") describe DevUtilitiesController do render_views diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index a7d745985..113ca4a9b 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -49,9 +49,28 @@ describe PublicsController do end describe 'webfinger' do - it 'should not try to webfinger out on a request to webfinger' do - Redfinger.should_not_receive :finger - post :webfinger, :q => 'remote@example.com' + it "succeeds when the person and user exist locally" do + user = Factory(:user) + post :webfinger, 'q' => user.person.diaspora_handle + response.should be_success + end + + it "404s when the person exists remotely because it is local only" do + stub_success('me@mydiaspora.pod.com') + post :webfinger, 'q' => 'me@mydiaspora.pod.com' + response.should be_not_found + end + + it "404s when the person is local but doesn't have an owner" do + person = Factory(:person) + post :webfinger, 'q' => person.diaspora_handle + response.should be_not_found + end + + it "404s when the person does not exist locally or remotely" do + stub_failure('me@mydiaspora.pod.com') + post :webfinger, 'q' => 'me@mydiaspora.pod.com' + response.should be_not_found end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb new file mode 100644 index 000000000..da7643fc9 --- /dev/null +++ b/spec/controllers/registrations_controller_spec.rb @@ -0,0 +1,56 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require File.join(File.dirname(__FILE__), "..", "spec_helper") + +describe RegistrationsController do + include Devise::TestHelpers + + render_views + + before do + request.env["devise.mapping"] = Devise.mappings[:user] + @valid_params = {"user" => {"username" => "jdoe", + "email" => "jdoe@example.com", + "password" => "password", + "password_confirmation" => "password", + "person" => { + "profile" => { + "first_name" => "John", + "last_name" => "Doe"}}}} + end + + describe "#create" do + context "with valid parameters" do + it "creates a user" do + lambda { get :create, @valid_params }.should change(User, :count).by(1) + end + it "sets the flash" do + get :create, @valid_params + flash[:notice].should_not be_empty + end + it "redirects to the root path" do + get :create, @valid_params + response.should redirect_to root_path + end + end + context "with invalid parameters" do + before do + @valid_params["user"].delete("username") + @invalid_params = @valid_params + end + it "does not create a user" do + lambda { get :create, @invalid_params }.should_not change(User, :count) + end + it "sets the flash error" do + get :create, @invalid_params + flash[:error].should_not be_blank + end + it "goes back to the form" do + get :create, @invalid_params + response.should redirect_to new_user_registration_path + end + end + end +end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 8df112285..9c84fe3e8 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -5,16 +5,17 @@ require 'spec_helper' describe StatusMessagesController do - render_views + render_views + + let!(:user) { Factory(:user) } + let!(:aspect) { user.aspect(:name => "lame-os") } + before do - @user = Factory.create(:user) - @aspect = @user.aspect(:name => "lame-os") - @album = @user.post :album, :to => @aspect.id, :name => 'things on fire' - sign_in :user, @user + sign_in :user, user end describe '#create' do - let(:status_message_hash) {{"aspect_ids" =>"#{@aspect.id.to_s}", "status_message"=>{"public"=>"1", "message"=>"facebook, is that you?"}}} + let(:status_message_hash) {{"status_message"=>{"public"=>"1", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}} before do @controller.stub!(:logged_into_fb?).and_return(true) diff --git a/spec/factories.rb b/spec/factories.rb index 5e5c32b10..c66fa4f86 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -32,7 +32,7 @@ Factory.define :user do |u| u.password_confirmation "bluepin7" u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export u.after_build do |user| - user.person = Factory(:person, :owner_id => user._id, + user.person = Factory.build(:person, :owner_id => user._id, :serialized_public_key => user.encryption_key.public_key.export, :diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") end diff --git a/spec/fixtures/hcard_response b/spec/fixtures/hcard_response index bbd06c4bf..c3bfb2840 100644 --- a/spec/fixtures/hcard_response +++ b/spec/fixtures/hcard_response @@ -1,44 +1,49 @@ -
-

Alexander Hamiltom

-
-
-

User profile

-
-
Nickname
-
- Alexander Hamiltom -
-
-
-
Full name
-
- Alexander -
-
+
+

Alexander Hamiltom

+
+
+

User profile

+
+
Nickname
+
+ Alexander Hamiltom +
+
+
+
First name
+
+ Alexander +
+
+
+
Family name
+
+ Hamiltom +
+
+
+
Full name
+
+ Alexander Hamiltom +
+
+
+
URL
+
+ http://tom.joindiaspora.com/ +
+
+
+
Photo
+
+ +
+
+
+
Note
+
Diaspora is awesome! vi is better than emacs!
+
+
+
+
-
-
Full name
-
- Hamiltom -
-
-
-
Full name
-
- Alexander Hamiltom -
-
-
-
URL
-
- http://tom.joindiaspora.com/ -
-
-
-
Note
-
Diaspora is awesome! vi is better than emacs!
-
-
-
- -
diff --git a/spec/helpers/status_messages_helper_spec.rb b/spec/helpers/status_messages_helper_spec.rb new file mode 100644 index 000000000..c0f7c1e38 --- /dev/null +++ b/spec/helpers/status_messages_helper_spec.rb @@ -0,0 +1,43 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe StatusMessagesHelper do + it "should not allow basic XSS/HTML" do + make_links("").should == "<script>alert('XSS is evil')</script>" + end + + it "should recognize basic http links (1/3)" do + proto="http" + url="bugs.joindiaspora.com/issues/332" + make_links(proto+"://"+url).should == ""+url+"" + end + + it "should recognize basic http links (2/3)" do + proto="http" + url="www.youtube.com/watch?v=b15yaPYNDRU" + make_links(proto+"://"+url).should == ""+url+"" + end + + it "should recognize basic http links (3/3)" do + proto="http" + url="127.0.0.1:3000/users/sign_in" + make_links(proto+"://"+url).should == ""+url+"" + end + + it "should recognize basic ftp links" do + proto="ftp" + url="ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4" + # I did not watch that one, but the title sounds nice :P + make_links(proto+"://"+url).should == ""+url+"" + end + + it "should recognize www links" do + url="www.joindiaspora.com" + make_links(url).should == ""+url+"" + end + + +end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 6e69721ae..5a84811db 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -164,17 +164,31 @@ describe Person do people = Person.search("Casey Grippi") people.should == [@friend_four] end + end - it 'should search by diaspora_handle exactly' do - stub_success("tom@tom.joindiaspora.com") - Person.by_webfinger(@friend_one.diaspora_handle).should == @friend_one + describe ".by_webfinger" do + context "local people" do + before do + @local_person = Factory(:person) + Redfinger.should_not_receive :finger + end + + it "finds the local person without calling out" do + person = Person.by_webfinger(@local_person.diaspora_handle) + person.should == @local_person + end + + it "finds a local person with a mixed-case username" do + user = Factory(:user, :username => "SaMaNtHa") + person = Person.by_webfinger(user.person.diaspora_handle) + person.should == user.person + end end - it 'should create a stub for a remote user' do + it 'creates a stub for a remote user' do stub_success("tom@tom.joindiaspora.com") tom = Person.by_webfinger('tom@tom.joindiaspora.com') tom.real_name.include?("Hamiltom").should be true end - end end diff --git a/spec/models/user/invite_spec.rb b/spec/models/user/invite_spec.rb index 3dccb436a..9776a687a 100644 --- a/spec/models/user/invite_spec.rb +++ b/spec/models/user/invite_spec.rb @@ -11,8 +11,8 @@ describe User do let(:wrong_aspect) {another_user.aspect(:name => "super")} let(:inviter_with_3_invites) {Factory.create :user, :invites => 3} let(:aspect2) {inviter_with_3_invites.aspect(:name => "Jersey Girls")} - let!(:invited_user1) { create_user_with_invitation("abc", :email => "email@example.com", :inviter => inviter)} - let!(:invited_user2) { inviter.invite_user(:email => "jane@example.com", :aspect_id => aspect.id) } + #let!(:invited_user1) { create_user_with_invitation("abc", :email => "email@example.com", :inviter => inviter)} + #let!(:invited_user2) { inviter.invite_user(:email => "jane@example.com", :aspect_id => aspect.id) } before do deliverable = Object.new @@ -20,17 +20,19 @@ describe User do ::Devise.mailer.stub!(:invitation).and_return(deliverable) end - context "creating invites" do - + context "creating invites" do it 'requires an apect' do + pending proc{inviter.invite_user(:email => "maggie@example.com")}.should raise_error /Must invite into aspect/ end it 'requires your aspect' do + pending proc{inviter.invite_user(:email => "maggie@example.com", :aspect_id => wrong_aspect.id)}.should raise_error /Must invite to your aspect/ end it 'creates a user' do + pending inviter lambda { inviter.invite_user(:email => "joe@example.com", :aspect_id => aspect.id ) @@ -38,11 +40,13 @@ describe User do end it 'sends email to the invited user' do + pending ::Devise.mailer.should_receive(:invitation).once inviter.invite_user(:email => "ian@example.com", :aspect_id => aspect.id) end it 'adds the inviter to the invited_user' do + pending invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id) invited_user.reload invited_user.inviters.include?(inviter).should be_true @@ -50,12 +54,14 @@ describe User do it 'adds a pending request to the invited user' do + pending invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id) invited_user.reload invited_user.pending_requests.find_by_callback_url(inviter.receive_url).nil?.should == false end it 'adds a pending request to the inviter' do + pending inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id) inviter.reload inviter.pending_requests.find_by_callback_url(inviter.receive_url).nil?.should == false @@ -64,6 +70,7 @@ describe User do context "limit on invites" do it 'does not invite users after 3 invites' do + pending inviter_with_3_invites.invite_user(:email => "email1@example.com", :aspect_id => aspect2.id) inviter_with_3_invites.invite_user(:email => "email2@example.com", :aspect_id => aspect2.id) inviter_with_3_invites.invite_user(:email => "email3@example.com", :aspect_id => aspect2.id) @@ -71,13 +78,16 @@ describe User do end it 'does not invite people I already invited' do + pending inviter_with_3_invites.invite_user(:email => "email1@example.com", :aspect_id => aspect2.id) proc{inviter_with_3_invites.invite_user(:email => "email1@example.com", :aspect_id => aspect2.id)}.should raise_error /You already invited this person/ end end + context "the acceptance of an invitation" do it "should create the person with the passed in params" do + pending person_count = Person.count u = invited_user1.accept_invitation!(:invitation_token => "abc", :username => "user", @@ -90,6 +100,7 @@ describe User do end it 'should auto accept the request for the sender into the right aspect' do + pending u = invited_user2.accept_invitation!(:invitation_token => invited_user2.invitation_token, :username => "user", :password => "secret", @@ -106,8 +117,6 @@ describe User do inviter.friends.include?(u.person).should be true end end - - end def create_user_with_invitation(invitation_token, attributes={}) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cf7c4c51a..5296fbeaf 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -5,36 +5,77 @@ require 'spec_helper' describe User do - let(:user) { Factory(:user) } + let(:user) { Factory(:user) } let(:aspect) { user.aspect(:name => 'heroes') } - let(:user2) { Factory(:user) } + let(:user2) { Factory(:user) } let(:aspect2) { user2.aspect(:name => 'stuff') } - let(:user3) { Factory(:user) } + let(:user3) { Factory(:user) } let(:aspect3) { user3.aspect(:name => 'stuff') } - describe "validations" do - it "downcases the username" do - user = Factory.build(:user, :username => "ALLUPPERCASE") - user.valid? - user.username.should == "alluppercase" + describe "validation" do + describe "of passwords" do + it "fails if password doesn't match confirmation" do + user = Factory.build(:user, :password => "password", :password_confirmation => "nope") + user.should_not be_valid + end - user = Factory.build(:user, :username => "someUPPERCASE") - user.valid? - user.username.should == "someuppercase" + it "succeeds if password matches confirmation" do + user = Factory.build(:user, :password => "password", :password_confirmation => "password") + user.should be_valid + end end - it "confirms the password" do - pending "I cannot figure out why this doesn't work. --Raphael" - user = User.instantiate!( - :email => "tom@tom.joindiaspora.com", - :username => "tom", - :password => "evankorth", - :password_confirmation => "potatoes", - :person => Person.new( - :profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" )) - ) - user.created_at.should be_nil - user.valid?.should be_false + describe "of username" do + it "requires presence" do + user = Factory.build(:user, :username => nil) + user.should_not be_valid + end + + it "requires uniqueness" do + duplicate_user = Factory.build(:user, :username => user.username) + duplicate_user.should_not be_valid + end + + it "keeps the original case" do + user = Factory.build(:user, :username => "WeIrDcAsE") + user.should be_valid + user.username.should == "WeIrDcAsE" + end + + it "fails if the requested username is only different in case from an existing username" do + duplicate_user = Factory.build(:user, :username => user.username.upcase) + duplicate_user.should_not be_valid + end + + it "strips leading and trailing whitespace" do + user = Factory.build(:user, :username => " janie ") + user.should be_valid + user.username.should == "janie" + end + + it "fails if there's whitespace in the middle" do + user = Factory.build(:user, :username => "bobby tables") + user.should_not be_valid + end + end + + describe "of email" do + it "requires email address" do + user = Factory.build(:user, :email => nil) + user.should_not be_valid + end + + it "requires a unique email address" do + duplicate_user = Factory.build(:user, :email => user.email) + duplicate_user.should_not be_valid + end + end + end + + describe ".find_for_authentication" do + it "preserves case" do + User.find_for_authentication(:username => user.username).should == user + User.find_for_authentication(:username => user.username.upcase).should be_nil end end @@ -46,10 +87,10 @@ describe User do context 'profiles' do it 'should be able to update their profile and send it to their friends' do - updated_profile = { :profile => { - :first_name => 'bob', - :last_name => 'billytown', - :image_url => "http://clown.com"} } + updated_profile = {:profile => { + :first_name => 'bob', + :last_name => 'billytown', + :image_url => "http://clown.com"}} user.update_profile(updated_profile).should be true user.profile.image_url.should == "http://clown.com" @@ -66,7 +107,7 @@ describe User do it 'should not delete an aspect with friends' do friend_users(user, aspect, user2, aspect2) aspect.reload - proc{user.drop_aspect(aspect)}.should raise_error /Aspect not empty/ + proc { user.drop_aspect(aspect) }.should raise_error /Aspect not empty/ user.aspects.include?(aspect).should == true end end @@ -76,27 +117,27 @@ describe User do friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user3, aspect3) end - + it 'should unfriend everyone' do user.should_receive(:unfriend_everyone) user.destroy end - + it 'should remove person' do user.should_receive(:remove_person) user.destroy end - + it 'should remove all aspects' do pending "this should use :dependant => :destroy on the many assoc...but that screws this test suite..." aspects = user.aspects user.destroy - proc{ aspects.reload }.should raise_error /does not exist/ + proc { aspects.reload }.should raise_error /does not exist/ end - + describe '#remove_person' do it 'should remove the person object' do person = user.person @@ -109,7 +150,7 @@ describe User do message = user.post(:status_message, :message => "hi", :to => aspect.id) user.reload user.destroy - proc{ message.reload }.should raise_error /does not exist/ + proc { message.reload }.should raise_error /does not exist/ end end @@ -124,7 +165,7 @@ describe User do user.destroy end - it 'should unfriend local people' do + it 'should unfriend local people' do user2.friends.count.should be 1 user.destroy user2.reload