Skip to content
Extraits de code Groupes Projets
Valider 3376057c rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Merge branch 'master' of github.com:diaspora/diaspora_rails

parents f4bace85 11a09991
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Affichage de
avec 118 ajouts et 37 suppressions
source 'http://rubygems.org' source 'http://rubygems.org'
source 'http://gemcutter.org' source 'http://gemcutter.org'
gem 'rails', '3.0.0.beta4' gem 'rails', '3.0.0.rc'
gem 'bundler', '0.9.26' gem 'bundler', '1.0.0.rc.1'
#Security #Security
gem 'gpgme' gem 'gpgme'
......
...@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base ...@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery :except => :receive protect_from_forgery :except => :receive
layout 'application' layout 'application'
before_filter :set_friends_and_authors, :count_requests before_filter :set_friends_authors_and_status, :count_requests
layout :layout_by_resource layout :layout_by_resource
...@@ -16,9 +16,11 @@ class ApplicationController < ActionController::Base ...@@ -16,9 +16,11 @@ class ApplicationController < ActionController::Base
end end
end end
def set_friends_and_authors def set_friends_authors_and_status
@friends = Person.friends.all if current_user @friends = Person.friends.all if current_user
@subscribed_persons = Author.all if current_user @subscribed_persons = Author.all if current_user
@latest_status_message = StatusMessage.newest(current_user) if current_user
end end
def count_requests def count_requests
......
...@@ -4,12 +4,10 @@ class DashboardsController < ApplicationController ...@@ -4,12 +4,10 @@ class DashboardsController < ApplicationController
def index def index
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC' @posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
@latest_status_message = StatusMessage.newest(current_user)
end end
def ostatus def ostatus
@posts = OstatusPost.paginate :page => params[:page], :order => 'created_at DESC' @posts = OstatusPost.paginate :page => params[:page], :order => 'created_at DESC'
@latest_status_message = StatusMessage.newest(current_user)
render :index render :index
end end
......
...@@ -17,9 +17,8 @@ class UsersController < ApplicationController ...@@ -17,9 +17,8 @@ class UsersController < ApplicationController
def update def update
@user = User.where(:id => params[:id]).first @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." flash[:notice] = "Successfully updated user."
redirect_to @user redirect_to @user
else else
......
module StatusMessagesHelper module StatusMessagesHelper
def my_latest_message def my_latest_message
message = @latest_status_message unless @latest_status_message.nil?
unless message.nil? return @latest_status_message.message
return message.message#+ " - " + how_long_ago(message)
else else
return "No message to display." return "No message to display."
end end
end end
end end
...@@ -26,9 +26,13 @@ class Photo < Post ...@@ -26,9 +26,13 @@ class Photo < Post
after_save :log_save_inspection after_save :log_save_inspection
validates_true_for :album_id, :logic => lambda {self.validate_album_person} validates_true_for :album_id, :logic => lambda {self.validate_album_person}
before_destroy :ensure_user_picture
def validate_album_person def validate_album_person
album.person_id == person_id album.person_id == person_id
end end
def remote_photo def remote_photo
@remote_photo ||= User.owner.url.chop + image.url(:scaled_full) @remote_photo ||= User.owner.url.chop + image.url(:scaled_full)
end end
...@@ -40,4 +44,11 @@ class Photo < Post ...@@ -40,4 +44,11 @@ class Photo < Post
image.store! image.store!
Rails.logger.info("Setting remote photo with id #{id}") Rails.logger.info("Setting remote photo with id #{id}")
end 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 end
class Post class Post
require 'lib/encryptable'
include MongoMapper::Document include MongoMapper::Document
include ApplicationHelper include ApplicationHelper
include ROXML include ROXML
......
class Profile class Profile
include MongoMapper::EmbeddedDocument include MongoMapper::EmbeddedDocument
require 'lib/diaspora/webhooks'
include Diaspora::Webhooks
include ROXML include ROXML
xml_reader :person_id
xml_accessor :first_name xml_accessor :first_name
xml_accessor :last_name xml_accessor :last_name
xml_accessor :image_url xml_accessor :image_url
key :first_name, String key :first_name, String
key :last_name, String key :last_name, String
...@@ -20,5 +24,12 @@ class Profile ...@@ -20,5 +24,12 @@ class Profile
# self.image_url = self._parent_document.url + self.image_url # self.image_url = self._parent_document.url + self.image_url
# end # end
# end # end
def person_id
self._parent_document.id
end
def to_diaspora_xml
self.to_xml.to_s
end
end end
...@@ -28,6 +28,17 @@ class User < Person ...@@ -28,6 +28,17 @@ class User < Person
end end
false false
end 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 ######### Friend Requesting
def send_friend_request_to(friend_url) def send_friend_request_to(friend_url)
......
%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
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
= link_to '⇧ ostatus', ostatus_path = link_to '⇧ ostatus', ostatus_path
= "#{@author.username}'s stream" = "#{@author.username}'s stream"
.sub_header
= @author.profile_url
- if @author_ostatus_posts - if @author_ostatus_posts
%ul#stream %ul#stream
- for post in @author_ostatus_posts - for post in @author_ostatus_posts
......
...@@ -50,6 +50,8 @@ ...@@ -50,6 +50,8 @@
= link_to current_user.real_name, root_path = link_to current_user.real_name, root_path
%span#latest_message %span#latest_message
= my_latest_message = my_latest_message
%span{:style => "font-size: small"}
= " - #{how_long_ago @latest_status_message}"
%ul.nav %ul.nav
%li= link_to "home", root_path %li= link_to "home", root_path
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
%p %p
%label{:for => "status_message_message"} Message %label{:for => "status_message_message"} Message
= f.text_area :message, :rows => 2 = f.text_area :message, :rows => 2
%p %p.right
= f.submit "Post" = f.submit "Post"
= form_for Bookmark.new, :remote => true do |f| = form_for Bookmark.new, :remote => true do |f|
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
%p %p
%label{:for => "bookmark_link"} Link %label{:for => "bookmark_link"} Link
= f.text_field :link = f.text_field :link
%p %p.right
= f.submit "Post" = f.submit "Post"
= form_for Blog.new, :remote => true do |f| = form_for Blog.new, :remote => true do |f|
...@@ -32,5 +32,5 @@ ...@@ -32,5 +32,5 @@
%p %p
%label{:for => "blog_body"} Body %label{:for => "blog_body"} Body
= f.text_area :body = f.text_area :body
%p %p.right
= f.submit "Post" = f.submit "Post"
module Diaspora module Diaspora
module Webhooks module Webhooks
def self.included(klass) def self.included(klass)
klass.class_eval do klass.class_eval do
#require 'message_handler' require 'message_handler'
@@queue = MessageHandler.new @@queue = MessageHandler.new
def notify_people def notify_people
...@@ -10,6 +12,10 @@ module Diaspora ...@@ -10,6 +12,10 @@ module Diaspora
push_to(people_with_permissions) push_to(people_with_permissions)
end end
end end
def notify_people!
push_to(people_with_permissions)
end
def subscribe_to_ostatus(feed_url) def subscribe_to_ostatus(feed_url)
@@queue.add_subscription_request(feed_url) @@queue.add_subscription_request(feed_url)
...@@ -54,6 +60,7 @@ module Diaspora ...@@ -54,6 +60,7 @@ module Diaspora
[*posts].each {|x| xml << x.to_diaspora_xml} [*posts].each {|x| xml << x.to_diaspora_xml}
xml += "</posts>" xml += "</posts>"
xml += "</XML>" xml += "</XML>"
end end
end end
end end
......
...@@ -46,7 +46,7 @@ class MessageHandler ...@@ -46,7 +46,7 @@ class MessageHandler
case query.type case query.type
when :post when :post
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
http.callback { puts query.destination; process; process} http.callback { process; process}
when :get when :get
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
http.callback {send_to_seed(query, http.response); process} http.callback {send_to_seed(query, http.response); process}
......
...@@ -174,6 +174,9 @@ form { ...@@ -174,6 +174,9 @@ form {
#user_name #latest_message { #user_name #latest_message {
font-weight: normal; font-weight: normal;
color: #999999; } color: #999999; }
#user_name #latest_message span {
size: small;
font-style: italic; }
#user_name ul { #user_name ul {
display: inline; display: inline;
margin: 0; margin: 0;
......
...@@ -209,6 +209,9 @@ form ...@@ -209,6 +209,9 @@ form
:font :font
:weight normal :weight normal
:color #999 :color #999
span
:size small
:font-style italic
ul ul
:display inline :display inline
......
...@@ -25,8 +25,7 @@ describe Photo do ...@@ -25,8 +25,7 @@ describe Photo do
binary.should == fixture_binary binary.should == fixture_binary
end end
it 'must have an album' do it 'must have an album' do
photo = Photo.new(:person => @user) photo = Photo.new(:person => @user)
photo.image = File.open(@fixture_name) photo.image = File.open(@fixture_name)
photo.save photo.save
...@@ -36,6 +35,18 @@ describe Photo do ...@@ -36,6 +35,18 @@ describe Photo do
Photo.first.album.name.should == 'foo' Photo.first.album.name.should == 'foo'
end 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 describe 'non-image files' do
it 'should not store' do it 'should not store' do
file = File.open(@fail_fixture_name) file = File.open(@fail_fixture_name)
...@@ -52,9 +63,6 @@ describe Photo do ...@@ -52,9 +63,6 @@ describe Photo do
@photo.image = file @photo.image = file
@photo.save.should == false @photo.save.should == false
end end
end end
describe 'with encryption' do describe 'with encryption' do
...@@ -80,12 +88,12 @@ describe Photo do ...@@ -80,12 +88,12 @@ describe Photo do
@photo.image = File.open(@fixture_name) @photo.image = File.open(@fixture_name)
@photo.image.store! @photo.image.store!
@photo.save @photo.save
xml = @photo.to_xml.to_s xml = @photo.to_xml.to_s
xml.include?("bp.jpeg").should be true xml.include?("bp.jpeg").should be true
end end
it 'should have an album id on serialization' do it 'should have an album id on serialization' do
@photo.image = File.open(@fixture_name) @photo.image = File.open(@fixture_name)
......
...@@ -59,26 +59,22 @@ describe User do ...@@ -59,26 +59,22 @@ describe User do
end end
it 'should be able to update their profile and send it to their friends' do 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)
p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}}
@user = Factory.create(:user, :profile => Profile.new(profile))
profile = {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://awesome.com"}
@user.update_profile(p).should == true
@user.update_profile(profile) @user.profile.image_url.should == "http://clown.com"
@user.profile.image_url.should == "http://awesome.com" Profile.should_receive(:build_xml_for)
#puts @user.to_xml.to_s
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 n = Profile.send :class_variable_get, :@@queue
n.should_receive(:process)
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter