diff --git a/Gemfile b/Gemfile index 7f5debe86..c87fa7348 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,8 @@ gem 'chef', '0.9.12', :require => false gem 'nokogiri', '1.4.3.1' +gem "fog" + #Security gem 'devise', '1.1.3' gem 'devise_invitable','0.3.5' diff --git a/Gemfile.lock b/Gemfile.lock index 57f1ce8e9..7c25f3f7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,6 +146,7 @@ GEM erubis (2.6.6) abstract (>= 1.0.0) eventmachine (0.12.10) + excon (0.3.4) extlib (0.9.15) factory_girl (1.3.3) factory_girl_rails (1.0.1) @@ -161,6 +162,16 @@ GEM fastthread (1.0.7) ffi (0.6.3) rake (>= 0.8.7) + fog (0.3.25) + builder + excon (>= 0.2.4) + formatador (>= 0.0.16) + json + mime-types + net-ssh (~> 2.0.23) + nokogiri (~> 1.4.3.1) + ruby-hmac + formatador (0.0.16) gem_plugin (0.2.3) gherkin (2.3.3) json (~> 1.4.6) @@ -204,6 +215,7 @@ GEM multipart-post (1.1.0) mysql2 (0.2.6) net-ldap (0.1.1) + net-ssh (2.0.23) nokogiri (1.4.3.1) oa-basic (0.1.6) multi_json (~> 0.0.2) @@ -298,6 +310,7 @@ GEM ruby-debug-base (~> 0.10.4.0) ruby-debug-base (0.10.4) linecache (>= 0.3) + ruby-hmac (0.4.0) ruby-openid (2.1.8) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) @@ -359,6 +372,7 @@ DEPENDENCIES factory_girl_rails fastercsv (= 1.5.4) haml (= 3.0.25) + fog http_accept_language! jammit (= 0.5.4) jasmine! diff --git a/app/models/photo.rb b/app/models/photo.rb index e5e8e40c3..7faff65a7 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -6,9 +6,11 @@ class Photo < Post require 'carrierwave/orm/activerecord' mount_uploader :image, ImageUploader - xml_attr :remote_photo - xml_attr :caption - xml_attr :status_message_id + xml_reader :remote_photo_path + xml_reader :remote_photo_name + + xml_reader :caption + xml_reader :status_message_id belongs_to :status_message @@ -17,7 +19,6 @@ class Photo < Post before_destroy :ensure_user_picture - #before_destroy :delete_parent_if_no_photos_or_message def ownership_of_status_message message = StatusMessage.find_by_id(self.status_message_id) if status_message_id && message @@ -33,25 +34,28 @@ class Photo < Post photo.random_string = gen_random_string(10) photo.image.store! image_file - photo - end - def remote_photo - image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url - end + unless photo.image.url.match(/^https?:\/\//) + pod_url = APP_CONFIG[:pod_url].dup + pod_url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' + remote_path = "#{pod_url}#{photo.image.url}" + else + remote_path = photo.image.url + end - def remote_photo= remote_path name_start = remote_path.rindex '/' - self.remote_photo_path = remote_path.slice(0, name_start ) - self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) + photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/" + photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) + + photo end def url(name = nil) if remote_photo_path - name = name.to_s + "_" if name - person.url.chop + remote_photo_path + "/" + name.to_s + remote_photo_name + name = name.to_s + '_' if name + remote_photo_path + name.to_s + remote_photo_name else - image.url name + image.url(name) end end @@ -71,17 +75,6 @@ class Photo < Post true end - def save_update updated_post - self.caption = updated_post.caption - self.save - end - - def absolute_url *args - pod_url = AppConfig[:pod_url].dup - pod_url.chop! if AppConfig[:pod_url][-1,1] == '/' - "#{pod_url}#{url(*args)}" - end - def self.gen_random_string(len) chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a string = "" @@ -89,10 +82,11 @@ class Photo < Post return string end + def as_json(opts={}) { - :photo => { - :id => self.id, + :photo => { + :id => self.id, :url => self.url(:thumb_medium), :thumb_small => self.url(:thumb_small), :caption => self.caption diff --git a/app/models/profile.rb b/app/models/profile.rb index 47d709e84..f0b5865e2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -56,29 +56,17 @@ class Profile < ActiveRecord::Base def image_url= url return image_url if url == '' - if url.nil? || url.match(/^https?:\/\//) - super(url) - else - super(absolutify_local_url(url)) - end + super(url) end def image_url_small= url return image_url if url == '' - if url.nil? || url.match(/^https?:\/\//) - super(url) - else - super(absolutify_local_url(url)) - end + super(url) end def image_url_medium= url return image_url if url == '' - if url.nil? || url.match(/^https?:\/\//) - super(url) - else - super(absolutify_local_url(url)) - end + super(url) end def date= params @@ -98,10 +86,4 @@ class Profile < ActiveRecord::Base self.last_name.strip! if self.last_name end - private - def absolutify_local_url url - pod_url = AppConfig[:pod_url].dup - pod_url.chop! if AppConfig[:pod_url][-1,1] == '/' - "#{pod_url}#{url}" - end end diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 000000000..30dcd4324 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,10 @@ +test: + adapter: mysql2 + database: diaspora_test + user: root + password: password +development: + adapter: mysql2 + database: diaspora_development + user: root + password: password diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 0451db212..d8d555df7 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -3,11 +3,11 @@ # the COPYRIGHT file. CarrierWave.configure do |config| - if ENV['S3_KEY'] && ENV['S3_SECRET'] && ENV['S3_BUCKET'] + if APP_CONFIG[:s3_key] && APP_CONFIG[:s3_secret] && APP_CONFIG[:s3_bucket] config.storage = :s3 - config.s3_access_key_id = ENV['S3_KEY'] - config.s3_secret_access_key = ENV['S3_SECRET'] - config.s3_bucket = ENV['S3_BUCKET'] + config.s3_access_key_id = APP_CONFIG[:s3_key] + config.s3_secret_access_key = APP_CONFIG[:s3_secret] + config.s3_bucket = APP_CONFIG[:s3_bucket] config.cache_dir = "#{Rails.root}/tmp/uploads" else config.storage = :file diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index c628514ae..d2aa63572 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -54,7 +54,13 @@ describe Photo do photo.created_at.nil?.should be_true photo.image.read.nil?.should be_false end - + it 'sets a remote url' do + image = File.open(@fixture_name) + photo = Photo.instantiate( + :person => @user.person, :user_file => image) + photo.remote_photo_path.should include("http") + photo.remote_photo_name.should include(".png") + end end it 'should save a photo' do @@ -82,7 +88,7 @@ describe Photo do it 'should remove its reference in user profile if it is referred' do @photo.save - @user.profile.image_url = @photo.image.url(:thumb_large) + @user.profile.image_url = @photo.url(:thumb_large) @user.person.save @photo.destroy Person.find(@user.person.id).profile.image_url.should be_nil @@ -111,7 +117,8 @@ describe Photo do @xml = @photo.to_xml.to_s end it 'serializes the url' do - @xml.include?(@photo.image.url).should be true + @xml.include?(@photo.remote_photo_path).should be true + @xml.include?(@photo.remote_photo_name).should be true end it 'serializes the diaspora_handle' do @xml.include?(@user.diaspora_handle).should be true diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 3695223f2..863785126 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -52,18 +52,16 @@ describe Profile do lambda {@profile.image_url = ""}.should_not change(@profile, :image_url) end it 'makes relative urls absolute' do - @profile.image_url = "/relative/url" - @profile.image_url.should == "#{@pod_url}/relative/url" - end - it "doesn't change absolute urls" do - @profile.image_url = "http://not/a/relative/url" - @profile.image_url.should == "http://not/a/relative/url" + @profile.image_url = @photo.url(:thumb_large) + + @profile.image_url.should == @photo.url(:thumb_large) end end - describe 'serialization' do - it "includes the person's diaspora handle if it doesn't have one" do - person = Factory(:person, :diaspora_handle => "foobar") + let(:person) {Factory.create(:person)} + + it 'should include persons diaspora handle' do + xml = person.profile.to_diaspora_xml xml = person.profile.to_diaspora_xml xml.should include "foobar" end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bcb56d95c..a7df19be0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -288,9 +288,9 @@ describe User do end it 'updates image_url' do user.update_profile(@params).should be_true - user.reload.profile.image_url.should == @photo.absolute_url(:thumb_large) - user.profile.image_url_medium.should == @photo.absolute_url(:thumb_medium) - user.profile.image_url_small.should == @photo.absolute_url(:thumb_small) + user.reload.profile.image_url.should == @photo.url(:thumb_large) + user.profile.image_url_medium.should == @photo.url(:thumb_medium) + user.profile.image_url_small.should == @photo.url(:thumb_small) end it 'unpends the photo' do @photo.pending = true