diff --git a/.gitignore b/.gitignore index 89b33da60..0025a86f5 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ gpg/diaspora-production/*.gpg gpg/*/random_seed public/uploads/* .rvmrc +config/app_config.yml diff --git a/app/models/user.rb b/app/models/user.rb index 4e9e968ca..06652a494 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,20 +103,41 @@ class User aspect_ids = options.delete(:to) end - aspect_ids = [aspect_ids.to_s] if aspect_ids.is_a? BSON::ObjectId + aspect_ids = validate_aspect_permissions(aspect_ids) - raise ArgumentError.new("You must post to someone.") if aspect_ids.nil? || aspect_ids.empty? - aspect_ids.each{ |aspect_id| - raise ArgumentError.new("Cannot post to an aspect you do not own.") unless aspect_id == "all" || self.aspects.find(aspect_id) } + intitial_post(class_name, aspect_ids, options) + end + + def intitial_post(class_name, aspect_ids, options = {}) post = build_post(class_name, options) - post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) push_to_aspects(post, aspect_ids) + post + end + def repost( post, options = {} ) + aspect_ids = validate_aspect_permissions(options[:to]) + push_to_aspects(post, aspect_ids) post end + def validate_aspect_permissions(aspect_ids) + aspect_ids = [aspect_ids.to_s] if aspect_ids.is_a? BSON::ObjectId + + if aspect_ids.nil? || aspect_ids.empty? + raise ArgumentError.new("You must post to someone.") + end + + aspect_ids.each do |aspect_id| + unless aspect_id == "all" || self.aspects.find(aspect_id) + raise ArgumentError.new("Cannot post to an aspect you do not own.") + end + end + + aspect_ids + end + def build_post( class_name, options = {}) options[:person] = self.person model_class = class_name.to_s.camelize.constantize @@ -221,7 +242,7 @@ class User ###Helpers############ def self.instantiate!( opts = {} ) - opts[:person][:diaspora_handle] = "#{opts[:username]}@#{terse_url}" + opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" opts[:person][:url] = APP_CONFIG[:pod_url] opts[:person][:serialized_key] = generate_key User.create(opts) diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 880d25ef4..cb578c590 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -17,11 +17,11 @@ %h3 Picture %div#image_picker - = p.hidden_field :image_url, :value => (@profile.image_url.sub(APP_CONFIG[:pod_url],'/') if @profile.image_url), :id => 'image_url_field' + = p.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' - unless @photos.nil? || @photos.empty? - for photo in @photos - - if @profile.image_url && (photo.url(:thumb_medium) == @profile.image_url.sub(APP_CONFIG[:pod_url],'/')) + - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} = check_box_tag 'checked_photo', true, true = link_to image_tag(photo.url(:thumb_medium)), "#" diff --git a/config/app_config.yml b/config/app_config_example.yml similarity index 100% rename from config/app_config.yml rename to config/app_config_example.yml diff --git a/config/deploy.rb b/config/deploy.rb index c84d25556..2f8065134 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -53,6 +53,11 @@ namespace :deploy do run "ln -s -f #{shared_path}/bundle #{current_path}/vendor/bundle" end + task :symlink_config do + run "touch #{shared_path}/app_config.yml" + run "ln -s -f #{shared_path}/app_config.yml #{current_path}/config/app_config.yml" + end + task :start do start_mongo start_thin @@ -150,4 +155,4 @@ namespace :db do end -after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle" +after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle", 'deploy:symlink_config' diff --git a/config/initializers/_load_app_config.rb b/config/initializers/_load_app_config.rb index ac14c97d8..521f9f0a0 100644 --- a/config/initializers/_load_app_config.rb +++ b/config/initializers/_load_app_config.rb @@ -2,12 +2,25 @@ # licensed under the Affero General Public License version 3. See # the COPYRIGHT file. -raw_config = File.read("#{Rails.root}/config/app_config.yml") -all_envs = YAML.load(raw_config) -if all_envs[Rails.env] - APP_CONFIG = all_envs['default'].merge(all_envs[Rails.env]).symbolize_keys +def load_config_yaml filename + YAML.load(File.read(filename)) +end + +if File.exist? "#{Rails.root}/config/app_config.yml" + all_envs = load_config_yaml "#{Rails.root}/config/app_config.yml" + all_envs = load_config_yaml "#{Rails.root}/config/app_config_example.yml" unless all_envs +else + puts "WARNING: No config/app_config.yml found! Look at config/app_config_example.yml for help." + all_envs = load_config_yaml "#{Rails.root}/config/app_config_example.yml" +end + +if all_envs[Rails.env.to_s] + APP_CONFIG = all_envs['default'].merge(all_envs[Rails.env.to_s]).symbolize_keys else APP_CONFIG = all_envs['default'].symbolize_keys end -puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" if APP_CONFIG[:pod_url] == "http://example.org/" && Rails.env != :test +APP_CONFIG[:terse_pod_url] = APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '') +APP_CONFIG[:terse_pod_url].chop! if APP_CONFIG[:terse_pod_url][-1, 1] == '/' + +puts "WARNING: Please modify your app_config.yml to have a proper pod_url!" if APP_CONFIG[:terse_pod_url] == "example.org" && Rails.env != :test diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 67c077090..10425864b 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -7,4 +7,137 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. pt-BR: - hello: "Olá Mundo" + hello: "Olá mundo" + layouts: + application: + edit_profile: "editar perfil" + logout: "sair" + shared: + aspect_nav: + all_aspects: "Todos Aspectos" + manage: "Gerenciar" + manage_your_aspects: "Gerencie seus Aspectos" + sub_header: + all_aspects: "Todos Aspectos" + manage_aspects: "Gerenciar Aspectos" + publisher: + share: "Compartilhar" + aspect_friends: + add_friends: "adicionar amigos" + albums: + album: + you: "você" + new_album: + create: "criar" + add_a_new_album: "Adicionar novo álbum" + show: + edit_album: "Editar Álbum" + albums: "álbuns" + updated: "atualizado" + by: "por" + edit: + editing: "Editando" + updated: "atualizado" + are_you_sure: "Tem certeza?" + delete_album: "Excluir Álbum" + cancel: "Cancelar" + index: + home: "home" + new_album: "Novo Álbum" + create: + success: "Você criou com sucesso um álbum chamado %{name}." + update: + success: "O álbum %{name} foi editado com sucesso." + failure: "Erro ao editar o álbum %{name}." + destroy: + success: "O álbum %{name} foi excluído com sucesso." + aspects: + index: + photos: "photos" + show: + photos: "photos" + manage: + add_a_new_aspect: "Adicionar um novo aspecto" + add_a_new_friend: "Adicionar um novo amigo" + show: "Exibir" + update_aspects: "Atualizar Aspectos" + requests: "Solicitações" + ignore_remove: "Ignorar/Excluir" + new_aspect: + add_a_new_aspect: "Adicionar um novo aspecto" + create: "Criar" + create: + success:"Clique no mais(+) do lado esquerdo para dizer ao Diaspora quem pode ver seu novo aspecto." + users: + edit: + cancel: "Cancelar" + update_profile: "Atualizar Perfil" + home: "Home" + diaspora_username: "USUÁRIO DIASPORA" + info: "Informações" + picture: "Imagem" + editing_profile: "Editando perfil" + albums: "Álbuns" + you_dont_have_any_photos: "Você não possui nenhuma photo! Vá para" + page_to_upload_some: "para fazer o upload de alguma." + comments: + comment: + ago: "atrás" + new_comment: + comment: "Comentário" + photos: + show: + prev: "anterior" + full_size: "tamanho máximo" + next: "próxima" + edit_photo: "Editar Foto" + delete_photo: "Excluir Foto" + are_you_sure: "Tem certeza?" + comments: "comentários" + edit: + editing: "Editando" + are_you_sure: "Tem certeza?" + delete_photo: "Excluir Foto" + photo: + show_comments: "exibir comentários" + posted_a_new_photo_to: "enviada um nova foto para" + new: + new_photo: "Nova Foto" + back_to_list: "Voltar para a Lista" + post_it: "enviar!" + registrations: + new: + sign_up: "Cadastro" + status_messages: + new_status_message: + tell_me_something_good: "diga-me qualquer coisa legal" + oh_yeah: "É isso aí!" + status_message: + show_comments: "exibir comentários" + delete: "Excluir" + are_you_sure: "Tem certeza?" + show: + status_message: "Mensagem de Status" + comments: "comentários" + are_you_sure: "Tem certeza?" + destroy: "Excluir" + view_all: "Exibir Todas" + message: "Mensagem" + owner: "Pertence a" + people: + index: + add_friend: "adicionar amigo(a)" + real_name: "nome real" + diaspora_handle: "diaspora handle" + thats_you: "esse é você!" + friend_request_pending: "pedido de amizade pendente" + you_have_a_friend_request_from_this_person: "você possui um pedido de amizade dessa pessoa" + new: + new_person: "Nova Pessoa" + back_to_list: "Voltar para a Lista" + show: + last_seen: "visto pela última vez a: %{how_long_ago}" + friends_since: "amigos desde: %{how_long_ago}" + save: "salvar" + are_you_sure: "Tem certeza?" + remove_friend: "excluir amigo" diff --git a/db/seeds/backer.rb b/db/seeds/backer.rb index d39ce490c..8fa72f23d 100644 --- a/db/seeds/backer.rb +++ b/db/seeds/backer.rb @@ -35,18 +35,18 @@ def create :person => Person.new( :profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'], :image_url => "http://#{username}.joindiaspora.com/images/user/#{username}.jpg") - ) + )) user.person.save! user.aspect(:name => "Presidents") end def set_app_config username - current_config = YAML.load(Rails.root.join('config', 'app_config.yml')) - current_config[Rails.env] ||= {} - current_config[Rails.env][:pod_url] = "#{username}.joindiaspora.com" - current_config[:default][:pod_url] = "#{username}.joindiaspora.com" - file = File.new(Rails.root.join('config','app_config.yml'),'w') + current_config = YAML.load(File.read(Rails.root.join('config', 'app_config_example.yml'))) + current_config[Rails.env.to_s] ||= {} + current_config[Rails.env.to_s]['pod_url'] = "#{username}.joindiaspora.com" + current_config['default']['pod_url'] = "#{username}.joindiaspora.com" + file = File.new(Rails.root.join('..','..','shared','app_config.yml'),'w') file.write(current_config.to_yaml) file.close end diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index ef9dddecf..4ffa947e7 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -6,7 +6,19 @@ require 'config/environment' +def set_app_config username + current_config = YAML.load(File.read(Rails.root.join('config', 'app_config_example.yml'))) + current_config[Rails.env.to_s] ||= {} + current_config[Rails.env.to_s]['pod_url'] = "#{username}.joindiaspora.com" + current_config['default']['pod_url'] = "#{username}.joindiaspora.com" + file = File.new(Rails.root.join('config','app_config.yml'),'w') + file.write(current_config.to_yaml) + file.close +end + username = "tom" +set_app_config username + # Create seed user user = User.instantiate!( :email => "tom@tom.joindiaspora.com", :username => "tom", diff --git a/db/seeds/tom.rb b/db/seeds/tom.rb index b81d10827..50d41eb91 100644 --- a/db/seeds/tom.rb +++ b/db/seeds/tom.rb @@ -7,11 +7,11 @@ require 'config/environment' def set_app_config username - current_config = YAML.load(Rails.root.join('config', 'app_config.yml')) - current_config[Rails.env] ||= {} - current_config[Rails.env][:pod_url] = "#{username}.joindiaspora.com" - current_config[:default][:pod_url] = "#{username}.joindiaspora.com" - file = File.new(Rails.root.join('config','app_config.yml'),'w') + current_config = YAML.load(File.read(Rails.root.join('config', 'app_config_example.yml'))) + current_config[Rails.env.to_s] ||= {} + current_config[Rails.env.to_s]['pod_url'] = "#{username}.joindiaspora.com" + current_config['default']['pod_url'] = "#{username}.joindiaspora.com" + file = File.new(Rails.root.join('..','..','shared','app_config.yml'),'w') file.write(current_config.to_yaml) file.close end diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 00ae27735..bd4174c76 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -35,11 +35,6 @@ module Diaspora aspects.detect{|x| x.id == id } end - def album_by_id( id ) - id = id.to_id - albums.detect{|x| x.id == id } - end - def aspects_with_post( id ) self.aspects.find_all_by_post_ids( id.to_id ) end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 1f24f3fed..da52ed849 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -26,15 +26,22 @@ describe User do end context 'posting' do - describe '#post' do + + describe '#validate_aspect_permissions' do it 'should not be able to post without a aspect' do - proc {user.post(:status_message, :message => "heyheyhey")}.should raise_error /You must post to someone/ + proc { + user.validate_aspect_permissions([]) + }.should raise_error /You must post to someone/ end it 'should not be able to post to someone elses aspect' do - proc {user.post(:status_message, :message => "heyheyhey", :to => aspect2.id)}.should raise_error /Cannot post to an aspect you do not own./ + proc { + user.validate_aspect_permissions(aspect2.id) + }.should raise_error /Cannot post to an aspect you do not own./ end - + end + + describe '#post' do it 'should put the post in the aspect post array' do post = user.post(:status_message, :message => "hey", :to => aspect.id) aspect.reload @@ -47,6 +54,16 @@ describe User do aspect.posts.should include album end end + + describe '#repost' do + let!(:status_message) { user.post(:status_message, :message => "hello", :to => aspect.id) } + + it 'should make the post visible in another aspect' do + user.repost( status_message, :to => aspect1.id ) + aspect1.reload + aspect1.posts.count.should be 1 + end + end end context 'dispatching' do diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/visible_posts_spec.rb index 5c44a2ce8..bcab473bc 100644 --- a/spec/models/user/visible_posts_spec.rb +++ b/spec/models/user/visible_posts_spec.rb @@ -7,83 +7,80 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe User do - before do - @user = Factory.create(:user) - @aspect = @user.aspect(:name => 'heroes') - @aspect2 = @user.aspect(:name => 'losers') + let(:user) { Factory(:user) } - @user2 = Factory.create :user - @user2_aspect = @user2.aspect(:name => 'dudes') + let(:user2) { Factory(:user) } + let(:user3) { Factory(:user) } + let(:user4) { Factory(:user) } - friend_users(@user, @aspect, @user2, @user2_aspect) + let!(:aspect) { user.aspect(:name => 'heroes') } + let!(:aspect2) { user.aspect(:name => 'losers') } - @user3 = Factory.create :user - @user3_aspect = @user3.aspect(:name => 'dudes') - friend_users(@user, @aspect2, @user3, @user3_aspect) + let!(:user2_aspect) { user2.aspect(:name => 'dudes') } + let!(:user3_aspect) { user3.aspect(:name => 'dudes') } + let!(:user4_aspect) { user4.aspect(:name => 'dudes') } - @user4 = Factory.create :user - @user4_aspect = @user4.aspect(:name => 'dudes') - friend_users(@user, @aspect2, @user4, @user4_aspect) - end + let(:status_message1) { user2.post :status_message, :message => "hi", :to => user2_aspect.id } + let(:status_message2) { user3.post :status_message, :message => "heyyyy", :to => user3_aspect.id } + let(:status_message3) { user4.post :status_message, :message => "yooo", :to => user4_aspect.id } - it 'should generate a valid stream for a aspect of people' do - status_message1 = @user2.post :status_message, :message => "hi", :to => @user2_aspect.id - status_message2 = @user3.post :status_message, :message => "heyyyy", :to => @user3_aspect.id - status_message3 = @user4.post :status_message, :message => "yooo", :to => @user4_aspect.id + before do + friend_users(user, aspect, user2, user2_aspect) + friend_users(user, aspect2, user3, user3_aspect) + friend_users(user, aspect2, user4, user4_aspect) + end - @user.receive status_message1.to_diaspora_xml - @user.receive status_message2.to_diaspora_xml - @user.receive status_message3.to_diaspora_xml - @user.reload + it 'should generate a valid stream for a aspect of people' do + (1..3).each{ |n| + eval("user.receive status_message#{n}.to_diaspora_xml") + } - @user.visible_posts(:by_members_of => @aspect).include?(status_message1).should be true - @user.visible_posts(:by_members_of => @aspect).include?(status_message2).should be false - @user.visible_posts(:by_members_of => @aspect).include?(status_message3).should be false + user.visible_posts(:by_members_of => aspect).should include status_message1 + user.visible_posts(:by_members_of => aspect).should_not include status_message2 + user.visible_posts(:by_members_of => aspect).should_not include status_message3 - @user.visible_posts(:by_members_of => @aspect2).include?(status_message1).should be false - @user.visible_posts(:by_members_of => @aspect2).include?(status_message2).should be true - @user.visible_posts(:by_members_of => @aspect2).include?(status_message3).should be true - end + user.visible_posts(:by_members_of => aspect2).should_not include status_message1 + user.visible_posts(:by_members_of => aspect2).should include status_message2 + user.visible_posts(:by_members_of => aspect2).should include status_message3 + end - describe 'querying' do - - it 'should find a visible post by id' do - status_message1 = @user.post :status_message, :message => "hi", :to => @aspect.id - status_message2 = @user2.post :status_message, :message => "heyyyy", :to => @user2_aspect.id - status_message3 = @user3.post :status_message, :message => "yooo", :to => @user3_aspect.id - - @user.find_visible_post_by_id(status_message1.id).should == status_message1 - @user2.find_visible_post_by_id(status_message1.id).should == nil - end - - end - - describe 'albums' do - before do - @album = @user.post :album, :name => "Georges", :to => @aspect.id - @aspect.reload - @aspect2.reload - @user.reload - - @album2 = @user.post :album, :name => "Borges", :to => @aspect.id - @aspect.reload - @aspect2.reload - @user.reload - - @user.post :album, :name => "Luises", :to => @aspect2.id - @aspect.reload - @aspect2.reload - @user.reload - end - - it 'should find all albums if passed :all' do - @user.albums_by_aspect(:all).size.should == 3 - end - - it 'should return the right number of albums' do - @user.albums_by_aspect(@aspect).size.should == 2 - @user.albums_by_aspect(@aspect2).size.should == 1 + context 'querying' do + describe '#find_visible_post_by_id' do + it 'should query' do + user2.find_visible_post_by_id(status_message1.id).should == status_message1 + user.find_visible_post_by_id(status_message1.id).should == nil end end + end + + context 'albums' do + + + before do + @album = user.post :album, :name => "Georges", :to => aspect.id + aspect.reload + aspect2.reload + user.reload + + @album2 = user.post :album, :name => "Borges", :to => aspect.id + aspect.reload + aspect2.reload + user.reload + + user.post :album, :name => "Luises", :to => aspect2.id + aspect.reload + aspect2.reload + user.reload + end + + it 'should find all albums if passed :all' do + user.albums_by_aspect(:all).should have(3).albums + end + + it 'should return the right number of albums' do + user.albums_by_aspect(aspect).should have(2).albums + user.albums_by_aspect(aspect2).should have(1).album + end + end end