From 34b21e75439b76b5cb01ec8c944c6504161e82b4 Mon Sep 17 00:00:00 2001 From: maelsoucaze Date: Sat, 16 Oct 2010 17:19:19 +0200 Subject: [PATCH 01/33] French localization updates. --- config/locales/diaspora/fr-informal.yml | 12 ++++++++---- config/locales/diaspora/fr.yml | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config/locales/diaspora/fr-informal.yml b/config/locales/diaspora/fr-informal.yml index d8944f81e..f5c4d53bf 100644 --- a/config/locales/diaspora/fr-informal.yml +++ b/config/locales/diaspora/fr-informal.yml @@ -38,6 +38,7 @@ fr-informal: share: "Partager" aspect_friends: add_friends: "ajouter des amis" + photos: "photos" albums: album: you: "toi" @@ -69,10 +70,13 @@ fr-informal: friends_albums: "Albums d’amis" your_albums: "Tes albums" aspects: - index: - photos: "photos" - show: - photos: "photos" + empty_messages: + start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" + nobody: "Tu as forcément des amis, n’hésite pas à les ramener sur Diaspora !" + nobody_in_aspect: "Ton aspect '%{aspect_name}' est vide." + add_friend: "Ajouter un ami" + add_friend_to: "Ajouter quelqu’un à %{aspect_name}" + invite: "Inviter quelqu’un à rejoindre Diaspora !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index c372ee57e..d4bc903c1 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -38,6 +38,7 @@ fr: share: "Partager" aspect_friends: add_friends: "ajouter des amis" + photos: "photos" albums: album: you: "vous" @@ -69,10 +70,13 @@ fr: friends_albums: "Albums d’amis" your_albums: "Vos albums" aspects: - index: - photos: "photos" - show: - photos: "photos" + empty_messages: + start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" + nobody: "Vous avez forcément des amis, n’hésitez pas à les ramener sur Diaspora !" + nobody_in_aspect: "Votre aspect '%{aspect_name}' est vide." + add_friend: "Ajouter un ami" + add_friend_to: "Ajouter quelqu’un à %{aspect_name}" + invite: "Inviter quelqu’un à rejoindre Diaspora !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" From 14ac908c3d26ea44713f3abb6814948ca10d21bf Mon Sep 17 00:00:00 2001 From: maelsoucaze Date: Mon, 25 Oct 2010 00:06:05 +0200 Subject: [PATCH 02/33] French localizations updates. --- config/locales/diaspora/fr-informal.yml | 31 +++++++++++++++++++------ config/locales/diaspora/fr.yml | 31 +++++++++++++++++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/config/locales/diaspora/fr-informal.yml b/config/locales/diaspora/fr-informal.yml index f5c4d53bf..42267d796 100644 --- a/config/locales/diaspora/fr-informal.yml +++ b/config/locales/diaspora/fr-informal.yml @@ -6,6 +6,15 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. fr-informal: + activemodel: + errors: + models: + user: + attributes: + username: + taken: "est déjà pris" + email: + taken: "est déjà pris" hello: "Bonjour tout le monde" application: helper: @@ -70,13 +79,14 @@ fr-informal: friends_albums: "Albums d’amis" your_albums: "Tes albums" aspects: - empty_messages: - start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" + no_friends_message: nobody: "Tu as forcément des amis, n’hésite pas à les ramener sur Diaspora !" nobody_in_aspect: "Ton aspect '%{aspect_name}' est vide." add_friend: "Ajouter un ami" add_friend_to: "Ajouter quelqu’un à %{aspect_name}" invite: "Inviter quelqu’un à rejoindre Diaspora !" + no_posts_message: + start_talking: "Personne n’a encore rien dit. Commence dès à présent la conversation !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" @@ -94,12 +104,12 @@ fr-informal: success: "%{name} a été supprimé avec succès." update: success: "Ton aspect, %{name}, a été édité avec succès." - move_friends: - failure: "L’édition de l’aspect concernant ton ami %{real_name} a échoué." - success: "Les aspects ont été édités avec succès." move_friend: failure: "ne fonctionne pas %{inspect}" - success: "Tu montres à présent à ton ami un aspect différent au tiens." + success: "Personne déplacée vers le nouvel aspect" + add_to_aspect: + failure: "L’ajout de l’ami vers l’aspect a échoué." + success: "Tu as ajouté l’ami à l’aspect avec succès." helper: remove: "supprimer" aspect_not_empty: "L’aspect n’est pas vide" @@ -140,6 +150,8 @@ fr-informal: photo: show_comments: "afficher les commentaires" posted_a_new_photo_to: "a publié une nouvelle photo dans" + delete: "Supprimer" + are_you_sure: "Es-tu sûr(e) ?" new: new_photo: "Nouvelle photo" back_to_list: "Retourner à la liste" @@ -163,6 +175,7 @@ fr-informal: sent: 'Ton invitation a été envoyée.' no_more: 'Tu n’as plus d’invitation.' already_sent: 'Tu as déjà invité cette personne.' + already_friends: 'Tu es déjà ami avec cette personne' invitation_token_invalid: 'Le jeton d’invitation fourni n’est pas valide !' updated: 'Ton mot de passe a été réglé avec succès. Tu es à présent connecté.' @@ -204,6 +217,7 @@ fr-informal: save: "sauver" are_you_sure: "Es-tu sûr(e) ?" remove_friend: "supprimer de mes amis" + no_posts: "aucun message à afficher !" requests: new_request: add_a_new_friend_to: "Ajouter un nouvel ami à" @@ -216,6 +230,9 @@ fr-informal: ignore: "Requête d’ami ignorée." create: error: "Aucun résultat Diaspora n’a été trouvé avec cette adresse e-mail !" - already_friends: "Vous êtes déjà amis avec %{destination_url}!" + invalid_identity: "Cette identité n’est pas proprement formatée" + error_server: "Un problème est survenu avec l’autre serveur. Il n’existe peut-être pas ?" + yourself: "Tu ne peux pas être ami avec toi-même !" + already_friends: "Tu es déjà ami avec %{destination_url}!" success: "Une requête d’ami a été envoyée à %{destination_url}." horribly_wrong: "Quelque chose d’horrible s’est produit." diff --git a/config/locales/diaspora/fr.yml b/config/locales/diaspora/fr.yml index d4bc903c1..baf9d1b82 100644 --- a/config/locales/diaspora/fr.yml +++ b/config/locales/diaspora/fr.yml @@ -6,6 +6,15 @@ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. fr: + activemodel: + errors: + models: + user: + attributes: + username: + taken: "est déjà pris" + email: + taken: "est déjà pris" hello: "Bonjour tout le monde" application: helper: @@ -70,13 +79,14 @@ fr: friends_albums: "Albums d’amis" your_albums: "Vos albums" aspects: - empty_messages: - start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" + no_friends_message: nobody: "Vous avez forcément des amis, n’hésitez pas à les ramener sur Diaspora !" nobody_in_aspect: "Votre aspect '%{aspect_name}' est vide." add_friend: "Ajouter un ami" add_friend_to: "Ajouter quelqu’un à %{aspect_name}" invite: "Inviter quelqu’un à rejoindre Diaspora !" + no_posts_message: + start_talking: "Personne n’a encore rien dit. Commencez dès à présent la conversation !" manage: add_a_new_aspect: "Ajouter un nouvel aspect" add_a_new_friend: "Ajouter un nouvel ami" @@ -94,12 +104,12 @@ fr: success: "%{name} a été supprimé avec succès." update: success: "Votre aspect, %{name}, a été édité avec succès." - move_friends: - failure: "L’édition de l’aspect concernant votre ami %{real_name} a échoué." - success: "Les aspects ont été édités avec succès." move_friend: failure: "ne fonctionne pas %{inspect}" - success: "Vous montrez à présent à votre ami un aspect différent au vôtre." + success: "Personne déplacée vers le nouvel aspect" + add_to_aspect: + failure: "L’ajout de l’ami vers l’aspect a échoué." + success: "Vous avez ajouté l’ami vers l’aspect avec succès." helper: remove: "supprimer" aspect_not_empty: "L’aspect n’est pas vide" @@ -140,6 +150,8 @@ fr: photo: show_comments: "afficher les commentaires" posted_a_new_photo_to: "a publié une nouvelle photo dans" + delete: "Supprimer" + are_you_sure: "Êtes-vous sûr(e) ?" new: new_photo: "Nouvelle photo" back_to_list: "Retourner à la liste" @@ -163,6 +175,7 @@ fr: sent: 'Votre invitation a été envoyée.' no_more: 'Vous n’avez plus d’invitation.' already_sent: 'Vous avez déjà invité cette personne.' + already_friends: 'Vous êtes déjà ami avec cette personne' invitation_token_invalid: 'Le jeton d’invitation fourni n’est pas valide !' updated: 'Votre mot de passe a été réglé avec succès. Vous êtes à présent connecté.' @@ -204,6 +217,7 @@ fr: save: "sauver" are_you_sure: "Êtes-vous sûr(e) ?" remove_friend: "supprimer de mes amis" + no_posts: "aucun message à afficher !" requests: new_request: add_a_new_friend_to: "Ajouter un nouvel ami à" @@ -216,6 +230,9 @@ fr: ignore: "Requête d’ami ignorée." create: error: "Aucun résultat Diaspora n’a été trouvé avec cette adresse e-mail !" - already_friends: "Vous êtes déjà amis avec %{destination_url}!" + invalid_identity: "Cette identité n’est pas proprement formatée" + error_server: "Un problème est survenu avec l’autre serveur. Il n’existe peut-être pas ?" + yourself: "Vous ne pouvez pas être ami avec vous-même !" + already_friends: "Vous êtes déjà ami avec %{destination_url}!" success: "Une requête d’ami a été envoyée à %{destination_url}." horribly_wrong: "Quelque chose d’horrible s’est produit." From c8663b45e2d46a3c45f08b8d6ed8139eeaad6054 Mon Sep 17 00:00:00 2001 From: ilya Date: Sun, 24 Oct 2010 15:17:15 -0700 Subject: [PATCH 03/33] readme added link to our convention --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a512f74d..8215e6c16 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ You can find an introduction to the source code [here](http://github.com/diaspor Bugs and pending features are on our [issue tracker](http://bugs.joindiaspora.com). Here are a few good places to start: - Run "rake spec" to run our [Rspec](http://blog.davidchelimsky.net/2007/05/14/an-introduction-to-rspec-part-i/) -unit test suite. Take a look at the pending specs, make one pass! +unit test suite. [Here](http://github.com/diaspora/diaspora/wiki/Introduction-to-Our-Rspec-Convention) is an introduction to our Rspec convention. Take a look at the pending specs, make one pass! - Run "rake cucumber" to run our [Cucumber](http://rubylearning.com/blog/2010/10/05/outside-in-development/) integration test suite. As you can see, we need more integration tests. Pick a feature and write one! From 31b3d739c0e82609d255e30b0b822c6335d16720 Mon Sep 17 00:00:00 2001 From: Alec Leamas Date: Mon, 25 Oct 2010 04:04:34 +0200 Subject: [PATCH 04/33] Bundle: add licenses, handle git gems Adding a docs dir collexting README and licenses from contained gems. git gems, which bundler does not handle well today, are handled by a hacked parsing of Gemfile.log, gem built into the source bundle and installed on target system --- pkg/Licenses | 99 +++++++++++++++++++++ pkg/fedora/.gitignore | 1 + pkg/fedora/diaspora-bundle.spec | 17 ++-- pkg/fedora/diaspora.spec | 3 +- pkg/fedora/make-dist.sh | 135 ++++++++++++++++++++--------- pkg/ubuntu/diaspora-bundle-install | 15 +++- 6 files changed, 218 insertions(+), 52 deletions(-) create mode 100644 pkg/Licenses diff --git a/pkg/Licenses b/pkg/Licenses new file mode 100644 index 000000000..cc8f33741 --- /dev/null +++ b/pkg/Licenses @@ -0,0 +1,99 @@ + +abstract: Ruby +actionmailer: MIT +actionpack: MIT +activemodel: MIT +activerecord: MIT +activeresource: ? (Other distros uses MIT, "Ruby-alike", no pointers) +activesupport: MIT +addressable: MIT +arel: MIT +aws MIT +bcrypt-ruby: MIT +builder: MIT +bunny: MIT +capistrano: MIT +capybara: MIT +chef: ASL 2.0 +childprocess: MIT +columnize: GPLv2 +crack: MIT +cucumber: MIT +cucumber-rails: MIT +culerity: MIT +daemons: Ruby+MIT +database_cleaner: MIT +devise: MIT +devise_invitable MIT +diff Ruby+GPLv2+ Artistic 2.0 +em-websocket: MIT +eribus: MIT +event-machine: Ruby+GPLv2 +extlib: MIT +factory_girls MIT +factory_girls_rails: MIT +ffi MIT +haml MIT +http_connection: MIT +gherkin: MIT +hashie: MIT +highline GPLv2+Ruby +json: Ruby +json-pure: Ruby +launchy: MIT +linecache: GPLv2 +mail: MIT +mime-types: GPLv2+Ruby+Artistic 2.0 +mini_magick: MIT +mini_fb: ? +mixlib-authentication: ASL 2.0 +mixlib-cli ASL 2.0 +mixlib-config ASL 2.0 +mixlib-log ASL 2.0 +mocha Ruby+MIT +moneta: MIT +mongo: ASL 2.0 +net-scp: MIT +net-sftp: MIT +net-ssh: MIT +net-ssh-gatawey: MIT +ohai: ASL 2.0 +plucky: MIT +polyglot. MIT +pubsubhubbub: ASL 2.0 http://code.google.com/p/pubsubhubbub/ +rake: MIT +rack-mount: MIT +rack-test: MIT +railties: MIT +rest-client: MIT +rspec-core: MIT +rspec-expectations: MIT +rspec-mocks: MIT +rspec-rails: MIT +rack: MIT +rack-mount: MIT +ruby-debug: MIT +ruby-debug-base: MIT +rubyzip: Ruby +selenium-webdriver: ASL 2.0 +subexec: MIT +term-ansicolor: GPLv2 +textile. MIT +textile-warden: MIT +thin: MIT +thor: MIT +treetop: MIT +tx-info: MIT +uutdtools: MIT +iwarden: MIT +webmock: MIT +will-paginate MIT + + + + + + + + + diff --git a/pkg/fedora/.gitignore b/pkg/fedora/.gitignore index bedbdc760..2a21dd54d 100644 --- a/pkg/fedora/.gitignore +++ b/pkg/fedora/.gitignore @@ -1,3 +1,4 @@ TODO dist .stgit* +vendor diff --git a/pkg/fedora/diaspora-bundle.spec b/pkg/fedora/diaspora-bundle.spec index dee189a26..a13a85368 100644 --- a/pkg/fedora/diaspora-bundle.spec +++ b/pkg/fedora/diaspora-bundle.spec @@ -38,9 +38,16 @@ Source file usede to compile native libraries in diaspora-bundle. %setup -q -n %{name}-%{version}-%{git_release} %build -mkdir -p vendor/cache -mv *.gem vendor/cache -bundle install --local --deployment --without ri rdoc +bundle install --local --deployment --without ri rdoc test +for gem in vendor/git/*; do + gem install --local \ + --force \ + --no-rdoc \ + --no-ri \ + --install-dir vendor/bundle/ruby/1.8/bundler \ + $gem + +done pushd vendor/bundle/ruby/1.8/gems # In repo (2.2.4) @@ -200,7 +207,7 @@ popd } mkdir -p $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle -cp -ar vendor/bundle $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle +cp -ar vendor $RPM_BUILD_ROOT/%{_libdir}/diaspora-bundle find %{buildroot}/%{_libdir}/diaspora-bundle \ -type d -fprintf dirs '%%%dir "%%p"\n' @@ -218,7 +225,7 @@ cat files >> dirs && cp dirs files %files -f files %defattr(-, diaspora, diaspora, 0755) -%doc COPYRIGHT Gemfile Gemfile.lock AUTHORS GNU-AGPL-3.0 +%doc COPYRIGHT Gemfile Gemfile.lock AUTHORS GNU-AGPL-3.0 docs %files -f dev-files devel %defattr(-, root, root, 0644) diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 1d61026e5..8a30492c8 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -49,13 +49,12 @@ 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/bundle|' \ + '/BUNDLE_PATH/s|:.*|: %{_libdir}/diaspora-bundle/vendor/bundle|' \ master/.bundle/config cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 3da2ab6e3..2ff8c9ef2 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -138,7 +138,7 @@ function checkout() cd diaspora; git fetch --quiet upstream git merge --quiet upstream/master - git checkout --quiet ${1:-'HEAD'} + [ -n "$1" ] && git reset --hard --quiet $1 git_id -n ) } @@ -175,41 +175,91 @@ function make_src echo "Required bundle: $(git_id dist/diaspora/Gemfile)" } -function get_git_repos() + +function build_git_gems() +# Usage: build_git_gems +# Horrible hack, in wait for bundler handling git gems OK. { - grep -A 2 GIT $1 | - awk ' /remote:/ { repo = $2 } - /revision:/ { printf "%s=%s\n",repo, $2}' + mkdir gem-tmp || : + cd gem-tmp + rm -rf * + + grep 'git:' ../$1 | sed 's/,/ /' | awk ' + /^.*git:\/\/.*$/ { + gsub( "=>", "") + gsub( ",", "") + if ( $1 != "gem") { + print "Strange git: line (ignored) :" $0 + next + } + name = $2 + suffix = "" + url="" + for (i = 3; i <= NF; i += 1) { + key = $i + i += 1 + if (key == ":git") + url = $i + else if ( key == ":ref") { + suffix = "; cd " name + suffix = suffix "; git reset --hard " $i + suffix = suffix "; cd .." + } + else if ( key == ":branch") + suffix = "; git checkout " $i + } + print "Running: ", cmd + cmd = sprintf( "git clone --quiet %s %s %s\n", + url, name, suffix) + system( cmd) + }' + sed -i 's/Date.today/"2010-10-24"/' carrierwave/carrierwave.gemspec + for dir in *; do + cd $dir + gem build *.gemspec + cp *.gem ../../$2 + cd .. + done + + cd .. + # rm -rf gem-tmp } - -function package_git_gems() +function make_docs() { - gemfile="$1" - dest="$2" + local gemfile=$1 + for url in $(read_git_urls $gemfile); do + local name=${url##*/} + name=${name%.*} + rm -rf vendor/git/$name + git clone --bare --quiet $url vendor/git/$name && + sed -i "s#$url#vendor/git/$name#" $gemfile || + echo "Cannot fix git repo \"$url\"" + done +} - rm -rf git-tmp - mkdir git-tmp - cd git-tmp - for repo in $( get_git_repos $1); do - url=${repo%%=*} - rev=${repo##*=} +function make_docs() +{ + local gems=$1 + local dest=$2 - name=${url##*/} - name="${name%.git}" - - rm -rf "$name" - git clone "$url" "$name" - cd $name - git reset --hard $rev - sed -i '/s.date/s/Date.today/"2010-09-25"/' *.gemspec - gem build *.gemspec - cp *.gem $dest - echo "Built GIT gem $name (*.gem)" - echo "Where: $dest" - cd .. - done - cd .. + for gem in $(ls $gems); do + local name=$(basename $gem) + [ -r $gems/$gem/README* ] && { + local readme=$(basename $gems/$gem/README*) + cp -a $gems/$gem/$readme $dest/$readme.$name + } + [ -r $gems/$gem/COPYRIGHT ] && \ + cp -a $gems/$gem/COPYRIGHT $dest/COPYRIGHT.$name + [ -r $gems/$gem/LICENSE ] && \ + cp -a $gems/$gem/LICENSE $dest/LICENSE.$name + [ -r $gems/$gem/License ] && \ + cp -a $gems/$gem/License $dest/License.$name + [ -r $gems/$gem/MIT-LICENSE ] && \ + cp -a $gems/$gem/MIT-LICENSE $dest/MIT-LICENSE.$name + [ -r $gems/$gem/COPYING ] && \ + cp -a $gems/$gem/COPYING $dest/COPYING.$name + done } @@ -219,8 +269,8 @@ function make_bundle() # { checkout ${1:-'HEAD'} >/dev/null - bundle_id=$( git_id dist/diaspora/Gemfile) - bundle_name="diaspora-bundle-$VERSION-$bundle_id" + local bundle_id=$( git_id dist/diaspora/Gemfile) + local bundle_name="diaspora-bundle-$VERSION-$bundle_id" test -e "dist/$bundle_name.tar.gz" || { echo "Creating bundle $bundle_name" cd dist @@ -231,22 +281,25 @@ function make_bundle() rm -rf .bundle bundle update fi - bundle install --deployment + [ -d 'vendor/git' ] || mkdir vendor/git + bundle install bundle package - package_git_gems "$PWD/Gemfile.lock" "$PWD/vendor/cache" + mkdir vendor/git + build_git_gems Gemfile vendor/git + + mkdir -p "../$bundle_name/docs" + mkdir -p "../$bundle_name/vendor" cp -ar AUTHORS Gemfile Gemfile.lock GNU-AGPL-3.0 COPYRIGHT \ - vendor/cache - cd vendor - mv cache $bundle_name - tar czf ../../$bundle_name.tar.gz $bundle_name - mv $bundle_name cache - cd .. + ../$bundle_name + make_docs "vendor/gems" "../$bundle_name/docs" + mv vendor/cache ../$bundle_name/vendor cd .. + tar czf $bundle_name.tar.gz $bundle_name + mv $bundle_name/vendor/cache diaspora/vendor/cache cd .. } echo echo "Bundle: dist/$bundle_name.tar.gz" - echo "Current dir:$PWD" } diff --git a/pkg/ubuntu/diaspora-bundle-install b/pkg/ubuntu/diaspora-bundle-install index 88924b930..65ae9520e 100755 --- a/pkg/ubuntu/diaspora-bundle-install +++ b/pkg/ubuntu/diaspora-bundle-install @@ -23,11 +23,18 @@ mv $(basename $1 .tar.gz) diaspora-bundle mkdir -p /usr/share/doc/diaspora-bundle || : cd /usr/lib/diaspora-bundle -cp AUTHORS GNU-AGPL-3.0 COPYRIGHT Gemfile Gemfile.lock \ +cp -a AUTHORS GNU-AGPL-3.0 COPYRIGHT Gemfile Gemfile.lock \ /usr/share/doc/diaspora-bundle - -mkdir -p vendor/cache -mv *.gem vendor/cache +cp -ar docs /usr/share/doc/diaspora-bundle bundle install --local --deployment --without ri rdoc +for gem in vendor/git/*; do + gem install --local \ + --force \ + --no-rdoc \ + --no-ri \ + --install-dir vendor/bundle/ruby/1.8/bundler \ + $gem +done + From c4ff07b09a35ec2dd5e44c8afae135b19f86f229 Mon Sep 17 00:00:00 2001 From: maxwell Date: Sat, 23 Oct 2010 16:09:58 -0700 Subject: [PATCH 05/33] twitter oauth dance complete --- Gemfile | 4 ++ Gemfile.lock | 64 +++++++++++++++++++ .../omniauth_services_controller.rb | 30 +++++++++ app/models/omniauth_service.rb | 13 ++++ app/models/user.rb | 2 + app/views/omniauth_services/index.html.haml | 17 +++++ config/initializers/_load_services.rb | 15 +++++ config/initializers/omniauth.rb | 9 +++ config/oauth_keys.yml | 3 + config/oauth_keys.yml.example | 3 + config/routes.rb | 5 +- 11 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 app/controllers/omniauth_services_controller.rb create mode 100644 app/models/omniauth_service.rb create mode 100644 app/views/omniauth_services/index.html.haml create mode 100644 config/initializers/_load_services.rb create mode 100644 config/initializers/omniauth.rb create mode 100644 config/oauth_keys.yml create mode 100644 config/oauth_keys.yml.example diff --git a/Gemfile b/Gemfile index bd90c0a46..766e3fd69 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,10 @@ gem "chef" gem 'devise', '1.1.3' gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper' gem 'devise_invitable', '~> 0.3.4' + +#Authentication +gem 'omniauth' + #Mongo gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git' gem 'bson_ext', '1.1' diff --git a/Gemfile.lock b/Gemfile.lock index 20a7f252c..7a1caf8ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,6 +170,9 @@ GEM factory_girl_rails (1.0) factory_girl (~> 1.3) rails (>= 3.0.0.beta4) + faraday (0.4.6) + addressable (>= 2.1.1) + rack (>= 1.0.1) ffi (0.6.3) rake (>= 0.8.7) gherkin (2.2.9) @@ -182,11 +185,20 @@ GEM i18n (0.4.1) json (1.4.6) json_pure (1.4.6) +<<<<<<< HEAD launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) +<<<<<<< HEAD linecache19 (0.5.11) ruby_core_source (>= 0.1.4) +======= + linecache (0.43) +======= + linecache19 (0.5.11) + ruby_core_source (>= 0.1.4) +>>>>>>> twitter oauth dance complete +>>>>>>> twitter oauth dance complete mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -207,6 +219,8 @@ GEM moneta (0.6.0) mongo (1.1) bson (>= 1.0.5) + multi_json (0.0.4) + net-ldap (0.1.1) net-scp (1.0.4) net-ssh (>= 1.99.1) net-sftp (2.0.5) @@ -215,6 +229,7 @@ GEM net-ssh-gateway (1.0.1) net-ssh (>= 1.99.1) nokogiri (1.4.3.1) +<<<<<<< HEAD ohai (0.5.8) extlib json (>= 1.4.4, <= 1.4.6) @@ -222,15 +237,54 @@ GEM mixlib-config mixlib-log systemu +======= + oa-basic (0.1.5) + multi_json (~> 0.0.2) + nokogiri (~> 1.4.2) + oa-core (= 0.1.5) + rest-client (~> 1.6.0) + oa-core (0.1.5) + rack (~> 1.1) + oa-enterprise (0.1.5) + net-ldap (~> 0.1.1) + nokogiri (~> 1.4.2) + oa-core (= 0.1.5) + pyu-ruby-sasl (~> 0.0.3.1) + rubyntlm (~> 0.1.1) + oa-oauth (0.1.5) + multi_json (~> 0.0.2) + nokogiri (~> 1.4.2) + oa-core (= 0.1.5) + oauth (~> 0.4.0) + oauth2 (~> 0.0.10) + oa-openid (0.1.5) + oa-core (= 0.1.5) + rack-openid (~> 1.1.1) + ruby-openid-apps-discovery + oauth (0.4.3) + oauth2 (0.0.13) + faraday (~> 0.4.1) + multi_json (>= 0.0.4) + omniauth (0.1.5) + oa-basic (= 0.1.5) + oa-core (= 0.1.5) + oa-enterprise (= 0.1.5) + oa-oauth (= 0.1.5) + oa-openid (= 0.1.5) +>>>>>>> twitter oauth dance complete plucky (0.3.6) mongo (~> 1.1) polyglot (0.3.1) pubsubhubbub (0.1.1) em-http-request (>= 0.1.5) eventmachine (>= 0.12.9) + pyu-ruby-sasl (0.0.3.2) rack (1.2.1) rack-mount (0.6.13) rack (>= 1.0.0) + rack-openid (1.1.2) + rack (>= 0.4) + ruby-openid (>= 2.0.3) rack-test (0.5.6) rack (>= 1.0) rails (3.0.1) @@ -269,8 +323,17 @@ GEM columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) +<<<<<<< HEAD ruby_core_source (0.1.4) archive-tar-minitar (>= 0.5.2) +======= + ruby-openid (2.1.8) + ruby-openid-apps-discovery (1.2.0) + ruby-openid (>= 2.1.7) + ruby_core_source (0.1.4) + archive-tar-minitar (>= 0.5.2) + rubyntlm (0.1.1) +>>>>>>> twitter oauth dance complete rubyzip (0.9.4) selenium-webdriver (0.0.29) childprocess (>= 0.0.7) @@ -325,6 +388,7 @@ DEPENDENCIES mini_magick mocha mongo_mapper! + omniauth pubsubhubbub rails (>= 3.0.0) redfinger! diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb new file mode 100644 index 000000000..cbc59be69 --- /dev/null +++ b/app/controllers/omniauth_services_controller.rb @@ -0,0 +1,30 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + + +class OmniauthServicesController < ApplicationController + before_filter :authenticate_user! + + def index + @services = current_user.services + end + + def create + auth = request.env['omniauth.auth'] + + + puts auth['extra']['access_token'].inspect + + current_user.services.create(:provider => auth['provider'], :uid => auth['uid']) + flash[:notice] = "Authentication successful." + redirect_to omniauth_services_url + end + + def destroy + @service = current_user.services.find(params[:id]) + @service.destroy + flash[:notice] = "Successfully destroyed authentication." + redirect_to omniauth_services_url + end +end diff --git a/app/models/omniauth_service.rb b/app/models/omniauth_service.rb new file mode 100644 index 000000000..1fe6ece32 --- /dev/null +++ b/app/models/omniauth_service.rb @@ -0,0 +1,13 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class OmniauthService + include MongoMapper::Document + + belongs_to :user + + key :provider, String + key :uid, String + +end diff --git a/app/models/user.rb b/app/models/user.rb index 343cc2d76..8d876f0e6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,6 +61,8 @@ class User many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect', :dependent => :destroy + many :services, :class_name => "OmniauthService" + #after_create :seed_aspects before_destroy :unfriend_everyone, :remove_person diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml new file mode 100644 index 000000000..6e77ade58 --- /dev/null +++ b/app/views/omniauth_services/index.html.haml @@ -0,0 +1,17 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +%h2 + Services + +%ul#stream + - for service in @services + %h3 + = service.provider + %b + =service.uid + = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete + += link_to "Connect to twitter", "/auth/twitter" + diff --git a/config/initializers/_load_services.rb b/config/initializers/_load_services.rb new file mode 100644 index 000000000..d65f2a695 --- /dev/null +++ b/config/initializers/_load_services.rb @@ -0,0 +1,15 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +def load_config_yaml filename + YAML.load(File.read(filename)) +end + +oauth_keys_file = "#{Rails.root}/config/oauth_keys.yml" + +if File.exist? oauth_keys_file + SERVICES = load_config_yaml(oauth_keys_file) + SERVICES ||= load_config_yaml("#{oauth_keys_file}.example") +end + diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 000000000..876d3f3f2 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,9 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +Rails.application.config.middleware.use OmniAuth::Builder do + provider :twitter, SERVICES['twitter']['consumer_key'], SERVICES['twitter']['consumer_secret'] + #provider :facebook, 'APP_ID', 'APP_SECRET' +end + diff --git a/config/oauth_keys.yml b/config/oauth_keys.yml new file mode 100644 index 000000000..1460b861f --- /dev/null +++ b/config/oauth_keys.yml @@ -0,0 +1,3 @@ +twitter: + consumer_key: no69jTnL5SCOnWgk5XWqbQ + consumer_secret: 2DZyu8DA43AIeFsRVdz8OtAHLvCtPjdRKdNO3UZGqWM diff --git a/config/oauth_keys.yml.example b/config/oauth_keys.yml.example new file mode 100644 index 000000000..3397b2832 --- /dev/null +++ b/config/oauth_keys.yml.example @@ -0,0 +1,3 @@ +twitter: + consumer_key: "" + consumer_secret: "" diff --git a/config/routes.rb b/config/routes.rb index 7364f9016..470193a74 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,9 @@ Diaspora::Application.routes.draw do resources :requests, :except => [:edit, :update] resources :photos, :except => [:index] resources :albums + resources :omniauth_services + + match '/auth/:provider/callback' => 'omniauth_services#create' devise_for :users, :controllers => {:registrations => "registrations", :password => "devise/passwords", @@ -18,7 +21,7 @@ Diaspora::Application.routes.draw do match 'users/export', :to => 'users#export' match 'users/import', :to => 'users#import' match 'users/export_photos', :to => 'users#export_photos' - resources :users, :except => [:create, :new, :show] + resources :users, :except => [:create, :new, :show] match 'aspects/move_friend', :to => 'aspects#move_friend', :as => 'move_friend' match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect' From 606c7a02a4d742ebb85bf0beeb3c92ee5f263ab9 Mon Sep 17 00:00:00 2001 From: maxwell Date: Sat, 23 Oct 2010 17:35:10 -0700 Subject: [PATCH 06/33] MS DG public message now post to twitter, if connected --- Gemfile | 2 +- app/controllers/omniauth_services_controller.rb | 11 +++++++---- app/controllers/status_messages_controller.rb | 9 +++++++-- app/models/omniauth_service.rb | 4 +++- app/models/user.rb | 10 ++++++++++ app/views/omniauth_services/index.html.haml | 5 +++-- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Gemfile b/Gemfile index 766e3fd69..cd11c7ceb 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'devise_invitable', '~> 0.3.4' #Authentication gem 'omniauth' - +gem 'twitter' #Mongo gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git' gem 'bson_ext', '1.1' diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb index cbc59be69..b15746875 100644 --- a/app/controllers/omniauth_services_controller.rb +++ b/app/controllers/omniauth_services_controller.rb @@ -13,10 +13,13 @@ class OmniauthServicesController < ApplicationController def create auth = request.env['omniauth.auth'] - - puts auth['extra']['access_token'].inspect - - current_user.services.create(:provider => auth['provider'], :uid => auth['uid']) + access_token = auth['extra']['access_token'] + user = auth['user_info'] + current_user.services.create(:nickname => user['nickname'], + :access_token => access_token.token, + :access_secret => access_token.secret, + :provider => auth['provider'], + :uid => auth['uid']) flash[:notice] = "Authentication successful." redirect_to omniauth_services_url end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 526818472..2e4c74472 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -10,12 +10,17 @@ class StatusMessagesController < ApplicationController def create data = clean_hash params[:status_message] + message = params[:status_message][:message] - if logged_into_fb? && params[:status_message][:public] == '1' - current_user.post_to_message_fb(params[:status_message][:message], @access_token) + if params[:status_message][:public] == '1' + current_user.post_to_twitter(message) + if logged_into_fb? + current_user.post_to_message_fb(message, @access_token) + end end @status_message = current_user.post(:status_message, data) + render :nothing => true end diff --git a/app/models/omniauth_service.rb b/app/models/omniauth_service.rb index 1fe6ece32..d30ab9f7d 100644 --- a/app/models/omniauth_service.rb +++ b/app/models/omniauth_service.rb @@ -9,5 +9,7 @@ class OmniauthService key :provider, String key :uid, String - + key :access_token, String + key :access_secret, String + key :nickname, String end diff --git a/app/models/user.rb b/app/models/user.rb index 8d876f0e6..1bcc5417c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -161,6 +161,16 @@ class User EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post end + def post_to_twitter(message) + twitter = self.services.find_by_provider("twitter") + if twitter + oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret']) + oauth.authorize_from_access(twitter.access_token, twitter.access_secret) + client = Twitter::Base.new(oauth) + client.update(message) + end + 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) diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml index 6e77ade58..9b6be3946 100644 --- a/app/views/omniauth_services/index.html.haml +++ b/app/views/omniauth_services/index.html.haml @@ -8,9 +8,10 @@ %ul#stream - for service in @services %h3 - = service.provider + %b= service.provider + logged in as %b - =service.uid + = service.nickname = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete = link_to "Connect to twitter", "/auth/twitter" From d66e986971b78a10e42397223e79c298e12daf5d Mon Sep 17 00:00:00 2001 From: maxwell Date: Sat, 23 Oct 2010 22:14:05 -0700 Subject: [PATCH 07/33] removing oauth keys --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a17dc3a1b..b09f9b136 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Configuration files config/app_config.yml config/fb_config.yml +config/oauth_keys.yml config/initializers/secret_token.rb .bundle vendor/bundle/* From 154b6e0ee7c7e55cdfcea7552e901b25ce203fff Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 11:54:52 -0700 Subject: [PATCH 08/33] MS DG added specs for posting to twitter, and basic services controller tests --- app/controllers/status_messages_controller.rb | 2 +- app/models/user.rb | 2 +- spec/controllers/albums_controller_spec.rb | 1 - .../omniauth_services_controller_spec.rb | 48 +++++++++++++++++ .../status_message_controller_spec.rb | 51 ++++++++++++------- spec/factories.rb | 21 +++----- 6 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 spec/controllers/omniauth_services_controller_spec.rb diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 2e4c74472..f2792f8f3 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -15,7 +15,7 @@ class StatusMessagesController < ApplicationController if params[:status_message][:public] == '1' current_user.post_to_twitter(message) if logged_into_fb? - current_user.post_to_message_fb(message, @access_token) + current_user.post_to_facebook(message, @access_token) end end diff --git a/app/models/user.rb b/app/models/user.rb index 1bcc5417c..75a0d0989 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -154,7 +154,7 @@ class User intitial_post(class_name, aspect_ids, options) end - def post_to_message_fb(message, access_token) + def post_to_facebook(message, access_token) id = 'me' type = 'feed' Rails.logger.info("Sending a message: #{message} to Facebook") diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb index 5c53f1909..74bec4045 100644 --- a/spec/controllers/albums_controller_spec.rb +++ b/spec/controllers/albums_controller_spec.rb @@ -14,7 +14,6 @@ describe AlbumsController do end it "should update the name of an album" do - sign_in :user, @user put :update, :id => @album.id, :album => { :name => "new_name"} @album.reload.name.should eql("new_name") end diff --git a/spec/controllers/omniauth_services_controller_spec.rb b/spec/controllers/omniauth_services_controller_spec.rb new file mode 100644 index 000000000..b72426eba --- /dev/null +++ b/spec/controllers/omniauth_services_controller_spec.rb @@ -0,0 +1,48 @@ +# 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 OmniauthServicesController do + render_views + let(:user) { Factory(:user) } + let!(:aspect) { user.aspect(:name => "lame-os") } + + let!(:service1) {a = Factory(:omniauth_service); user.services << a; a} + let!(:service2) {a = Factory(:omniauth_service); user.services << a; a} + let!(:service3) {a = Factory(:omniauth_service); user.services << a; a} + let!(:service4) {a = Factory(:omniauth_service); user.services << a; a} + + let(:mock_access_token) { Object.new } + + let(:omniauth_auth) {{ 'provider' => 'twitter', 'uid' => '2', + 'user_info' => { 'nickname' => 'grimmin' }, + 'extra' => { 'access_token' => mock_access_token }}} + + before do + sign_in :user, user + mock_access_token.stub!(:token).and_return("12345") + mock_access_token.stub!(:secret).and_return("56789") + end + + describe '#index' do + it 'displays all connected serivices for a user' do + get :index + assigns[:services].should == user.services + end + end + + describe '#create' do + it 'creates a new OmniauthService' do + request.env['omniauth.auth'] = omniauth_auth + lambda{post :create}.should change(user.services, :count).by(1) + end + end + + describe '#destroy' do + it 'should destroy a service of a users with the id' do + lambda{delete :destroy, :id => service1.id.to_s}.should change(user.services, :count).by(-1) + end + end +end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 9c84fe3e8..536db40d4 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -12,27 +12,42 @@ describe StatusMessagesController do before do sign_in :user, user + @controller.stub!(:current_user).and_return(user) end describe '#create' do - 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) - end + let(:status_message_hash) {{"status_message"=>{"public"=>"1", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}} - it 'should post to facebook when public is set' do - my_mock = mock("http") - my_mock.stub!(:post) - EventMachine::HttpRequest.should_receive(:new).and_return(my_mock) - post :create, status_message_hash - end - - it 'should not post to facebook when public in not set' do - status_message_hash['status_message']['public'] = '0' - EventMachine::HttpRequest.should_not_receive(:new) - post :create, status_message_hash - end + + context "posting out to facebook" do + before do + @controller.stub!(:logged_into_fb?).and_return(true) + end + + it 'should post to facebook when public is set' do + user.should_receive(:post_to_facebook) + post :create, status_message_hash + end + + it 'should not post to facebook when public in not set' do + status_message_hash['status_message']['public'] = '0' + user.should_not_receive(:post_to_facebook) + post :create, status_message_hash + end + end + + + context "posting to twitter" do + it 'should post to twitter if public is set' do + user.should_receive(:post_to_twitter).and_return(true) + post :create, status_message_hash + end + + it 'should not post to twitter when public in not set' do + status_message_hash['status_message']['public'] = '0' + user.should_not_receive(:post_to_twitter) + post :create, status_message_hash + end + end end end - diff --git a/spec/factories.rb b/spec/factories.rb index 982a3a07e..81f001a17 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -52,22 +52,17 @@ Factory.define :status_message do |m| m.person end -Factory.define :blog do |b| - b.sequence(:title) {|n| "bobby's #{n} penguins"} - b.sequence(:body) {|n| "jimmy's huge #{n} whales"} -end - -Factory.define :bookmark do |b| - b.link "http://www.yahooligans.com/" -end - -Factory.define :post do |p| -end - Factory.define :photo do |p| p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png') end -Factory.define(:comment) {} +Factory.define :omniauth_service do |service| + service.nickname "sirrobertking" + service.provider "twitter" + + service.sequence(:uid) { |token| "000#{token}" } + service.sequence(:access_token) { |token| "12345#{token}" } + service.sequence(:access_secret) { |token| "98765#{token}" } +end From fdd222003a0ca72026b2db1f4deefc9c49af9d60 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 12:14:27 -0700 Subject: [PATCH 09/33] fixed failing specs due to omitted factories. --- Gemfile.lock | 31 ++++++++++++++++++++----------- spec/factories.rb | 9 +++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7a1caf8ce..0a8a3eb65 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -182,13 +182,15 @@ GEM hashie (0.4.0) highline (1.6.1) http_connection (1.4.0) + httparty (0.6.1) + crack (= 0.1.8) i18n (0.4.1) json (1.4.6) json_pure (1.4.6) -<<<<<<< HEAD launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) +<<<<<<< HEAD <<<<<<< HEAD linecache19 (0.5.11) ruby_core_source (>= 0.1.4) @@ -199,6 +201,10 @@ GEM ruby_core_source (>= 0.1.4) >>>>>>> twitter oauth dance complete >>>>>>> twitter oauth dance complete +======= + linecache19 (0.5.11) + ruby_core_source (>= 0.1.4) +>>>>>>> fixed failing specs due to omitted factories. mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -229,15 +235,6 @@ GEM net-ssh-gateway (1.0.1) net-ssh (>= 1.99.1) nokogiri (1.4.3.1) -<<<<<<< HEAD - ohai (0.5.8) - extlib - json (>= 1.4.4, <= 1.4.6) - mixlib-cli - mixlib-config - mixlib-log - systemu -======= oa-basic (0.1.5) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) @@ -265,13 +262,19 @@ GEM oauth2 (0.0.13) faraday (~> 0.4.1) multi_json (>= 0.0.4) + ohai (0.5.8) + extlib + json (>= 1.4.4, <= 1.4.6) + mixlib-cli + mixlib-config + mixlib-log + systemu omniauth (0.1.5) oa-basic (= 0.1.5) oa-core (= 0.1.5) oa-enterprise (= 0.1.5) oa-oauth (= 0.1.5) oa-openid (= 0.1.5) ->>>>>>> twitter oauth dance complete plucky (0.3.6) mongo (~> 1.1) polyglot (0.3.1) @@ -350,6 +353,11 @@ GEM thor (0.14.3) treetop (1.4.8) polyglot (>= 0.3.1) + twitter (0.9.12) + hashie (~> 0.4.0) + httparty (~> 0.6.1) + multi_json (~> 0.0.4) + oauth (~> 0.4.3) tzinfo (0.3.23) uuidtools (2.1.1) warden (0.10.7) @@ -398,5 +406,6 @@ DEPENDENCIES ruby-debug19 sprinkle! thin + twitter webmock will_paginate (= 3.0.pre2) diff --git a/spec/factories.rb b/spec/factories.rb index 81f001a17..6c6d69f4f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -66,3 +66,12 @@ Factory.define :omniauth_service do |service| service.sequence(:access_secret) { |token| "98765#{token}" } end +Factory.define(:comment) {} + +Factory.define :fb_status do |s| + s.graph_id "367501354973" + s.author_name "Bret Taylor" + s.author_id "220439" + s.message "Pigs run from our house in fear. Tonight, I am wrapping the pork tenderloin in bacon and putting pancetta in the corn." + s.updated_time Time.parse "2010-03-06T02:57:48+0000" +end From be39df75fed3c7495be1e6a25781a745c1400610 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 12:28:45 -0700 Subject: [PATCH 10/33] removed fb_status from the factories. whoops. --- Gemfile.lock | 18 ------------------ spec/factories.rb | 7 ------- 2 files changed, 25 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0a8a3eb65..1a3128822 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -190,21 +190,8 @@ GEM launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) -<<<<<<< HEAD -<<<<<<< HEAD linecache19 (0.5.11) ruby_core_source (>= 0.1.4) -======= - linecache (0.43) -======= - linecache19 (0.5.11) - ruby_core_source (>= 0.1.4) ->>>>>>> twitter oauth dance complete ->>>>>>> twitter oauth dance complete -======= - linecache19 (0.5.11) - ruby_core_source (>= 0.1.4) ->>>>>>> fixed failing specs due to omitted factories. mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -326,17 +313,12 @@ GEM columnize (>= 0.3.1) linecache19 (>= 0.5.11) ruby-debug-base19 (>= 0.11.19) -<<<<<<< HEAD - ruby_core_source (0.1.4) - archive-tar-minitar (>= 0.5.2) -======= ruby-openid (2.1.8) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) ruby_core_source (0.1.4) archive-tar-minitar (>= 0.5.2) rubyntlm (0.1.1) ->>>>>>> twitter oauth dance complete rubyzip (0.9.4) selenium-webdriver (0.0.29) childprocess (>= 0.0.7) diff --git a/spec/factories.rb b/spec/factories.rb index 6c6d69f4f..b64cbbc5e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -68,10 +68,3 @@ end Factory.define(:comment) {} -Factory.define :fb_status do |s| - s.graph_id "367501354973" - s.author_name "Bret Taylor" - s.author_id "220439" - s.message "Pigs run from our house in fear. Tonight, I am wrapping the pork tenderloin in bacon and putting pancetta in the corn." - s.updated_time Time.parse "2010-03-06T02:57:48+0000" -end From c489f49a25939d66a8c7be989a9ffb9f922fe667 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 13:59:26 -0700 Subject: [PATCH 11/33] DG beginning to collapse twitter&facebook --- app/controllers/application_controller.rb | 3 ++- app/controllers/omniauth_services_controller.rb | 2 ++ app/controllers/services_controller.rb | 1 - app/models/user.rb | 11 ++++++----- app/views/omniauth_services/index.html.haml | 1 + config/initializers/omniauth.rb | 2 +- config/oauth_keys.yml | 3 +++ 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 137705df4..d61cb193d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,15 +45,16 @@ class ApplicationController < ActionController::Base end end + ## take this out def fb_user_info if current_user @access_token = warden.session[:access_token] @logged_in = @access_token.present? end end - def logged_into_fb? @logged_in end + ## end diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb index b15746875..23ff7afe5 100644 --- a/app/controllers/omniauth_services_controller.rb +++ b/app/controllers/omniauth_services_controller.rb @@ -13,6 +13,8 @@ class OmniauthServicesController < ApplicationController def create auth = request.env['omniauth.auth'] + puts auth.inspect + access_token = auth['extra']['access_token'] user = auth['user_info'] current_user.services.create(:nickname => user['nickname'], diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 97f52cef2..29da09872 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -12,7 +12,6 @@ class ServicesController < ApplicationController code = params['code'] # Facebooks verification string if code access_token_hash = MiniFB.oauth_access_token(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", FB_SECRET, code) - p access_token_hash @access_token = access_token_hash["access_token"] # TODO: This is where you'd want to store the token in your database diff --git a/app/models/user.rb b/app/models/user.rb index 75a0d0989..a52201fa0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -154,11 +154,12 @@ class User intitial_post(class_name, aspect_ids, options) end - def post_to_facebook(message, access_token) - id = 'me' - type = 'feed' - Rails.logger.info("Sending a message: #{message} to Facebook") - EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post + def post_to_facebook(message) + facebook = self.services.find_by_provider("facebook") + if facebook + Rails.logger.info("Sending a message: #{message} to Facebook") + EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{facebook.access_token}").post + end end def post_to_twitter(message) diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml index 9b6be3946..282df96fc 100644 --- a/app/views/omniauth_services/index.html.haml +++ b/app/views/omniauth_services/index.html.haml @@ -15,4 +15,5 @@ = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete = link_to "Connect to twitter", "/auth/twitter" += link_to "Connect to facebook", "/auth/facebook" diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 876d3f3f2..a9253f6c2 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -4,6 +4,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, SERVICES['twitter']['consumer_key'], SERVICES['twitter']['consumer_secret'] - #provider :facebook, 'APP_ID', 'APP_SECRET' + provider :facebook, SERVICES['facebook']['app_id'], SERVICES['facebook']['app_secret'] end diff --git a/config/oauth_keys.yml b/config/oauth_keys.yml index 1460b861f..c3dc20afd 100644 --- a/config/oauth_keys.yml +++ b/config/oauth_keys.yml @@ -1,3 +1,6 @@ twitter: consumer_key: no69jTnL5SCOnWgk5XWqbQ consumer_secret: 2DZyu8DA43AIeFsRVdz8OtAHLvCtPjdRKdNO3UZGqWM +facebook: + app_id: 120373411325347 + app_secret: 7fe864834726f8a5e65bc93928b99a53 From 3d302f8db7c2a794038a27dfabc43aced2e22acb Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 14:49:55 -0700 Subject: [PATCH 12/33] facebook and twitter both use omniauth and are saved as OmniauthServices --- Gemfile.lock | 21 +++++---------- .../omniauth_services_controller.rb | 26 +++++++++++++------ app/controllers/status_messages_controller.rb | 4 +-- app/views/omniauth_services/index.html.haml | 4 +-- config/deploy_config.yml | 2 +- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a3128822..1abff88d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,7 +98,6 @@ GEM activesupport (= 3.0.1) activesupport (3.0.1) addressable (2.2.2) - archive-tar-minitar (0.5.2) arel (1.0.1) activesupport (~> 3.0.0) aws (2.3.22) @@ -190,8 +189,7 @@ GEM launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) - linecache19 (0.5.11) - ruby_core_source (>= 0.1.4) + linecache (0.43) mail (2.2.7) activesupport (>= 2.3.6) mime-types @@ -305,19 +303,14 @@ GEM rspec-expectations (~> 2.0.1) rspec-rails (2.0.1) rspec (~> 2.0.0) - ruby-debug-base19 (0.11.24) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby_core_source (>= 0.1.4) - ruby-debug19 (0.11.6) - columnize (>= 0.3.1) - linecache19 (>= 0.5.11) - ruby-debug-base19 (>= 0.11.19) + ruby-debug (0.10.3) + columnize (>= 0.1) + ruby-debug-base (~> 0.10.3.0) + ruby-debug-base (0.10.3) + linecache (>= 0.3) ruby-openid (2.1.8) ruby-openid-apps-discovery (1.2.0) ruby-openid (>= 2.1.7) - ruby_core_source (0.1.4) - archive-tar-minitar (>= 0.5.2) rubyntlm (0.1.1) rubyzip (0.9.4) selenium-webdriver (0.0.29) @@ -385,7 +378,7 @@ DEPENDENCIES roxml! rspec (>= 2.0.0) rspec-rails (>= 2.0.0) - ruby-debug19 + ruby-debug sprinkle! thin twitter diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb index 23ff7afe5..d7659236e 100644 --- a/app/controllers/omniauth_services_controller.rb +++ b/app/controllers/omniauth_services_controller.rb @@ -13,15 +13,25 @@ class OmniauthServicesController < ApplicationController def create auth = request.env['omniauth.auth'] - puts auth.inspect + provider = auth['provider'] + user = auth['user_info'] + + if provider == 'twitter' + access_token = auth['extra']['access_token'] + current_user.services.create(:nickname => user['nickname'], + :access_token => access_token.token, + :access_secret => access_token.secret, + :provider => provider, + :uid => auth['uid']) + + elsif provider == 'facebook' + current_user.services.create(:nickname => user['nickname'], + :access_token => auth['credentials']['token'], + :provider => provider, + :uid => auth['uid']) + end + - access_token = auth['extra']['access_token'] - user = auth['user_info'] - current_user.services.create(:nickname => user['nickname'], - :access_token => access_token.token, - :access_secret => access_token.secret, - :provider => auth['provider'], - :uid => auth['uid']) flash[:notice] = "Authentication successful." redirect_to omniauth_services_url end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index f2792f8f3..47caf4bf9 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -14,9 +14,7 @@ class StatusMessagesController < ApplicationController if params[:status_message][:public] == '1' current_user.post_to_twitter(message) - if logged_into_fb? - current_user.post_to_facebook(message, @access_token) - end + current_user.post_to_facebook(message) end @status_message = current_user.post(:status_message, data) diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml index 282df96fc..7d7e7c13f 100644 --- a/app/views/omniauth_services/index.html.haml +++ b/app/views/omniauth_services/index.html.haml @@ -14,6 +14,6 @@ = service.nickname = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete -= link_to "Connect to twitter", "/auth/twitter" -= link_to "Connect to facebook", "/auth/facebook" +%h4= link_to "Connect to twitter", "/auth/twitter" +%h4= link_to "Connect to facebook", "/auth/facebook" diff --git a/config/deploy_config.yml b/config/deploy_config.yml index 06a6747e1..dda2cc200 100644 --- a/config/deploy_config.yml +++ b/config/deploy_config.yml @@ -6,7 +6,7 @@ cross_server: deploy_to: '/usr/local/app/diaspora' user: 'root' repo: 'git://github.com/diaspora/diaspora.git' - branch: 'master' + branch: 'twitter' default_env: 'development' servers: tom: From b2e8ebd0bcea57693e60b992ff4fb544fa4e90d0 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 16:17:19 -0700 Subject: [PATCH 13/33] OmniauthService -> Service. Cleaned up views. --- app/controllers/application_controller.rb | 14 ----- app/controllers/aspects_controller.rb | 12 ----- .../omniauth_services_controller.rb | 45 ---------------- app/controllers/services_controller.rb | 52 +++++++++++-------- app/controllers/users_controller.rb | 3 -- app/helpers/application_helper.rb | 5 -- .../{omniauth_service.rb => service.rb} | 2 +- app/models/user.rb | 2 +- app/views/omniauth_services/index.html.haml | 19 ------- app/views/services/index.html.haml | 28 ++++++++++ app/views/shared/_aspect_friends.haml | 5 -- app/views/shared/_public_explain.haml | 12 +++-- app/views/shared/_publisher.haml | 28 +++++----- app/views/users/_services.haml | 26 ---------- app/views/users/edit.html.haml | 5 +- config/routes.rb | 11 ++-- ...er_spec.rb => services_controller_spec.rb} | 10 ++-- spec/factories.rb | 6 +-- 18 files changed, 94 insertions(+), 191 deletions(-) delete mode 100644 app/controllers/omniauth_services_controller.rb rename app/models/{omniauth_service.rb => service.rb} (93%) delete mode 100644 app/views/omniauth_services/index.html.haml create mode 100644 app/views/services/index.html.haml delete mode 100644 app/views/users/_services.haml rename spec/controllers/{omniauth_services_controller_spec.rb => services_controller_spec.rb} (78%) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d61cb193d..df08808ae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base before_filter :set_friends_and_status, :except => [:create, :update] before_filter :count_requests - before_filter :fb_user_info before_filter :set_invites layout :layout_by_resource @@ -44,17 +43,4 @@ class ApplicationController < ActionController::Base @invites = current_user.invites end end - - ## take this out - def fb_user_info - if current_user - @access_token = warden.session[:access_token] - @logged_in = @access_token.present? - end - end - def logged_into_fb? - @logged_in - end - ## - end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index ddde8a725..0129c0abf 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -11,9 +11,6 @@ class AspectsController < ApplicationController def index @posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' @aspect = :all - - @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - :scope=>MiniFB.scopes.join(",")) end def create @@ -56,15 +53,6 @@ class AspectsController < ApplicationController end end - def public - # @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - # :scope=>MiniFB.scopes.join(",")) - - @posts = current_user.visible_posts(:person_id => current_user.person.id, :public => true).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' - - respond_with @aspect - end - def manage @aspect = :manage @remote_requests = current_user.requests_for_me diff --git a/app/controllers/omniauth_services_controller.rb b/app/controllers/omniauth_services_controller.rb deleted file mode 100644 index d7659236e..000000000 --- a/app/controllers/omniauth_services_controller.rb +++ /dev/null @@ -1,45 +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. - - -class OmniauthServicesController < ApplicationController - before_filter :authenticate_user! - - def index - @services = current_user.services - end - - def create - auth = request.env['omniauth.auth'] - - provider = auth['provider'] - user = auth['user_info'] - - if provider == 'twitter' - access_token = auth['extra']['access_token'] - current_user.services.create(:nickname => user['nickname'], - :access_token => access_token.token, - :access_secret => access_token.secret, - :provider => provider, - :uid => auth['uid']) - - elsif provider == 'facebook' - current_user.services.create(:nickname => user['nickname'], - :access_token => auth['credentials']['token'], - :provider => provider, - :uid => auth['uid']) - end - - - flash[:notice] = "Authentication successful." - redirect_to omniauth_services_url - end - - def destroy - @service = current_user.services.find(params[:id]) - @service.destroy - flash[:notice] = "Successfully destroyed authentication." - redirect_to omniauth_services_url - end -end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 29da09872..7c5da42a7 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -4,36 +4,42 @@ class ServicesController < ApplicationController + before_filter :authenticate_user! + + def index + @services = current_user.services + end def create - puts 'services/create' - p params + auth = request.env['omniauth.auth'] - code = params['code'] # Facebooks verification string - if code - access_token_hash = MiniFB.oauth_access_token(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", FB_SECRET, code) - @access_token = access_token_hash["access_token"] + provider = auth['provider'] + user = auth['user_info'] - # TODO: This is where you'd want to store the token in your database - # but for now, we'll just keep it in the session so we don't need a database - warden.session[:access_token] = @access_token - flash[:success] = "Authentication successful." + if provider == 'twitter' + access_token = auth['extra']['access_token'] + current_user.services.create(:nickname => user['nickname'], + :access_token => access_token.token, + :access_secret => access_token.secret, + :provider => provider, + :uid => auth['uid']) + + elsif provider == 'facebook' + current_user.services.create(:nickname => user['nickname'], + :access_token => auth['credentials']['token'], + :provider => provider, + :uid => auth['uid']) end - redirect_to edit_user_url current_user + + + flash[:notice] = "Authentication successful." + redirect_to services_url end def destroy - warden.session[:access_token] = nil - warden.session[:user_id] = nil - redirect_to edit_user_url current_user + @service = current_user.services.find(params[:id]) + @service.destroy + flash[:notice] = "Successfully destroyed authentication." + redirect_to services_url end - - def fb_post - id = 'me' - type = 'feed' - - @res = MiniFB.post(@access_token, id, :type=>type, :metadata=>true, :params=>params) - redirect_to edit_user_url current_user - end - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aacff8504..9c1bb3e9c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -19,9 +19,6 @@ class UsersController < ApplicationController @person = @user.person @profile = @user.person.profile @photos = current_user.visible_posts(:person_id => current_user.person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' - - @fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create", - :scope=>MiniFB.scopes.join(",")) end def update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8851f3c8e..869d49a98 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -78,9 +78,4 @@ module ApplicationHelper def post_yield_tag(post) (':' + post.id.to_s).to_sym end - - def connected_fb_as token - response_hash = MiniFB.get(token, 'me') - "Connected to facebook as #{response_hash[:name]}" - end end diff --git a/app/models/omniauth_service.rb b/app/models/service.rb similarity index 93% rename from app/models/omniauth_service.rb rename to app/models/service.rb index d30ab9f7d..1b64f013e 100644 --- a/app/models/omniauth_service.rb +++ b/app/models/service.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class OmniauthService +class Service include MongoMapper::Document belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index a52201fa0..48420e577 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -61,7 +61,7 @@ class User many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :aspects, :class_name => 'Aspect', :dependent => :destroy - many :services, :class_name => "OmniauthService" + many :services, :class_name => "Service" #after_create :seed_aspects diff --git a/app/views/omniauth_services/index.html.haml b/app/views/omniauth_services/index.html.haml deleted file mode 100644 index 7d7e7c13f..000000000 --- a/app/views/omniauth_services/index.html.haml +++ /dev/null @@ -1,19 +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. - -%h2 - Services - -%ul#stream - - for service in @services - %h3 - %b= service.provider - logged in as - %b - = service.nickname - = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete - -%h4= link_to "Connect to twitter", "/auth/twitter" -%h4= link_to "Connect to facebook", "/auth/facebook" - diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml new file mode 100644 index 000000000..ea375e9ac --- /dev/null +++ b/app/views/services/index.html.haml @@ -0,0 +1,28 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +#section_header + %h2 + Settings + %ul#settings_nav + %li=link_to 'Profile', '#', :class => 'profile' + %li=link_to 'Account', '#', :class => 'account' + %li=link_to 'Services', services_path + +.span-19.prepend-5.last + %h2 + Services + + %ul#stream + - for service in @services + %h3 + %b= service.provider + logged in as + %b + = service.nickname + = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete + + %h4= link_to "Connect to twitter", "/auth/twitter" + %h4= link_to "Connect to facebook", "/auth/facebook" + diff --git a/app/views/shared/_aspect_friends.haml b/app/views/shared/_aspect_friends.haml index c44d88e6b..f4b2f06f7 100644 --- a/app/views/shared/_aspect_friends.haml +++ b/app/views/shared/_aspect_friends.haml @@ -15,11 +15,6 @@ - for friend in @friends = person_image_link(friend) - - if @logged_in && (@aspect == :public) - %h3 Facebook Friends - - @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) = link_to (image_tag('add_friend_button.png', :title => "add to #{@aspect}")), "#add_request_pane", :id => 'add_request_button' diff --git a/app/views/shared/_public_explain.haml b/app/views/shared/_public_explain.haml index ca1a2b1d7..3d7e7f644 100644 --- a/app/views/shared/_public_explain.haml +++ b/app/views/shared/_public_explain.haml @@ -9,10 +9,14 @@ Public messages will be available for others outside of Diaspora to see. %br %br - - if @logged_in - = connected_fb_as(@access_token) - - else - = link_to "Connect to Facebook", @fb_access_url + + - if current_user.services + - for service in current_user.services + = "logged in to #{service.provider}" + %br + + = link_to "manage connected services", services_path + %br %br = link_to "OK", '#', :class => "button", :onClick => '$.fancybox.close();' diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 56ac9e440..5e3be8f2a 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -2,20 +2,22 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -:javascript - $("div.public_toggle input").live("click", function(evt){ - if("#{@logged_in}" == "false" && $(this).attr('checked') == true){ - $(".question_mark").click(); - }; - }); - - $("#publisher textarea, #publisher input").live("focus", function(evt){ - $("#publisher .options_and_submit").fadeIn(50); - }); - $("#publisher form").live("submit", function(evt){ - $("#publisher .options_and_submit").hide(); - }); +- content_for :head do + :javascript + $("div.public_toggle input").live("click", function(evt){ + if($(this).attr('checked') == true){ + $(".question_mark").click(); + }; + }); + + $("#publisher textarea, #publisher input").live("focus", function(evt){ + $("#publisher .options_and_submit").fadeIn(50); + }); + + $("#publisher form").live("submit", function(evt){ + $("#publisher .options_and_submit").hide(); + }); #publisher = owner_image_tag diff --git a/app/views/users/_services.haml b/app/views/users/_services.haml deleted file mode 100644 index a9a6d7977..000000000 --- a/app/views/users/_services.haml +++ /dev/null @@ -1,26 +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. - - -%h2 Services - -- if FACEBOOK - %h3 Facebook - %p - - if @logged_in - = connected_fb_as(@access_token) - - %p - - @fb_friends = MiniFB.get(@access_token, 'me', :type => "friends") - - @fb_friends[:data].each do |friend| - = image_tag( "http://graph.facebook.com/#{friend[:id]}/picture" ) - - = link_to "Disconnect from Facebook", services_destroy_path - - else - = link_to "Connect to Facebook", @fb_access_url - - #content_bottom - .back - = link_to "⇧ home", root_path - diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 48b266c09..104a9e8fd 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -18,7 +18,7 @@ %ul#settings_nav %li=link_to 'Profile', '#', :class => 'profile' %li=link_to 'Account', '#', :class => 'account' - %li=link_to 'Services', '#', :class => 'services' + %li=link_to 'Services', services_path .span-19.prepend-5.last #profile.settings_pane{:style=>"display:block;"} @@ -27,6 +27,3 @@ #account.settings_pane = render 'users/account' - #services.settings_pane - = render 'users/services' - diff --git a/config/routes.rb b/config/routes.rb index 470193a74..b9b05ca65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,13 +9,13 @@ Diaspora::Application.routes.draw do resources :requests, :except => [:edit, :update] resources :photos, :except => [:index] resources :albums - resources :omniauth_services + resources :services - match '/auth/:provider/callback' => 'omniauth_services#create' + match '/auth/:provider/callback' => 'services#create' devise_for :users, :controllers => {:registrations => "registrations", :password => "devise/passwords", - :invitations => "invitations"} + :invitations => "invitations"} # added public route to user match 'public/:username', :to => 'users#public' match 'users/export', :to => 'users#export' @@ -27,13 +27,8 @@ Diaspora::Application.routes.draw do match 'aspects/add_to_aspect',:to => 'aspects#add_to_aspect', :as => 'add_to_aspect' match 'aspects/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect' match 'aspects/manage', :to => 'aspects#manage' - match 'aspects/public', :to => 'aspects#public' resources :aspects, :except => [:edit] - match 'services/create', :to => "services#create" - match 'services/destroy', :to => "services#destroy" - match 'services/fb_post', :to => "services#fb_post" - match 'warzombie', :to => "dev_utilities#warzombie" match 'zombiefriends', :to => "dev_utilities#zombiefriends" match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept" diff --git a/spec/controllers/omniauth_services_controller_spec.rb b/spec/controllers/services_controller_spec.rb similarity index 78% rename from spec/controllers/omniauth_services_controller_spec.rb rename to spec/controllers/services_controller_spec.rb index b72426eba..0c19c1e23 100644 --- a/spec/controllers/omniauth_services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -4,15 +4,15 @@ require 'spec_helper' -describe OmniauthServicesController do +describe ServicesController do render_views let(:user) { Factory(:user) } let!(:aspect) { user.aspect(:name => "lame-os") } - let!(:service1) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service2) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service3) {a = Factory(:omniauth_service); user.services << a; a} - let!(:service4) {a = Factory(:omniauth_service); user.services << a; a} + let!(:service1) {a = Factory(:service); user.services << a; a} + let!(:service2) {a = Factory(:service); user.services << a; a} + let!(:service3) {a = Factory(:service); user.services << a; a} + let!(:service4) {a = Factory(:service); user.services << a; a} let(:mock_access_token) { Object.new } diff --git a/spec/factories.rb b/spec/factories.rb index b64cbbc5e..32d747937 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -57,12 +57,12 @@ Factory.define :photo do |p| end -Factory.define :omniauth_service do |service| +Factory.define :service do |service| service.nickname "sirrobertking" service.provider "twitter" - service.sequence(:uid) { |token| "000#{token}" } - service.sequence(:access_token) { |token| "12345#{token}" } + service.sequence(:uid) { |token| "00000#{token}" } + service.sequence(:access_token) { |token| "12345#{token}" } service.sequence(:access_secret) { |token| "98765#{token}" } end From 287d633c443ad383cd4a9463701cc2ab2260380f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 17:22:03 -0700 Subject: [PATCH 14/33] user#post now handles posting to services. --- app/controllers/status_messages_controller.rb | 7 ------ app/models/user.rb | 19 +++++++++------- spec/models/user/posting_spec.rb | 22 +++++++++++++++++-- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 47caf4bf9..89cf59f32 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -11,14 +11,7 @@ class StatusMessagesController < ApplicationController def create data = clean_hash params[:status_message] message = params[:status_message][:message] - - if params[:status_message][:public] == '1' - current_user.post_to_twitter(message) - current_user.post_to_facebook(message) - end - @status_message = current_user.post(:status_message, data) - render :nothing => true end diff --git a/app/models/user.rb b/app/models/user.rb index 48420e577..8c179c239 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -151,7 +151,17 @@ class User aspect_ids = validate_aspect_permissions(aspect_ids) - 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) + + if options[:public] + self.services.each do |service| + self.send("post_to_#{service.provider}".to_sym) + end + end + + post end def post_to_facebook(message) @@ -172,13 +182,6 @@ class User end 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 update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 70438bbec..f21bad8a7 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -7,12 +7,16 @@ require 'spec_helper' describe User do let!(:user) { Factory(:user) } + let!(:user2) { Factory(:user) } + let!(:aspect) { user.aspect(:name => 'heroes') } let!(:aspect1) { user.aspect(:name => 'other') } - - let!(:user2) { Factory(:user) } let!(:aspect2) { user2.aspect(:name => 'losers') } + let!(:service1) { user.services << Factory(:service, :provider => 'twitter') } + let!(:service2) { user.services << Factory(:service, :provider => 'facebook') } + + describe '#validate_aspect_permissions' do it 'requires an aspect' do proc { @@ -44,11 +48,25 @@ describe User do aspect.reload aspect.posts.should include album end + it "should add the post to that user's visible posts" do status_message = user.post :status_message, :message => "hi", :to => aspect.id user.reload user.raw_visible_posts.include?(status_message).should be true end + + it "posts to services if post is public" do + user.should_receive(:post_to_twitter).exactly(1).times + user.should_receive(:post_to_facebook).exactly(1).times + user.post :status_message, :message => "hi", :to => "all", :public => true + end + + it "does not post to services if post is not public" do + user.should_receive(:post_to_twitter).exactly(0).times + user.should_receive(:post_to_facebook).exactly(0).times + user.post :status_message, :message => "hi", :to => "all" + end + end describe '#update_post' do From 6ff94e67b3b404965625e298bb1a5704b5b6ea0d Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 17:26:07 -0700 Subject: [PATCH 15/33] remove unused fb_config.yml files. removed oauth_keys.yml from git, updated .example" --- config/fb_config.yml | 4 ---- config/fb_config.yml.example | 4 ---- config/initializers/_load_services.rb | 3 ++- config/oauth_keys.yml | 6 ------ config/oauth_keys.yml.example | 3 +++ 5 files changed, 5 insertions(+), 15 deletions(-) delete mode 100644 config/fb_config.yml delete mode 100644 config/fb_config.yml.example delete mode 100644 config/oauth_keys.yml diff --git a/config/fb_config.yml b/config/fb_config.yml deleted file mode 100644 index 4c3309fac..000000000 --- a/config/fb_config.yml +++ /dev/null @@ -1,4 +0,0 @@ -fb_api_key: {dcf4e90df086cf6d3e531b31e043ff32} -fb_secret: {7fe864834726f8a5e65bc93928b99a53} -fb_app_id: {120373411325347} -host: http://localhost:3000/ diff --git a/config/fb_config.yml.example b/config/fb_config.yml.example deleted file mode 100644 index 5bb145316..000000000 --- a/config/fb_config.yml.example +++ /dev/null @@ -1,4 +0,0 @@ -fb_api_key: {key} -fb_secret: {secret} -fb_app_id: {app_id} -host: http://localhost:3000/ diff --git a/config/initializers/_load_services.rb b/config/initializers/_load_services.rb index d65f2a695..ef41d75a7 100644 --- a/config/initializers/_load_services.rb +++ b/config/initializers/_load_services.rb @@ -10,6 +10,7 @@ oauth_keys_file = "#{Rails.root}/config/oauth_keys.yml" if File.exist? oauth_keys_file SERVICES = load_config_yaml(oauth_keys_file) - SERVICES ||= load_config_yaml("#{oauth_keys_file}.example") end +SERVICES ||= load_config_yaml("#{oauth_keys_file}.example") + diff --git a/config/oauth_keys.yml b/config/oauth_keys.yml deleted file mode 100644 index c3dc20afd..000000000 --- a/config/oauth_keys.yml +++ /dev/null @@ -1,6 +0,0 @@ -twitter: - consumer_key: no69jTnL5SCOnWgk5XWqbQ - consumer_secret: 2DZyu8DA43AIeFsRVdz8OtAHLvCtPjdRKdNO3UZGqWM -facebook: - app_id: 120373411325347 - app_secret: 7fe864834726f8a5e65bc93928b99a53 diff --git a/config/oauth_keys.yml.example b/config/oauth_keys.yml.example index 3397b2832..8e1db632a 100644 --- a/config/oauth_keys.yml.example +++ b/config/oauth_keys.yml.example @@ -1,3 +1,6 @@ twitter: consumer_key: "" consumer_secret: "" +facebook: + app_id: "" + app_secret: "" From 060d8f9c7bb6b240d6f8b1fc9939e1932f86db5a Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 19:24:48 -0700 Subject: [PATCH 16/33] DG MS; fixed some bugs with posting publicly. --- app/controllers/status_messages_controller.rb | 12 ++++----- app/models/user.rb | 26 +++++++------------ app/views/shared/_publisher.haml | 2 +- .../status_message_controller_spec.rb | 16 +++++------- spec/models/user/posting_spec.rb | 11 ++++---- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 89cf59f32..cf6625839 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,9 +9,13 @@ class StatusMessagesController < ApplicationController respond_to :json, :only => :show def create + public_flag = params[:status_message][:public] + public_flag.match(/(true)/) ? public_flag = true : public_flag = false + params[:status_message][:public] = public_flag + data = clean_hash params[:status_message] message = params[:status_message][:message] - @status_message = current_user.post(:status_message, data) + status_message = current_user.post(:status_message, data) render :nothing => true end @@ -23,11 +27,7 @@ class StatusMessagesController < ApplicationController def show @status_message = current_user.find_visible_post_by_id params[:id] - unless @status_message - render :status => 404 - else - respond_with @status_message - end + respond_with @status_message end private diff --git a/app/models/user.rb b/app/models/user.rb index 8c179c239..6a184b156 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -155,31 +155,25 @@ class User post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) push_to_aspects(post, aspect_ids) - if options[:public] + if options[:public] == true self.services.each do |service| - self.send("post_to_#{service.provider}".to_sym) + self.send("post_to_#{service.provider}".to_sym, service, post.message) end end post end - def post_to_facebook(message) - facebook = self.services.find_by_provider("facebook") - if facebook - Rails.logger.info("Sending a message: #{message} to Facebook") - EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{facebook.access_token}").post - end + def post_to_facebook(service, message) + Rails.logger.info("Sending a message: #{message} to Facebook") + EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post end - def post_to_twitter(message) - twitter = self.services.find_by_provider("twitter") - if twitter - oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret']) - oauth.authorize_from_access(twitter.access_token, twitter.access_secret) - client = Twitter::Base.new(oauth) - client.update(message) - end + def post_to_twitter(service, message) + oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret']) + oauth.authorize_from_access(service.access_token, service.access_secret) + client = Twitter::Base.new(oauth) + client.update(message) end def update_post(post, post_hash = {}) diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index 5e3be8f2a..4ac7c5392 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -35,7 +35,7 @@ - if aspect == :all .public_toggle - = status.check_box( :public, :value => false ) + = status.check_box( :public, {}, true, false ) make public = link_to '(?)', "#question_mark_pane", :class => 'question_mark' diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 536db40d4..0869972b3 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -16,35 +16,33 @@ describe StatusMessagesController do end describe '#create' do - let(:status_message_hash) {{"status_message"=>{"public"=>"1", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}} - + let(:status_message_hash) {{"status_message"=>{"public"=>"true", "message"=>"facebook, is that you?", "to" =>"#{aspect.id}"}}} context "posting out to facebook" do - before do - @controller.stub!(:logged_into_fb?).and_return(true) - end + let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } it 'should post to facebook when public is set' do user.should_receive(:post_to_facebook) post :create, status_message_hash end - it 'should not post to facebook when public in not set' do - status_message_hash['status_message']['public'] = '0' + it 'should not post to facebook when public is not set' do + status_message_hash['status_message']['public'] = 'false' user.should_not_receive(:post_to_facebook) post :create, status_message_hash end end - context "posting to twitter" do + let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s } + it 'should post to twitter if public is set' do user.should_receive(:post_to_twitter).and_return(true) post :create, status_message_hash end it 'should not post to twitter when public in not set' do - status_message_hash['status_message']['public'] = '0' + status_message_hash['status_message']['public'] = 'false' user.should_not_receive(:post_to_twitter) post :create, status_message_hash end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index f21bad8a7..5e1b115ae 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -13,8 +13,8 @@ describe User do let!(:aspect1) { user.aspect(:name => 'other') } let!(:aspect2) { user2.aspect(:name => 'losers') } - let!(:service1) { user.services << Factory(:service, :provider => 'twitter') } - let!(:service2) { user.services << Factory(:service, :provider => 'facebook') } + let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s } + let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s } describe '#validate_aspect_permissions' do @@ -56,9 +56,10 @@ describe User do end it "posts to services if post is public" do - user.should_receive(:post_to_twitter).exactly(1).times - user.should_receive(:post_to_facebook).exactly(1).times - user.post :status_message, :message => "hi", :to => "all", :public => true + message = "hello, world!" + user.should_receive(:post_to_twitter).with(service1, message).exactly(1).times + user.should_receive(:post_to_facebook).with(service2, message).exactly(1).times + user.post :status_message, :message => message, :to => "all", :public => true end it "does not post to services if post is not public" do From a1d00d41e50c66d25aec8e98f64fc98fccffcff3 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Mon, 25 Oct 2010 19:33:23 -0700 Subject: [PATCH 17/33] deploys back to master --- config/deploy_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy_config.yml b/config/deploy_config.yml index dda2cc200..06a6747e1 100644 --- a/config/deploy_config.yml +++ b/config/deploy_config.yml @@ -6,7 +6,7 @@ cross_server: deploy_to: '/usr/local/app/diaspora' user: 'root' repo: 'git://github.com/diaspora/diaspora.git' - branch: 'twitter' + branch: 'master' default_env: 'development' servers: tom: From 33410899d9db557b6ad593ad959e30483f82bb18 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Mon, 25 Oct 2010 21:38:53 -0700 Subject: [PATCH 18/33] Fix for build breakage --- config/initializers/_load_services.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/config/initializers/_load_services.rb b/config/initializers/_load_services.rb index ef41d75a7..e893ce9ae 100644 --- a/config/initializers/_load_services.rb +++ b/config/initializers/_load_services.rb @@ -8,9 +8,12 @@ end oauth_keys_file = "#{Rails.root}/config/oauth_keys.yml" -if File.exist? oauth_keys_file - SERVICES = load_config_yaml(oauth_keys_file) -end - -SERVICES ||= load_config_yaml("#{oauth_keys_file}.example") +SERVICES = nil +silence_warnings do + if File.exist? oauth_keys_file + SERVICES = load_config_yaml(oauth_keys_file) + else + SERVICES = load_config_yaml("#{oauth_keys_file}.example") + end +end \ No newline at end of file From 69fc293829ea42dea3b4963e65e0ed6bbb4ffa1a Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Mon, 25 Oct 2010 21:54:13 -0700 Subject: [PATCH 19/33] CI does a clean checkout --- cruise_config.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/cruise_config.rb b/cruise_config.rb index a5efcd3d7..04b5bb284 100644 --- a/cruise_config.rb +++ b/cruise_config.rb @@ -2,4 +2,5 @@ require 'fileutils' Project.configure do |project| project.build_command = './ci.sh' + project.do_clean_checkout :always end From cd67d38a24ef8fc3b172855b379f4ab39a458f3c Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Mon, 25 Oct 2010 22:00:33 -0700 Subject: [PATCH 20/33] Clean checkout: bad idea. --- cruise_config.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/cruise_config.rb b/cruise_config.rb index 04b5bb284..a5efcd3d7 100644 --- a/cruise_config.rb +++ b/cruise_config.rb @@ -2,5 +2,4 @@ require 'fileutils' Project.configure do |project| project.build_command = './ci.sh' - project.do_clean_checkout :always end From ed99f29a09dea11b637ad01883f321acdd6255b2 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 22:03:36 -0700 Subject: [PATCH 21/33] dont show service if you dont have the keys for it. also, update deploy script --- app/views/services/index.html.haml | 4 ++-- config/deploy.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index ea375e9ac..5bec55933 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -23,6 +23,6 @@ = service.nickname = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete - %h4= link_to "Connect to twitter", "/auth/twitter" - %h4= link_to "Connect to facebook", "/auth/facebook" + %h4= link_to "Connect to twitter", "/auth/twitter" if SERVICES['twitter']['consumer_key']!= "" + %h4= link_to "Connect to facebook", "/auth/facebook" if SERVICES['facebook']['app_id'] !="" diff --git a/config/deploy.rb b/config/deploy.rb index b4893ec93..91fab2f85 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -56,9 +56,9 @@ namespace :deploy do run "ln -s -f #{shared_path}/app_config.yml #{current_path}/config/app_config.yml" end - task :symlink_fb_config do - run "touch #{shared_path}/fb_config.yml" - run "ln -s -f #{shared_path}/fb_config.yml #{current_path}/config/fb_config.yml" + task :symlink_oauth_keys_config do + run "touch #{shared_path}/oauth_keys.yml" + run "ln -s -f #{shared_path}/oauth_keys.yml #{current_path}/config/oauth_keys.yml" end task :start do From a992c5fbc218ed8c813240e75b153fed92ef53be Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 22:03:36 -0700 Subject: [PATCH 22/33] dont show service if you dont have the keys for it. also, update deploy script --- app/views/services/index.html.haml | 4 ++-- config/deploy.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index ea375e9ac..5bec55933 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -23,6 +23,6 @@ = service.nickname = link_to "disconnect", service, :confirm => "disconnect #{service.provider}?", :method => :delete - %h4= link_to "Connect to twitter", "/auth/twitter" - %h4= link_to "Connect to facebook", "/auth/facebook" + %h4= link_to "Connect to twitter", "/auth/twitter" if SERVICES['twitter']['consumer_key']!= "" + %h4= link_to "Connect to facebook", "/auth/facebook" if SERVICES['facebook']['app_id'] !="" diff --git a/config/deploy.rb b/config/deploy.rb index b4893ec93..09d8c0bc3 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -56,9 +56,9 @@ namespace :deploy do run "ln -s -f #{shared_path}/app_config.yml #{current_path}/config/app_config.yml" end - task :symlink_fb_config do - run "touch #{shared_path}/fb_config.yml" - run "ln -s -f #{shared_path}/fb_config.yml #{current_path}/config/fb_config.yml" + task :symlink_oauth_keys_config do + run "touch #{shared_path}/oauth_keys.yml" + run "ln -s -f #{shared_path}/oauth_keys.yml #{current_path}/config/oauth_keys.yml" end task :start do @@ -157,4 +157,4 @@ namespace :db do end -after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle", 'deploy:symlink_config', 'deploy:symlink_fb_config' +after "deploy:symlink", "deploy:symlink_images", "deploy:symlink_bundle", 'deploy:symlink_config', 'deploy:symlink_oauth_keys_config' From af917557f601a06f7056f5edea92a683bd5b54b1 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 25 Oct 2010 22:56:50 -0700 Subject: [PATCH 23/33] can't call match on nil --- app/controllers/status_messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index cf6625839..a5c018af2 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -10,7 +10,7 @@ class StatusMessagesController < ApplicationController def create public_flag = params[:status_message][:public] - public_flag.match(/(true)/) ? public_flag = true : public_flag = false + public_flag.to_s.match(/(true)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag data = clean_hash params[:status_message] From ff13cad116edc5875bfd9147ecf697392400008b Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 12:19:32 -0700 Subject: [PATCH 24/33] names of people display immediately on aspect#manage page --- public/javascripts/aspect-edit.js | 4 ++++ public/javascripts/view.js | 1 + 2 files changed, 5 insertions(+) diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 9e565e4b2..4b6f1c421 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -25,8 +25,12 @@ $(function() { revert: true, start: function(event,ui){ $(this).children("img").animate({'height':80, 'width':80, 'opacity':0.8},200); + $(this).children("img").tipsy("hide"); $(".draggable_info").fadeIn(100); }, + drag: function(event,ui){ + $(this).children("img").tipsy("hide"); //ensure this is hidden + }, stop: function(event,ui){ $(this).children("img").animate({'height':70, 'width':70, 'opacity':1},200); $(".draggable_info").fadeOut(100); diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 0b3987d53..26b3fea55 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -76,6 +76,7 @@ $(document).ready(function(){ $("img", "#left_pane").tipsy({live:true}); $(".add_aspect_button", "#aspect_nav").tipsy({gravity:'w'}); + $(".person img", ".dropzone").tipsy({live:true}); });//end document ready From 7f1d87f4241206ccaf3e6626e4e2d2110c2e92b8 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 12:57:43 -0700 Subject: [PATCH 25/33] fixed pagination bug on aspect#show (re: #445) --- app/controllers/aspects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 0129c0abf..985fb68a9 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -48,7 +48,7 @@ class AspectsController < ApplicationController render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @friends = @aspect.people - @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' + @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC' respond_with @aspect end end From d8ca91769fbe1068b3a5c3ea06bd127065e98b94 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 13:03:45 -0700 Subject: [PATCH 26/33] dragging a person to Remove from Aspect on aspect#manage fades person correctly (re: #442) --- public/javascripts/aspect-edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index 4b6f1c421..e4a581d57 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -92,7 +92,7 @@ $(function() { 'aspect_id' : person.attr('data-aspect_id') } }); } - person.fadeOut('slow', $(this).remove()); + person.fadeOut(400, function(){person.remove();}); } } }); From 8acdf212345e9c73d221a8d024d19b9b4af2a833 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 26 Oct 2010 14:49:37 -0700 Subject: [PATCH 27/33] MS IZ got rid of the requests for me scope in the user --- app/models/request.rb | 2 - app/models/user.rb | 10 ++--- lib/diaspora/user/friending.rb | 11 +++-- spec/models/request_spec.rb | 11 ----- spec/models/user/user_friending_spec.rb | 53 +++++++++++++++++-------- spec/spec_helper.rb | 1 + 6 files changed, 48 insertions(+), 40 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index a6efdc987..2226a7b45 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -26,8 +26,6 @@ class Request validates_presence_of :destination_url, :callback_url before_validation :clean_link - scope :for_user, lambda{ |user| where(:destination_url => user.person.receive_url) } - def self.instantiate(options = {}) person = options[:from] self.new(:destination_url => options[:to], diff --git a/app/models/user.rb b/app/models/user.rb index 6a184b156..850a2bb66 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,11 +32,11 @@ class User 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 :inviter_ids, Array, :typecast => 'ObjectId' + key :friend_ids, Array, :typecast => 'ObjectId' + key :pending_request_ids, Array, :typecast => 'ObjectId' + key :visible_post_ids, Array, :typecast => 'ObjectId' + key :visible_person_ids, Array, :typecast => 'ObjectId' key :invite_messages, Hash diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index 4a19ffd68..131b5b96a 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -29,9 +29,8 @@ module Diaspora end def accept_friend_request(friend_request_id, aspect_id) - request = Request.find_by_id(friend_request_id) - pending_requests.delete(request) - + request = pending_requests.find!(friend_request_id) + pending_request_ids.delete(request.id.to_id) activate_friend(request.person, aspect_by_id(aspect_id)) request.reverse_for(self) @@ -45,16 +44,16 @@ module Diaspora end def accept_and_respond(friend_request_id, aspect_id) - requester = Request.find_by_id(friend_request_id).person + requester = pending_requests.find!(friend_request_id).person reversed_request = accept_friend_request(friend_request_id, aspect_id) dispatch_friend_acceptance reversed_request, requester end def ignore_friend_request(friend_request_id) - request = Request.find_by_id(friend_request_id) + request = pending_requests.find!(friend_request_id) person = request.person - self.pending_requests.delete(request) + self.pending_request_ids.delete(request.id) self.save person.save diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 6483c45fa..6e5dfbf57 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -31,17 +31,6 @@ describe Request do xml.should include user.exported_key end - it 'should allow me to see only friend requests sent to me' do - remote_person = Factory.build(:person, :diaspora_handle => "robert@grimm.com", :url => "http://king.com/") - - Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save - Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save - Request.instantiate(:into => aspect.id, :from => user.person, :to => remote_person.receive_url).save - Request.instantiate(:into => aspect.id, :from => remote_person, :to => user.receive_url).save - - Request.for_user(user).all.count.should == 1 - end - it 'should strip the destination url' do person_request = Request.new person_request.destination_url = " http://google.com/ " diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 63a472031..8a4386601 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -25,7 +25,7 @@ describe Diaspora::UserModules::Friending do end context 'friend requesting' do - it "should assign a request to a aspect" do + it "should assign a request to a aspect for the user that sent it out" do aspect.requests.size.should == 0 user.send_friend_request_to(friend, aspect) @@ -34,21 +34,42 @@ describe Diaspora::UserModules::Friending do aspect.requests.size.should == 1 end - it "should be able to accept a pending friend request" do - r = Request.instantiate(:to => user.receive_url, :from => friend) - r.save + describe '#receive_friend_request' do + it 'adds a request to pending if it was not sent by user' do + r = Request.instantiate(:to => user.receive_url, :from => friend) + r.save + user.receive_friend_request(r) + user.reload.pending_requests.should include r + end + + it 'should autoaccept a request the user sent' do + request = user.send_friend_request_to(user2.person, aspect) + request.reverse_for(user2) + proc{user.receive_friend_request(request)}.should change(user.reload.friends, :count).by(1) + end - proc { user.accept_friend_request(r.id, aspect.id) }.should change { - Request.for_user(user).all.count }.by(-1) end - it 'should be able to ignore a pending friend request' do - friend = Factory.create(:person) - r = Request.instantiate(:to => user.receive_url, :from => friend) - r.save + context 'received a friend request' do - proc { user.ignore_friend_request(r.id) }.should change { - Request.for_user(user).count }.by(-1) + let(:request_for_user) {Request.instantiate(:to => user.receive_url, :from => friend)} + let(:request2_for_user) {Request.instantiate(:to => user.receive_url, :from => person_one)} + before do + request_for_user.save + user.receive_friend_request(request_for_user) + user.receive_friend_request(request2_for_user) + user.reload + end + + it "should delete an accepted friend request" do + proc { user.accept_friend_request(request2_for_user.id, aspect.id) }.should change( + user.reload.pending_requests, :count ).by(-1) + end + + it 'should be able to ignore a pending friend request' do + proc { user.ignore_friend_request(request_for_user.id) }.should change ( + user.reload.pending_requests, :count ).by(-1) + end end it 'should not be able to friend request an existing friend' do @@ -168,20 +189,20 @@ describe Diaspora::UserModules::Friending do user.receive_friend_request @request person_two.destroy - user.pending_requests.size.should be 1 + user.reload.pending_requests.size.should be 1 user.friends.size.should be 0 user.receive_friend_request @request_two - user.pending_requests.size.should be 2 + user.reload.pending_requests.size.should be 2 user.friends.size.should be 0 user.accept_friend_request @request.id, aspect.id - user.pending_requests.size.should be 1 + user.reload.pending_requests.size.should be 1 user.friends.size.should be 1 user.friends.include?(person_one).should be true user.ignore_friend_request @request_two.id - user.pending_requests.size.should be 0 + user.reload.pending_requests.size.should be 0 user.friends.size.should be 1 user.friends.include?(person_two).should be false end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 29d731b29..11f18d8d2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -67,6 +67,7 @@ ImageUploader.enable_processing = false def friend_users(user1, aspect1, user2, aspect2) request = user1.send_friend_request_to(user2.person, aspect1) + user2.receive_friend_request(request) reversed_request = user2.accept_friend_request( request.id, aspect2.id) user1.reload user1.receive reversed_request.to_diaspora_xml, user2.person From 6e015790a79e2ef75ba8d09c5f988abde432c9d7 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 16:02:53 -0700 Subject: [PATCH 28/33] settings are more restful with account settings submitting to users#update, and profile settings submitting to person#update --- app/controllers/people_controller.rb | 36 ++++++++++- app/controllers/users_controller.rb | 30 +-------- app/views/people/edit.html.haml | 67 ++++++++++++++++++++ app/views/services/index.html.haml | 4 +- app/views/users/_account.haml | 41 ------------ app/views/users/_profile.haml | 58 ----------------- app/views/users/edit.html.haml | 42 +++++++++++-- config/locales/diaspora/en.yml | 24 ++++---- config/routes.rb | 2 +- spec/controllers/people_controller_spec.rb | 33 +++++++--- spec/controllers/users_controller_spec.rb | 72 ++++++---------------- 11 files changed, 200 insertions(+), 209 deletions(-) create mode 100644 app/views/people/edit.html.haml delete mode 100644 app/views/users/_account.haml delete mode 100644 app/views/users/_profile.haml diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 352a39c92..46230f811 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -23,8 +23,6 @@ class PeopleController < ApplicationController @profile = @person.profile @aspects_with_person = current_user.aspects_with_person(@person) @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' - @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last - @post_count = @posts.count respond_with @person end end @@ -34,4 +32,38 @@ class PeopleController < ApplicationController respond_with :location => root_url end + def edit + @aspect = :person_edit + @person = current_user.person + @profile = @person.profile + @photos = current_user.visible_posts(:person_id => @person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' + end + + def update + prep_image_url(params[:person]) + + if current_user.update_profile params[:person][:profile] + flash[:notice] = "Profile updated" + else + flash[:error] = "Failed to update profile" + end + + redirect_to edit_person_path + end + + private + def prep_image_url(params) + url = APP_CONFIG[:pod_url].dup + url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' + if params[:profile][:image_url].empty? + params[:profile].delete(:image_url) + else + if /^http:\/\// =~ params[:profile][:image_url] + params[:profile][:image_url] = params[:profile][:image_url] + else + params[:profile][:image_url] = url + params[:profile][:image_url] + end + end + end + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9c1bb3e9c..1da5a1734 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,11 +14,8 @@ class UsersController < ApplicationController respond_to :html def edit - @aspect = :user_edit - @user = current_user - @person = @user.person - @profile = @user.person.profile - @photos = current_user.visible_posts(:person_id => current_user.person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' + @aspect = :user_edit + @user = current_user end def update @@ -32,16 +29,9 @@ class UsersController < ApplicationController else flash[:error] = "Password Change Failed" end - else - prep_image_url(params[:user]) - if @user.update_profile params[:user][:profile] - flash[:notice] = "Profile updated" - else - flash[:error] = "Failed to update profile" - end end - redirect_to edit_user_path(@user) + redirect_to edit_user_path(@user) end def destroy @@ -100,19 +90,5 @@ class UsersController < ApplicationController end - private - def prep_image_url(params) - url = APP_CONFIG[:pod_url].dup - url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' - if params[:profile][:image_url].empty? - params[:profile].delete(:image_url) - else - if /^http:\/\// =~ params[:profile][:image_url] - params[:profile][:image_url] = params[:profile][:image_url] - else - params[:profile][:image_url] = url + params[:profile][:image_url] - end - end - end end diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml new file mode 100644 index 000000000..8db35bb3e --- /dev/null +++ b/app/views/people/edit.html.haml @@ -0,0 +1,67 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +#section_header + %h2 + Settings + %ul#settings_nav + %li=link_to 'Profile', edit_person_path(current_user.person) + %li=link_to 'Account', edit_user_path(current_user) + %li=link_to 'Services', services_path + +.span-19.prepend-5.last + %h2 Profile + = form_for @person do |person| + = person.error_messages + + = person.fields_for :profile do |p| + + %h3="#{t('.picture')}" + %div#image_picker + = 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 && @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)), "#" + - else + %div.small_photo{:id => photo.url(:thumb_medium)} + = check_box_tag 'checked_photo' + = link_to image_tag(photo.url(:thumb_medium)), "#" + + - else + =t('.you_dont_have_any_photos') + = link_to t('.albums'), albums_path(:aspect => 'all') + =t('.page_to_upload_some') + + =will_paginate @photos + + %br + + %h3="#{t('.info')}" + + %p + %b + ="#{t('.diaspora_username')}:" + = @person.diaspora_handle + + %p + = p.label :first_name + = p.text_field :first_name, :value => @profile.first_name + %p + = p.label :last_name + = p.text_field :last_name, :value => @profile.last_name + + .submit_block + = link_to t('.cancel'), edit_user_path(current_user) + = t('.or') + = person.submit t('.update_profile') + + #content_bottom + .back + = link_to "⇧ #{t('.home')}", root_path + diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index 5bec55933..8d00f8eb3 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -6,8 +6,8 @@ %h2 Settings %ul#settings_nav - %li=link_to 'Profile', '#', :class => 'profile' - %li=link_to 'Account', '#', :class => 'account' + %li=link_to 'Profile', edit_person_path(current_user.person) + %li=link_to 'Account', edit_user_path(current_user) %li=link_to 'Services', services_path .span-19.prepend-5.last diff --git a/app/views/users/_account.haml b/app/views/users/_account.haml deleted file mode 100644 index e76ae6cc6..000000000 --- a/app/views/users/_account.haml +++ /dev/null @@ -1,41 +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. - - -%h2 Account - -= link_to "invite friends", new_user_invitation_path(current_user) - -%br -%br -%br - -%h3 Change Password -= form_for @user do |f| - = f.error_messages - - %p - = f.label :password, "New Password" - = f.password_field :password - %p - = f.label :password_confirmation - = f.password_field :password_confirmation - - .submit_block - = link_to "Cancel", edit_user_path(current_user) - or - = f.submit 'Change password' - -%h3 Export Data -= link_to "download my xml", users_export_path, :class => "button" -= link_to "download my photos", users_export_photos_path, :class => "button" - -%br -%br -%br - -%h3 Close Account -= link_to "Close Account", current_user, - :confirm => "Are you sure?", :method => :delete, - :class => "button" diff --git a/app/views/users/_profile.haml b/app/views/users/_profile.haml deleted file mode 100644 index cbb2b6d6a..000000000 --- a/app/views/users/_profile.haml +++ /dev/null @@ -1,58 +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. - - -%h2 Profile -= form_for @user do |f| - = f.error_messages - - = f.fields_for :profile do |p| - - %h3="#{t('.picture')}" - %div#image_picker - = 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 && @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)), "#" - - else - %div.small_photo{:id => photo.url(:thumb_medium)} - = check_box_tag 'checked_photo' - = link_to image_tag(photo.url(:thumb_medium)), "#" - - - else - =t('.you_dont_have_any_photos') - = link_to t('.albums'), albums_path(:aspect => 'all') - =t('.page_to_upload_some') - - =will_paginate @photos - - %br - - %h3="#{t('.info')}" - - %p - %b - ="#{t('.diaspora_username')}:" - = @user.diaspora_handle - - %p - = p.label :first_name - = p.text_field :first_name, :value => @profile.first_name - %p - = p.label :last_name - = p.text_field :last_name, :value => @profile.last_name - - .submit_block - = link_to t('.cancel'), edit_user_path(current_user) - = t('.or') - = f.submit t('.update_profile') - -#content_bottom - .back - = link_to "⇧ #{t('.home')}", root_path - diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 104a9e8fd..5317a5095 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -16,14 +16,44 @@ %h2 Settings %ul#settings_nav - %li=link_to 'Profile', '#', :class => 'profile' - %li=link_to 'Account', '#', :class => 'account' + %li=link_to 'Profile', edit_person_path(current_user.person) + %li=link_to 'Account', edit_user_path(current_user) %li=link_to 'Services', services_path .span-19.prepend-5.last - #profile.settings_pane{:style=>"display:block;"} - = render 'users/profile' + %h2 Account - #account.settings_pane - = render 'users/account' + = link_to "invite friends", new_user_invitation_path(current_user) + %br + %br + %br + + %h3 Change Password + = form_for @user do |f| + = f.error_messages + + %p + = f.label :password, "New Password" + = f.password_field :password + %p + = f.label :password_confirmation + = f.password_field :password_confirmation + + .submit_block + = link_to "Cancel", edit_user_path(current_user) + or + = f.submit 'Change password' + + %h3 Export Data + = link_to "download my xml", users_export_path, :class => "button" + = link_to "download my photos", users_export_photos_path, :class => "button" + + %br + %br + %br + + %h3 Close Account + = link_to "Close Account", current_user, + :confirm => "Are you sure?", :method => :delete, + :class => "button" diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 101080ef8..91b80deab 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -116,18 +116,6 @@ en: users: edit: editing_profile: "Editing profile" - profile: - cancel: "Cancel" - update_profile: "Update Profile" - home: "Home" - diaspora_username: "DIASPORA USERNAME" - info: "Info" - picture: "Picture" - editing_profile: "Editing profile" - albums: "Albums" - you_dont_have_any_photos: "You don't have any photos! Go to the" - page_to_upload_some: "page to upload some." - or: "or" destroy: "Account successfully closed." comments: comment: @@ -218,6 +206,18 @@ en: are_you_sure: "Are you sure?" remove_friend: "remove friend" no_posts: "no posts to display!" + edit: + cancel: "Cancel" + update_profile: "Update Profile" + home: "Home" + diaspora_username: "DIASPORA USERNAME" + info: "Info" + picture: "Picture" + editing_profile: "Editing profile" + albums: "Albums" + you_dont_have_any_photos: "You don't have any photos! Go to the" + page_to_upload_some: "page to upload some." + or: "or" requests: new_request: add_a_new_friend_to: "Add a new friend to" diff --git a/config/routes.rb b/config/routes.rb index b9b05ca65..e46a65b0a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. Diaspora::Application.routes.draw do - resources :people, :only => [:index, :show, :destroy] + resources :people resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 26bf2a804..64e10b94e 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -6,22 +6,22 @@ require 'spec_helper' describe PeopleController do render_views - before do - @user = Factory.create(:user) - sign_in :user, @user - @user.aspect(:name => "lame-os") + let(:user) { Factory(:user) } + let!(:aspect) { user.aspect(:name => "lame-os") } + + before do + sign_in :user, user end it "index should yield search results for substring of person name" do - eugene = Factory.create(:person, :profile => {:first_name => "Eugene", :last_name => "w"}) get :index, :q => "Eu" assigns[:people].should include eugene end it 'should go to the current_user show page' do - get :show, :id => @user.person.id + get :show, :id => user.person.id end it "doesn't error out on an invalid id" do @@ -29,6 +29,25 @@ describe PeopleController do end it "doesn't error out on a nonexistent person" do - get :show, :id => @user.id + get :show, :id => user.id + end + + describe '#update' do + context 'with a profile photo set' do + it "doesn't overwrite the profile photo when an empty string is passed in" do + user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" + user.person.profile.save + + params = {"profile"=> + {"image_url" => "", + "last_name" => user.person.profile.last_name, + "first_name" => user.person.profile.first_name}} + + image_url = user.person.profile.image_url + put("update", :id => user.person.id, "person" => params) + + user.person.profile.image_url.should == image_url + end + end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index f00a519db..93790c681 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -5,10 +5,14 @@ require 'spec_helper' describe UsersController do + + let(:user) { Factory(:user) } + let!(:aspect) { user.aspect(:name => "lame-os") } + + let!(:old_password) { user.encrypted_password } + before do - @user = Factory.create(:user) - sign_in :user, @user - @user.aspect(:name => "lame-os") + sign_in :user, user end describe '#export' do @@ -18,67 +22,29 @@ describe UsersController do end end - describe '#update' do - context 'with a profile photo set' do - before do - @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" - @user.person.profile.save - - @params = {"profile"=> - {"image_url" => "", - "last_name" => @user.person.profile.last_name, - "first_name" => @user.person.profile.first_name}} - end - - it "doesn't overwrite the profile photo when an empty string is passed in" do - image_url = @user.person.profile.image_url - put("update", :id => @user.id, "user" => @params) - - @user.person.profile.image_url.should == image_url - end - it "doesn't overwrite random attributes" do - new_user = Factory.create(:user) - @params[:owner_id] = new_user.id - person = @user.person - put('update', :id => @user.id, "user" => @params) - Person.find(person.id).owner_id.should == @user.id - end + it "doesn't overwrite random attributes" do + params = {:diaspora_handle => "notreal@stuff.com"} + proc{ put 'update', :id => user.id, "user" => params }.should_not change(user, :diaspora_handle) end context 'should allow the user to update their password' do it 'should change a users password ' do - old_password = @user.encrypted_password - - put("update", :id => @user.id, "user"=> {"password" => "foobaz", 'password_confirmation' => "foobaz","profile"=> - {"image_url" => "", - "last_name" => @user.person.profile.last_name, - "first_name" => @user.person.profile.first_name}}) - - @user.reload - @user.encrypted_password.should_not == old_password + put("update", :id => user.id, "user"=> {"password" => "foobaz", 'password_confirmation' => "foobaz"}) + user.reload + user.encrypted_password.should_not == old_password end it 'should not change a password if they do not match' do - old_password = @user.encrypted_password - put("update", :id => @user.id, "user"=> {"password" => "foobarz", 'password_confirmation' => "not_the_same","profile"=> - {"image_url" => "", - "last_name" => @user.person.profile.last_name, - "first_name" => @user.person.profile.first_name}}) - @user.reload - @user.encrypted_password.should == old_password + put("update", :id => user.id, "user"=> {"password" => "foobarz", 'password_confirmation' => "not_the_same"}) + user.reload + user.encrypted_password.should == old_password end - it 'should not update if the password fields are left blank' do - - old_password = @user.encrypted_password - put("update", :id => @user.id, "user"=> {"password" => "", 'password_confirmation' => "","profile"=> - {"image_url" => "", - "last_name" => @user.person.profile.last_name, - "first_name" => @user.person.profile.first_name}}) - @user.reload - @user.encrypted_password.should == old_password + put("update", :id => user.id, "user"=> {"password" => "", 'password_confirmation' => ""}) + user.reload + user.encrypted_password.should == old_password end end end From e62afae045088b6e9397041688238928a422bf03 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 16:12:58 -0700 Subject: [PATCH 29/33] deselected tabs in top nav, made user drop down a bit clearer --- app/views/layouts/application.html.haml | 5 +++-- public/stylesheets/sass/application.sass | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 0e21eb7de..7f6cf94cf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -55,8 +55,9 @@ .avatar = owner_image_tag = link_to current_user.real_name, '#' - %li= link_to "profile", current_user.person - %li= link_to "settings", edit_user_path(current_user) + %li= link_to "view profile", current_user.person + %li= link_to "edit profile", edit_person_path(current_user.person) + %li= link_to "account settings", edit_user_path(current_user) %li= link_to t('.logout.'), destroy_user_session_path = render "shared/aspect_nav" diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index c4da5d4fc..739a0ffac 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -855,6 +855,9 @@ h1.big_text :padding 4px 10px :color #CCC + :background + :color #222 + &:hover :background :color #000 From f314ab39dfc537dcf2eef5029e5cdcc6f8f90320 Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Tue, 26 Oct 2010 19:05:18 -0700 Subject: [PATCH 30/33] At some point, we should upgrade database_cleaner to 0.6.0. That point is not now. (It breaks cucumber.) --- Gemfile | 2 +- Gemfile.lock | 75 +++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index cd11c7ceb..ddff8fa21 100644 --- a/Gemfile +++ b/Gemfile @@ -58,7 +58,7 @@ group :test do gem 'rspec', '>= 2.0.0' gem 'rspec-rails', '>= 2.0.0' gem 'mocha' - gem 'database_cleaner' + gem 'database_cleaner', '0.5.2' gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 1abff88d1..dc26a8bf9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,8 @@ GIT remote: git://github.com/Empact/roxml.git - revision: 33034d3e632b3a14565a791af0a63c7e23ec0de4 + revision: d411519add92e0cd5a985253f376d25c26884324 specs: - roxml (3.1.5) + roxml (3.1.6) activesupport (>= 2.3.0) nokogiri (>= 1.3.3) @@ -141,10 +141,10 @@ GEM columnize (0.3.1) configuration (1.1.0) crack (0.1.8) - cucumber (0.9.2) + cucumber (0.9.3) builder (~> 2.1.2) diff-lcs (~> 1.1.2) - gherkin (~> 2.2.5) + gherkin (~> 2.2.9) json (~> 1.4.6) term-ansicolor (~> 1.0.5) cucumber-rails (0.3.2) @@ -169,9 +169,10 @@ GEM factory_girl_rails (1.0) factory_girl (~> 1.3) rails (>= 3.0.0.beta4) - faraday (0.4.6) - addressable (>= 2.1.1) - rack (>= 1.0.1) + faraday (0.5.1) + addressable (~> 2.2.2) + multipart-post (~> 1.0.1) + rack (~> 1.2.1) ffi (0.6.3) rake (>= 0.8.7) gherkin (2.2.9) @@ -183,17 +184,18 @@ GEM http_connection (1.4.0) httparty (0.6.1) crack (= 0.1.8) - i18n (0.4.1) + i18n (0.4.2) json (1.4.6) json_pure (1.4.6) launchy (0.3.7) configuration (>= 0.0.5) rake (>= 0.8.1) linecache (0.43) - mail (2.2.7) + mail (2.2.9) activesupport (>= 2.3.6) - mime-types - treetop (>= 1.4.5) + i18n (~> 0.4.1) + mime-types (~> 1.16) + treetop (~> 1.4.8) mime-types (1.16) mini_fb (1.1.3) hashie @@ -205,12 +207,13 @@ GEM mixlib-cli (1.2.0) mixlib-config (1.1.2) mixlib-log (1.2.0) - mocha (0.9.8) + mocha (0.9.9) rake moneta (0.6.0) mongo (1.1) bson (>= 1.0.5) multi_json (0.0.4) + multipart-post (1.0.1) net-ldap (0.1.1) net-scp (1.0.4) net-ssh (>= 1.99.1) @@ -220,33 +223,33 @@ GEM net-ssh-gateway (1.0.1) net-ssh (>= 1.99.1) nokogiri (1.4.3.1) - oa-basic (0.1.5) + oa-basic (0.1.6) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) rest-client (~> 1.6.0) - oa-core (0.1.5) + oa-core (0.1.6) rack (~> 1.1) - oa-enterprise (0.1.5) + oa-enterprise (0.1.6) net-ldap (~> 0.1.1) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) pyu-ruby-sasl (~> 0.0.3.1) rubyntlm (~> 0.1.1) - oa-oauth (0.1.5) + oa-oauth (0.1.6) multi_json (~> 0.0.2) nokogiri (~> 1.4.2) - oa-core (= 0.1.5) + oa-core (= 0.1.6) oauth (~> 0.4.0) - oauth2 (~> 0.0.10) - oa-openid (0.1.5) - oa-core (= 0.1.5) - rack-openid (~> 1.1.1) + oauth2 (~> 0.1.0) + oa-openid (0.1.6) + oa-core (= 0.1.6) + rack-openid (~> 1.2.0) ruby-openid-apps-discovery oauth (0.4.3) - oauth2 (0.0.13) - faraday (~> 0.4.1) - multi_json (>= 0.0.4) + oauth2 (0.1.0) + faraday (~> 0.5.0) + multi_json (~> 0.0.4) ohai (0.5.8) extlib json (>= 1.4.4, <= 1.4.6) @@ -254,12 +257,12 @@ GEM mixlib-config mixlib-log systemu - omniauth (0.1.5) - oa-basic (= 0.1.5) - oa-core (= 0.1.5) - oa-enterprise (= 0.1.5) - oa-oauth (= 0.1.5) - oa-openid (= 0.1.5) + omniauth (0.1.6) + oa-basic (= 0.1.6) + oa-core (= 0.1.6) + oa-enterprise (= 0.1.6) + oa-oauth (= 0.1.6) + oa-openid (= 0.1.6) plucky (0.3.6) mongo (~> 1.1) polyglot (0.3.1) @@ -270,9 +273,9 @@ GEM rack (1.2.1) rack-mount (0.6.13) rack (>= 1.0.0) - rack-openid (1.1.2) - rack (>= 0.4) - ruby-openid (>= 2.0.3) + rack-openid (1.2.0) + rack (>= 1.1.0) + ruby-openid (>= 2.1.8) rack-test (0.5.6) rack (>= 1.0) rails (3.0.1) @@ -356,7 +359,7 @@ DEPENDENCIES carrierwave! chef cucumber-rails (= 0.3.2) - database_cleaner + database_cleaner (= 0.5.2) devise (= 1.1.3) devise-mongo_mapper! devise_invitable (~> 0.3.4) From 49c09b9c8c7f7f6f438749bcd39cdfeedf623baf Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 26 Oct 2010 17:04:44 -0700 Subject: [PATCH 31/33] Remove unused clean_hash --- app/controllers/aspects_controller.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 985fb68a9..f92c9426b 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -97,11 +97,4 @@ class AspectsController < ApplicationController end redirect_to aspects_manage_path end - - private - def clean_hash(params) - return { - :name => params[:name] - } - end end From aa819d21135f55d89a073283de4be5cda0bd59f1 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 26 Oct 2010 19:15:41 -0700 Subject: [PATCH 32/33] Putting an index on Person#diaspora_handle --- app/models/person.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/person.rb b/app/models/person.rb index 5a1486653..58e637557 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -40,6 +40,8 @@ class Person validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix + ensure_index :diaspora_handle + def self.search(query) return Person.all if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") From 039bf374d889b4ad8260398ce8b400eb487ca9b4 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 26 Oct 2010 23:38:12 -0700 Subject: [PATCH 33/33] soft shadow on header --- public/stylesheets/sass/application.sass | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 739a0ffac..3c468e659 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -105,8 +105,12 @@ header :margin -2em :bottom 2em :color #000 + :background :color #333 + :background -webkit-gradient( linear, left bottom, left top, color-stop(0.01, rgb(31,31,31)), color-stop(0.12, rgb(51,51,51))) + :background -moz-linear-gradient( center bottom, rgb(31,31,31) 1%, rgb(51,51,51) 12%) + :padding 0 :top 5px :color #CCC @@ -873,7 +877,7 @@ h1.big_text :font :weight bold :background - :color rgba(252,252,252,1) + :color rgb(252,252,252) :color #444 &:hover