From 049361ea1539d3ae5351a7a3fb408623ee9d3b17 Mon Sep 17 00:00:00 2001 From: maxwell Date: Wed, 28 Jul 2010 18:32:00 -0700 Subject: [PATCH 1/7] MS profiles should send, need to just make the parser now --- app/controllers/users_controller.rb | 3 +-- app/models/profile.rb | 11 +++++++++++ app/models/user.rb | 11 +++++++++++ lib/diaspora/webhooks.rb | 8 ++++++++ lib/message_handler.rb | 2 +- spec/models/user_spec.rb | 28 ++++++++++++---------------- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a9adbf346..9b4411c7a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -17,9 +17,8 @@ class UsersController < ApplicationController def update @user = User.where(:id => params[:id]).first - puts params.inspect - if @user.update_attributes(params[:user]) + if @user.update_profile(params[:user]) flash[:notice] = "Successfully updated user." redirect_to @user else diff --git a/app/models/profile.rb b/app/models/profile.rb index 934c46f93..8243268be 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,10 +1,14 @@ class Profile include MongoMapper::EmbeddedDocument + require 'lib/diaspora/webhooks' + include Diaspora::Webhooks include ROXML + xml_reader :person_id xml_accessor :first_name xml_accessor :last_name xml_accessor :image_url + key :first_name, String key :last_name, String @@ -20,5 +24,12 @@ class Profile # self.image_url = self._parent_document.url + self.image_url # end # end + def person_id + self._parent_document.id + end + + def to_diaspora_xml + self.to_xml.to_s + end end diff --git a/app/models/user.rb b/app/models/user.rb index bd8dcdc52..a7326c18a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -28,6 +28,17 @@ class User < Person end false end + + ##profile + def update_profile(params) + if self.update_attributes(params) + puts self.profile.class + self.profile.notify_people! + true + else + false + end + end ######### Friend Requesting def send_friend_request_to(friend_url) diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index b87f7e784..fc20841a4 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -10,6 +10,10 @@ module Diaspora push_to(people_with_permissions) end end + + def notify_people! + push_to(people_with_permissions) + end def subscribe_to_ostatus(feed_url) @@queue.add_subscription_request(feed_url) @@ -22,9 +26,12 @@ module Diaspora end def push_to(recipients) + puts "FOOBATT" @@queue.add_hub_notification(APP_CONFIG[:pubsub_server], User.owner.url + self.class.to_s.pluralize.underscore + '.atom') unless recipients.empty? recipients.map!{|x| x = x.url + "receive/"} + puts self.class + puts "made it in here!" xml = self.class.build_xml_for(self) Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}") @@queue.add_post_request( recipients, xml ) @@ -54,6 +61,7 @@ module Diaspora [*posts].each {|x| xml << x.to_diaspora_xml} xml += "" xml += "" + end end end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index a1d5702f2..8d35cb1f3 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -46,7 +46,7 @@ class MessageHandler case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} - http.callback { puts query.destination; process; process} + http.callback { puts query.destination; puts query.body; process; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 04c4f44a9..b767db3b6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -59,26 +59,22 @@ describe User do end it 'should be able to update their profile and send it to their friends' do - pending + Factory.create(:person) + p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"}} - profile = {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"} - - @user = Factory.create(:user, :profile => Profile.new(profile)) - profile = {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://awesome.com"} + @user = Factory.create(:user) + p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} - @user.update_profile(profile) + @user.update_profile(p).should == true - @user.profile.image_url.should == "http://awesome.com" - #puts @user.to_xml.to_s + @user.profile.image_url.should == "http://clown.com" + + Profile.should_receive(:build_xml_for) + + n = Profile.send :class_variable_get, :@@queue + n.should_receive(:process) end - - it 'should fix the image_url 'do - pending - profile = Profile.new(:image_url => "/images/foo.jpg") - user = Factory.create(:user, :profile => profile) - - puts user.profile.image_url - end + end From c8b40001e592fdbd4207130750ceba7ac3182e20 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 28 Jul 2010 21:10:35 -0700 Subject: [PATCH 2/7] IZ album edit page was not added --- app/views/albums/edit.html.haml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/views/albums/edit.html.haml diff --git a/app/views/albums/edit.html.haml b/app/views/albums/edit.html.haml new file mode 100644 index 000000000..3843685e0 --- /dev/null +++ b/app/views/albums/edit.html.haml @@ -0,0 +1,25 @@ +%h1.big_text + .back + = link_to "⇧ #{@album.name}", @album + + = "Editing #{@album.name}" + +.sub_header + ="updated #{how_long_ago(@album)}" + +- form_for @album do |a| + = a.error_messages + %p + = a.text_field :name + + #submit_block + = link_to "Cancel", root_path + or + = a.submit + +.button.delete + = link_to 'Delete Album', @album, :confirm => 'Are you sure?', :method => :delete + +#content_bottom + .back + = link_to "⇧ #{@album.name}", @album From 7a0db375abc5ae6d0469b4f3501701a09a840f63 Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 29 Jul 2010 09:59:03 -0700 Subject: [PATCH 3/7] MS added rails 3rc --- Gemfile | 4 ++-- app/controllers/application_controller.rb | 6 ++++-- app/controllers/dashboards_controller.rb | 2 -- app/helpers/status_messages_helper.rb | 7 ++++--- app/models/post.rb | 1 + app/views/layouts/application.html.haml | 2 ++ app/views/shared/_publisher.haml | 6 +++--- lib/diaspora/webhooks.rb | 4 +++- public/stylesheets/application.css | 3 +++ public/stylesheets/sass/application.sass | 3 +++ 10 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 06598a446..441e441a3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'http://rubygems.org' source 'http://gemcutter.org' -gem 'rails', '3.0.0.beta4' -gem 'bundler', '0.9.26' +gem 'rails', '3.0.0.rc' +gem 'bundler', '1.0.0.rc.1' #Security gem 'gpgme' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4a33a2b42..a2a4ee3b5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery :except => :receive layout 'application' - before_filter :set_friends_and_authors, :count_requests + before_filter :set_friends_authors_and_status, :count_requests layout :layout_by_resource @@ -16,9 +16,11 @@ class ApplicationController < ActionController::Base end end - def set_friends_and_authors + def set_friends_authors_and_status @friends = Person.friends.all if current_user @subscribed_persons = Author.all if current_user + @latest_status_message = StatusMessage.newest(current_user) if current_user + end def count_requests diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index e09e182f8..414f5956a 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -4,12 +4,10 @@ class DashboardsController < ApplicationController def index @posts = Post.paginate :page => params[:page], :order => 'created_at DESC' - @latest_status_message = StatusMessage.newest(current_user) end def ostatus @posts = OstatusPost.paginate :page => params[:page], :order => 'created_at DESC' - @latest_status_message = StatusMessage.newest(current_user) render :index end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 522b990a4..57d0f2f17 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -1,12 +1,13 @@ module StatusMessagesHelper def my_latest_message - message = @latest_status_message - unless message.nil? - return message.message#+ " - " + how_long_ago(message) + unless @latest_status_message.nil? + return @latest_status_message.message else return "No message to display." end end + + end diff --git a/app/models/post.rb b/app/models/post.rb index 1be97bd05..f270666fa 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,4 +1,5 @@ class Post + require 'lib/encryptable' include MongoMapper::Document include ApplicationHelper include ROXML diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a567062a5..36ebdbc8c 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -50,6 +50,8 @@ = link_to current_user.real_name, root_path %span#latest_message = my_latest_message + %span{:style => "font-size: small"} + = " - #{how_long_ago @latest_status_message}" %ul.nav %li= link_to "home", root_path diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 2ac0bcc65..bd43ee7cb 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -10,7 +10,7 @@ %p %label{:for => "status_message_message"} Message = f.text_area :message, :rows => 2 - %p + %p.right = f.submit "Post" = form_for Bookmark.new, :remote => true do |f| @@ -21,7 +21,7 @@ %p %label{:for => "bookmark_link"} Link = f.text_field :link - %p + %p.right = f.submit "Post" = form_for Blog.new, :remote => true do |f| @@ -32,5 +32,5 @@ %p %label{:for => "blog_body"} Body = f.text_area :body - %p + %p.right = f.submit "Post" diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index fc20841a4..c303fa5a7 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -1,8 +1,10 @@ + module Diaspora module Webhooks def self.included(klass) klass.class_eval do - #require 'message_handler' + require 'message_handler' + @@queue = MessageHandler.new def notify_people diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index c0467eeea..c50e1e9ff 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -174,6 +174,9 @@ form { #user_name #latest_message { font-weight: normal; color: #999999; } + #user_name #latest_message span { + size: small; + font-style: italic; } #user_name ul { display: inline; margin: 0; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 408841d47..3490e3b39 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -209,6 +209,9 @@ form :font :weight normal :color #999 + span + :size small + :font-style italic ul :display inline From 2040c0d347f9f704bd5222e082fdee511fcab7fe Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 29 Jul 2010 10:05:02 -0700 Subject: [PATCH 4/7] MS fixed lots of debug messages --- gpg/diaspora-test/pubring.gpg | Bin 37991 -> 37991 bytes gpg/diaspora-test/trustdb.gpg | Bin 1680 -> 1680 bytes lib/diaspora/webhooks.rb | 3 --- lib/message_handler.rb | 2 +- 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/gpg/diaspora-test/pubring.gpg b/gpg/diaspora-test/pubring.gpg index edac5d95b216f263b94be3fe285f4da92da09f51..cabfdca741cbcbb6b7cfde5479c8b8e068be8eb6 100644 GIT binary patch delta 19 bcmaF9g6a7RrVUw&n;q@dLN})=UY7*`T5SkA delta 19 bcmaF9g6a7RrVUw&o2Qgrmff7Ds1*tTVOa>o diff --git a/gpg/diaspora-test/trustdb.gpg b/gpg/diaspora-test/trustdb.gpg index 87e4dbb8a4fa7498184172b4162397f70d2ff066..0302183a535bb58ef9d7bfba3c53bab87275b43f 100644 GIT binary patch delta 28 jcmbQhJAqe#F})z2nVFH5k%581CvfxOiGku9)ic=uTHXfg delta 28 jcmbQhJAqe#F})z2nVFH5k%581CtzFb#6aX~c+SHA{^ diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index c303fa5a7..c73530d11 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -28,12 +28,9 @@ module Diaspora end def push_to(recipients) - puts "FOOBATT" @@queue.add_hub_notification(APP_CONFIG[:pubsub_server], User.owner.url + self.class.to_s.pluralize.underscore + '.atom') unless recipients.empty? recipients.map!{|x| x = x.url + "receive/"} - puts self.class - puts "made it in here!" xml = self.class.build_xml_for(self) Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}") @@queue.add_post_request( recipients, xml ) diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 8d35cb1f3..3e76c2783 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -46,7 +46,7 @@ class MessageHandler case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} - http.callback { puts query.destination; puts query.body; process; process} + http.callback { process; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} From e185498c4ea3ba76c7ac28a19bb560023d03b8e7 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 29 Jul 2010 10:14:35 -0700 Subject: [PATCH 5/7] Fixing keyring --- gpg/diaspora-test/pubring.gpg | Bin 37991 -> 37991 bytes gpg/diaspora-test/trustdb.gpg | Bin 1680 -> 1680 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/gpg/diaspora-test/pubring.gpg b/gpg/diaspora-test/pubring.gpg index cabfdca741cbcbb6b7cfde5479c8b8e068be8eb6..edac5d95b216f263b94be3fe285f4da92da09f51 100644 GIT binary patch delta 19 bcmaF9g6a7RrVUw&o2Qgrmff7Ds1*tTVOa>o delta 19 bcmaF9g6a7RrVUw&n;q@dLN})=UY7*`T5SkA diff --git a/gpg/diaspora-test/trustdb.gpg b/gpg/diaspora-test/trustdb.gpg index 0302183a535bb58ef9d7bfba3c53bab87275b43f..87e4dbb8a4fa7498184172b4162397f70d2ff066 100644 GIT binary patch delta 28 jcmbQhJAqe#F})z2nVFH5k%581CtzFb#6aX~c+SHA{^ delta 28 jcmbQhJAqe#F})z2nVFH5k%581CvfxOiGku9)ic=uTHXfg From fd4475370dcb323d3b3ff0f68d6a6e0e52bea7f1 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Thu, 29 Jul 2010 10:30:24 -0700 Subject: [PATCH 6/7] added profile url to author show page --- app/views/authors/show.html.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/authors/show.html.haml b/app/views/authors/show.html.haml index 4ee71a7c8..89b6cd165 100644 --- a/app/views/authors/show.html.haml +++ b/app/views/authors/show.html.haml @@ -3,6 +3,9 @@ = link_to '⇧ ostatus', ostatus_path = "#{@author.username}'s stream" +.sub_header + = @author.profile_url + - if @author_ostatus_posts %ul#stream - for post in @author_ostatus_posts From 11a099914cd6b959a30acb2981b681ac73ce1264 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Thu, 29 Jul 2010 11:07:44 -0700 Subject: [PATCH 7/7] on photo delete, photo checks to see if it is set in user profile. if it is, profile is edited. --- app/models/photo.rb | 11 +++++++++++ spec/models/photo_spec.rb | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index f52dc0d1c..3498a2e3b 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -26,9 +26,13 @@ class Photo < Post after_save :log_save_inspection validates_true_for :album_id, :logic => lambda {self.validate_album_person} + before_destroy :ensure_user_picture + + def validate_album_person album.person_id == person_id end + def remote_photo @remote_photo ||= User.owner.url.chop + image.url(:scaled_full) end @@ -40,4 +44,11 @@ class Photo < Post image.store! Rails.logger.info("Setting remote photo with id #{id}") end + + def ensure_user_picture + user = User.owner + if user.profile.image_url == image.url(:thumb_medium) + user.profile.update_attributes!(:image_url => nil) + end + end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 5eb9ea805..3646d0626 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -25,8 +25,7 @@ describe Photo do binary.should == fixture_binary end - it 'must have an album' do - + it 'must have an album' do photo = Photo.new(:person => @user) photo.image = File.open(@fixture_name) photo.save @@ -36,6 +35,18 @@ describe Photo do Photo.first.album.name.should == 'foo' end + it 'should remove its reference in user profile if it is referred' do + @photo.image.store! File.open(@fixture_name) + @photo.save + + @user.profile.image_url = @photo.image.url(:thumb_medium) + @user.save + + User.first.profile.image_url.should == @photo.image.url(:thumb_medium) + @photo.destroy + User.first.profile.image_url.should be nil + end + describe 'non-image files' do it 'should not store' do file = File.open(@fail_fixture_name) @@ -52,9 +63,6 @@ describe Photo do @photo.image = file @photo.save.should == false end - - - end describe 'with encryption' do @@ -80,12 +88,12 @@ describe Photo do @photo.image = File.open(@fixture_name) @photo.image.store! @photo.save - xml = @photo.to_xml.to_s xml.include?("bp.jpeg").should be true end + it 'should have an album id on serialization' do @photo.image = File.open(@fixture_name)