From 82c82b8cccca5a0f82ba1c89b2ecafca1d6994b3 Mon Sep 17 00:00:00 2001 From: danielvincent <danielgrippi@gmail.com> Date: Thu, 4 Nov 2010 00:27:13 -0700 Subject: [PATCH] killed albums --- app/controllers/albums_controller.rb | 89 --------------------- app/controllers/dev_utilities_controller.rb | 4 +- app/controllers/photos_controller.rb | 30 +++---- app/helpers/albums_helper.rb | 21 ----- app/helpers/photos_helper.rb | 17 ---- app/models/album.rb | 44 ---------- app/models/comment.rb | 1 + app/models/person.rb | 1 - app/models/photo.rb | 16 +--- app/models/user.rb | 7 +- app/views/albums/_album.html.haml | 18 ----- app/views/albums/_new_album.haml | 12 --- app/views/albums/edit.html.haml | 25 ------ app/views/albums/index.html.haml | 14 ---- app/views/albums/show.html.haml | 46 ----------- app/views/aspects/index.html.haml | 4 +- app/views/aspects/show.html.haml | 4 +- app/views/people/show.html.haml | 2 +- app/views/photos/_new_photo.haml | 2 +- app/views/photos/_photo.haml | 6 +- app/views/photos/edit.html.haml | 10 +-- app/views/photos/index.html.haml | 14 +--- app/views/photos/show.html.haml | 22 +++-- app/views/shared/_publisher.haml | 71 +++++++--------- config/locales/diaspora/en.yml | 31 ------- config/routes.rb | 1 - lib/collect_user_photos.rb | 16 ++-- lib/diaspora/user/querying.rb | 4 - spec/controllers/albums_controller_spec.rb | 54 ------------- spec/controllers/photos_controller_spec.rb | 33 ++------ spec/controllers/sockets_controller_spec.rb | 5 +- spec/helper_methods.rb | 6 ++ spec/models/album_spec.rb | 83 ------------------- spec/models/photo_spec.rb | 13 +-- spec/models/user/attack_vectors_spec.rb | 8 +- spec/models/user/posting_spec.rb | 23 ++---- spec/models/user/querying_spec.rb | 20 ----- spec/models/user/receive_spec.rb | 13 +-- spec/models/user_spec.rb | 6 +- 39 files changed, 108 insertions(+), 688 deletions(-) delete mode 100644 app/controllers/albums_controller.rb delete mode 100644 app/helpers/albums_helper.rb delete mode 100644 app/helpers/photos_helper.rb delete mode 100644 app/models/album.rb delete mode 100644 app/views/albums/_album.html.haml delete mode 100644 app/views/albums/_new_album.haml delete mode 100644 app/views/albums/edit.html.haml delete mode 100644 app/views/albums/index.html.haml delete mode 100644 app/views/albums/show.html.haml delete mode 100644 spec/controllers/albums_controller_spec.rb delete mode 100644 spec/models/album_spec.rb diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb deleted file mode 100644 index 52ecfa45bb..0000000000 --- a/app/controllers/albums_controller.rb +++ /dev/null @@ -1,89 +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 AlbumsController < ApplicationController - before_filter :authenticate_user! - - respond_to :html - respond_to :json, :only => [:index, :show] - - def index - if params[:person_id] - @person = current_user.visible_people.find_by_person_id(params[:person_id]) - end - @person ||= current_user.person - - @albums = current_user.visible_posts(:_type => 'Album').paginate :page => params[:page], :per_page => 9, :order => 'created_at DESC' - respond_with @albums - end - - def create - aspects = params[:album][:to] - - @album = current_user.build_post(:album, params[:album]) - if @album.save - raise 'MongoMapper failed to catch a failed save' unless @album.id - current_user.dispatch_post(@album, :to => aspects) - flash[:notice] = I18n.t 'albums.create.success', :name => @album.name - redirect_to :action => :show, :id => @album.id, :aspect =>aspects - else - flash[:error] = I18n.t 'albums.create.failure' - redirect_to albums_path(:aspect =>aspects) - end - end - - def new - @album = Album.new - end - - def destroy - @album = current_user.find_visible_post_by_id params[:id] - @album.destroy - flash[:notice] = I18n.t 'albums.destroy.success', :name => @album.name - respond_with :location => albums_url - end - - def show - @person = current_user.visible_people.find_by_person_id(params[:person_id]) if params[:person_id] - @person ||= current_user.person - - @album = :uploads if params[:id] == "uploads" - @album ||= current_user.find_visible_post_by_id(params[:id]) - - unless @album - render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 - else - - if @album == :uploads - @album_id = nil - @album_name = "Uploads" - @album_photos = current_user.visible_posts(:_type => "Photo", :album_id => nil, :person_id => @person.id) - - else - @album_id = @album.id - @album_name = @album.name - @album_photos = @album.photos - end - - respond_with @album - end - end - - def edit - @album = current_user.find_visible_post_by_id params[:id] - redirect_to @album unless current_user.owns? @album - end - - def update - @album = current_user.find_visible_post_by_id params[:id] - - if current_user.update_post( @album, params[:album] ) - flash[:notice] = I18n.t 'albums.update.success', :name => @album.name - respond_with @album - else - flash[:error] = I18n.t 'albums.update.failure', :name => @album.name - render :action => :edit - end - end -end diff --git a/app/controllers/dev_utilities_controller.rb b/app/controllers/dev_utilities_controller.rb index 8300258433..1b376216bd 100644 --- a/app/controllers/dev_utilities_controller.rb +++ b/app/controllers/dev_utilities_controller.rb @@ -56,15 +56,13 @@ class DevUtilitiesController < ApplicationController def set_profile_photo render :nothing => true - album = current_user.build_post(:album, :name => "Profile Photos") - current_user.dispatch_post(album, :to => current_user.aspects.first.id) backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i username = backer_info[backer_number]['username'].gsub(/ /,'').downcase @fixture_name = File.join(File.dirname(__FILE__), "..", "..", "public", "images", "user", "#{username}.jpg") - photo = Photo.new(:album => album) + photo = Photo.new photo.person = current_user.person photo.image.store! File.open(@fixture_name) photo.save diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 51fcf13a5b..87f02a6b35 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -10,18 +10,17 @@ class PhotosController < ApplicationController def index if params[:person_id] - @person = current_user.contact_for_person_id(params[:person_id]).person + @person = current_user.contact_for_person_id(params[:person_id]) + @person = @person.person if @person end @person ||= current_user.person @photos = current_user.visible_posts(:_type => "Photo", :person_id => @person.id) - @albums = current_user.visible_posts(:_type => "Album", :person_id => @person.id) @aspect = :photos end def create - album = current_user.find_visible_post_by_id( params[:photo][:album_id] ) begin params[:photo][:user_file] = file_handler(params) @@ -31,34 +30,32 @@ class PhotosController < ApplicationController if @photo.save raise 'MongoMapper failed to catch a failed save' unless @photo.id - current_user.dispatch_post(@photo, :to => params[:photo][:to]) respond_to do |format| format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} end else - respond_with :location => album, :error => message + respond_with :location => photos_path, :error => message end rescue TypeError message = I18n.t 'photos.create.type_error' - respond_with :location => album, :error => message + respond_with :location => photos_path, :error => message rescue CarrierWave::IntegrityError message = I18n.t 'photos.create.integrity_error' - respond_with :location => album, :error => message + respond_with :location => photos_path, :error => message rescue RuntimeError => e message = I18n.t 'photos.create.runtime_error' - respond_with :location => album, :error => message + respond_with :location => photos_path, :error => message raise e end end def new @photo = Photo.new - @album = current_user.album_by_id(params[:album_id]) - render :partial => 'new_photo' + respond_with @photo end def destroy @@ -67,12 +64,9 @@ class PhotosController < ApplicationController if photo photo.destroy flash[:notice] = I18n.t 'photos.destroy.notice' - - redirect = photo.album end - redirect ||= photos_path - respond_with :location => redirect + respond_with :location => photos_path end def show @@ -80,17 +74,15 @@ class PhotosController < ApplicationController unless @photo render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else - @album = @photo.album @ownership = current_user.owns? @photo - respond_with @photo, @album + respond_with @photo end end def edit - @photo = current_user.my_posts.where(:_id => params[:id]).first - if @photo - @album = @photo.album + if @photo = current_user.my_posts.where(:_id => params[:id]).first + respond_with @photo else redirect_to photos_path end diff --git a/app/helpers/albums_helper.rb b/app/helpers/albums_helper.rb deleted file mode 100644 index a5e47b440f..0000000000 --- a/app/helpers/albums_helper.rb +++ /dev/null @@ -1,21 +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. - -module AlbumsHelper - def friends_albums_link - if params[:friends] - I18n.t('albums.helper.friends_albums') - else - link_to I18n.t('albums.helper.friends_albums'), albums_path({:friends => true}) - end - end - - def your_albums_link - if params[:friends] - link_to I18n.t('albums.helper.your_albums'), albums_path - else - I18n.t('albums.helper.your_albums') - end - end -end diff --git a/app/helpers/photos_helper.rb b/app/helpers/photos_helper.rb deleted file mode 100644 index ede57d43e7..0000000000 --- a/app/helpers/photos_helper.rb +++ /dev/null @@ -1,17 +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. - -module PhotosHelper - def linked_scaled_photo(photo, album) - link_to (image_tag photo.url(:scaled_full)), photo_path(album.next_photo(photo)), :rel => "prefetch" - end - - def url_to_prev(photo, album) - photo_path(album.prev_photo(photo)) - end - - def url_to_next(photo, album) - photo_path(album.next_photo(photo)) - end -end diff --git a/app/models/album.rb b/app/models/album.rb deleted file mode 100644 index 9be93701ca..0000000000 --- a/app/models/album.rb +++ /dev/null @@ -1,44 +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 Album < Post - - xml_reader :name - - key :name, String - - many :photos, :class_name => 'Photo', :foreign_key => :album_id - - timestamps! - - validates_presence_of :name, :person - - before_destroy :destroy_photos - - attr_accessible :name - - def self.mine_or_friends(friend_param, current_user) - friend_param ? Album.find_all_by_person_id(current_user.friend_ids) : current_user.person.albums - end - - def prev_photo(photo) - n_photo = self.photos.where(:created_at.lt => photo.created_at).sort(:created_at.desc).first - n_photo ? n_photo : self.photos.sort(:created_at.desc).first - end - - def next_photo(photo) - p_photo = self.photos.where(:created_at.gt => photo.created_at).sort(:created_at.asc).first - p_photo ? p_photo : self.photos.sort(:created_at.desc).last - end - - def mutable? - true - end - - protected - def destroy_photos - self.photos.each{|p| p.destroy} - end - -end diff --git a/app/models/comment.rb b/app/models/comment.rb index e6686efcec..40d3844e2c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -11,6 +11,7 @@ class HandleValidator < ActiveModel::Validator end class Comment + require File.join(Rails.root, 'lib/diaspora/websocket') include MongoMapper::Document include ROXML include Diaspora::Webhooks diff --git a/app/models/person.rb b/app/models/person.rb index 8d604eb20e..70a961f0ee 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -30,7 +30,6 @@ class Person diaspora_handle.downcase! end - many :albums, :class_name => 'Album', :foreign_key => :person_id belongs_to :owner, :class_name => 'User' timestamps! diff --git a/app/models/photo.rb b/app/models/photo.rb index 1eb0aa10e6..927b3db57c 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -2,13 +2,6 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -class PhotoAlbumValidator < ActiveModel::Validator - def validate(document) - unless document.album.nil? || document.album.person_id == document.person_id - document.errors[:base] << "You post photos to that album" - end - end -end class Photo < Post require 'carrierwave/orm/mongomapper' include MongoMapper::Document @@ -16,19 +9,13 @@ class Photo < Post xml_accessor :remote_photo xml_accessor :caption - xml_reader :album_id - key :album_id, ObjectId key :caption, String key :remote_photo_path key :remote_photo_name - belongs_to :album, :class_name => 'Album' - timestamps! - validates_with PhotoAlbumValidator - attr_accessible :caption before_destroy :ensure_user_picture @@ -37,7 +24,6 @@ class Photo < Post photo = super(params) image_file = params.delete(:user_file) - photo.album_id = params[:album_id] photo.image.store! image_file photo end @@ -69,7 +55,7 @@ class Photo < Post end def thumb_hash - {:thumb_url => url(:thumb_medium), :id => id, :album_id => album_id} + {:thumb_url => url(:thumb_medium), :id => id, :album_id => nil} end def mutable? diff --git a/app/models/user.rb b/app/models/user.rb index d0acdfe129..49d84a4ed7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,12 +157,7 @@ class User end def dispatch_post(post, opts = {}) - if post.is_a?(Photo) && post.album_id - aspect_ids = aspects_with_post(post.album_id) - aspect_ids.map! { |aspect| aspect.id } - else - aspect_ids = opts.delete(:to) - end + aspect_ids = opts.delete(:to) aspect_ids = validate_aspect_permissions(aspect_ids) self.raw_visible_posts << post diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml deleted file mode 100644 index 43ae3a7088..0000000000 --- a/app/views/albums/_album.html.haml +++ /dev/null @@ -1,18 +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. - -.album{:id => post.id, :class => ("mine" if current_user.owns?(post))} - %div.name - = link_to post.name, album_path(post) - - %div.time - by - = link_to ((current_user.person == post.person)? t('.you') : post.person.real_name), person_path(post.person) - %br - = link_to(how_long_ago(post), album_path(post)) - - %div.image_cycle - - for photo in post.photos[0..3] - = link_to (image_tag photo.url(:thumb_large)), album_path(post) - diff --git a/app/views/albums/_new_album.haml b/app/views/albums/_new_album.haml deleted file mode 100644 index e8cd3e7783..0000000000 --- a/app/views/albums/_new_album.haml +++ /dev/null @@ -1,12 +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. - - -= form_for Album.new do |album| - = album.error_messages - %p - = album.label :name - = album.hidden_field :to, :value => aspect - = album.text_field :name - = album.submit t('.create'), :class => 'button' diff --git a/app/views/albums/edit.html.haml b/app/views/albums/edit.html.haml deleted file mode 100644 index 81da980e02..0000000000 --- a/app/views/albums/edit.html.haml +++ /dev/null @@ -1,25 +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= "#{t('.editing')} #{@album.name}" - -- form_for @album do |album| - = album.error_messages - - %h4 - = t('.album_name') - = album.text_field :name - - - for photo in @album.photos - .photo_edit_block= image_tag photo.url(:thumb_medium) - - .submit_block - = link_to t('cancel'), root_path - or - = album.submit t('.update_album') - -.button.delete - = link_to t('.delete_album'), @album, :confirm => t('are_you_sure'), :method => :delete - diff --git a/app/views/albums/index.html.haml b/app/views/albums/index.html.haml deleted file mode 100644 index f46d3b8c76..0000000000 --- a/app/views/albums/index.html.haml +++ /dev/null @@ -1,14 +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. - -.span-24.last - = render "shared/publisher", :type => :album, :aspect => @aspect - - %div - - for album in @albums - = render "album", :post => album - - #pagination - = will_paginate @albums - diff --git a/app/views/albums/show.html.haml b/app/views/albums/show.html.haml deleted file mode 100644 index 267b43bc13..0000000000 --- a/app/views/albums/show.html.haml +++ /dev/null @@ -1,46 +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. - -:javascript - $(document).ready(function(){ - $(".image_thumb img").load( function() { - $(this).fadeIn("slow"); - }); - }); - - -- if @album != :uploads - = render 'shared/author_info', :person => @person, :post => @album -- else - = render 'shared/author_info', :person => @person - -%ul#breadcrumb - %li= link_to "#{@person.profile.first_name}'s Photos", person_photos_path(@person) - %li= @album_name - - -.span-19.appends-1.last - #thumbnails - - for photo in @album_photos - .image_thumb - = link_to (image_tag photo.url(:thumb_medium)), object_path(photo) - -.span-5.last - %h2 - = @album_name - - - if @album != :uploads - ="#{t('.updated')} #{how_long_ago(@album)}" - - -if current_user.person.id == @person.id - = render 'photos/new_photo', :album_id => @album_id, :aspect_id => "all" - - - if @album != :uploads - = link_to t('.edit_album'), edit_album_path(@album_id), :class => 'button' - - .album_id{:id => @album_id, :style => "display:hidden;"} - - -unless current_user.person.id == @person.id - %h4= "#{t('by')} #{@person.real_name}" - diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index af5e399d21..4e696b29a9 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -7,11 +7,11 @@ .span-15.last = render 'aspects/no_friends_message' - = render 'shared/publisher', :type => :status_message, :aspect => @aspect + = render 'shared/publisher', :aspect => @aspect = render 'aspects/no_posts_message' %ul#stream - for post in @posts - = render type_partial(post), :post => post unless post.class == Album + = render type_partial(post), :post => post #pagination = will_paginate @posts diff --git a/app/views/aspects/show.html.haml b/app/views/aspects/show.html.haml index af5e399d21..4e696b29a9 100644 --- a/app/views/aspects/show.html.haml +++ b/app/views/aspects/show.html.haml @@ -7,11 +7,11 @@ .span-15.last = render 'aspects/no_friends_message' - = render 'shared/publisher', :type => :status_message, :aspect => @aspect + = render 'shared/publisher', :aspect => @aspect = render 'aspects/no_posts_message' %ul#stream - for post in @posts - = render type_partial(post), :post => post unless post.class == Album + = render type_partial(post), :post => post #pagination = will_paginate @posts diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 7d068a14f3..84b9d59146 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -46,7 +46,7 @@ - if @posts.count > 0 %ul#stream - for post in @posts - = render type_partial(post), :post => post unless post.class == Album + = render type_partial(post), :post => post = will_paginate @posts - else %h3= t('.no_posts') diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index dd029008e8..7a10a25301 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -6,7 +6,7 @@ function createUploader(){ var uploader = new qq.FileUploader({ element: document.getElementById('file-upload'), - params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, + params: {'photo' : { 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], action: "#{photos_path}" }); diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index a122614aa3..d3d676f86a 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -22,11 +22,7 @@ .right = link_to t('delete'), photo_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" - - if !post.album_id.nil? - =t('.posted_a_new_photo_to') - = link_to post.album.name, object_path(post.album) - - else - posted a photo + posted a photo %br %br diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml index dcdebab1cf..dd8ed7d6b2 100644 --- a/app/views/photos/edit.html.haml +++ b/app/views/photos/edit.html.haml @@ -6,18 +6,10 @@ %div{:id => @photo.id} #show_photo - = linked_scaled_photo @photo, @album + = image_tag @photo.url(:scaled_full) = form_for @photo do |photo| = photo.label :caption = photo.text_field :caption, :value => @photo.caption = photo.submit - %div{:class => 'clear'} - - #content_bottom - .back - = link_to "⇧ #{@album.name}", album_path(@album) - -if current_user.owns? @album - .button.right - = link_to t('.delete_photo'), @photo, :confirm => t('are_you_sure'), :method => :delete diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml index 23ff5a7db9..dc9fb9a9ac 100644 --- a/app/views/photos/index.html.haml +++ b/app/views/photos/index.html.haml @@ -21,19 +21,7 @@ .image_thumb = link_to (image_tag photo.url(:thumb_medium)), photo_path(photo) -.span-24.last - %h3 - Photos - %div - - for album in @albums - = render "albums/album", :post => album - = link_to "uploads", album_path("uploads") - -.span-24.last - %h3 - Albums - .span-24.last #add_photo_pane - = render "photos/new_photo", :album_id => nil, :aspect_id => :all + = render "photos/new_photo", :aspect_id => :all diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 49590e653a..bd068731fc 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -10,18 +10,15 @@ %ul#breadcrumb %li= link_to "#{@photo.person.profile.first_name}'s Photos", person_photos_path(@photo.person) - - if !@photo.album_id.nil? - %li= link_to @album.name, album_path(@album) - - else - %li= link_to "uploads", album_path("uploads") %li= @photo.caption -- if @photo.album - = link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo" - | - = link_to "#{t('.full_size')}", @photo.url - | - = link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo" +/ we need to do next photo here +/- if @photo.album +/= link_to "<< #{t('.prev')}", url_to_prev(@photo, @album), :rel => 'prefetch', :id => "prev_photo" +/| +/= link_to "#{t('.full_size')}", @photo.url +/| +/= link_to "#{t('.next')} >>", url_to_next(@photo, @album), :rel => 'prefetch', :id => "next_photo" .span-14.append-1.last %div{:data=>{:guid=>@photo.id}} @@ -31,9 +28,10 @@ .edit_pane .controls{:data=>{:actor=>"#{@photo.person.owner.id}",:actor_person=>"#{@photo.person.id}",:image_url=>"#{@photo.url(:thumb_medium)}"}} = link_to 'make profile photo', '#', :class => "make_profile_photo" - = linked_scaled_photo @photo, @album + = image_tag @photo.url(:scaled_full) + -else - = linked_scaled_photo @photo, @album + = image_tag @photo.url(:scaled_full) .caption -if @ownership diff --git a/app/views/shared/_publisher.haml b/app/views/shared/_publisher.haml index c2ced4804c..ce25bc65c6 100644 --- a/app/views/shared/_publisher.haml +++ b/app/views/shared/_publisher.haml @@ -22,46 +22,31 @@ #publisher = owner_image_link - - if( !defined?(type) || type == :status_message ) - = form_for StatusMessage.new, :remote => true do |status| - = status.error_messages - %p - = status.label :message, t('.post_a_message_to', :aspect => aspect) - = status.text_area :message, :rows => 2, :value => params[:prefill] - - = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) - - .options_and_submit - - if aspect == :all - = status.submit t('.share'), :title => "Share with all aspects" - - else - = status.submit t('.share'), :title => "Share with #{aspect}" - - - if aspect == :all - .public_toggle - = status.check_box( :public, {}, true, false ) - = t('.make_public') - = link_to '(?)', "#question_mark_pane", :class => 'question_mark' - - .fancybox_content - #question_mark_pane - = render 'shared/public_explain' - - - #publisher_photo_upload - = t('or') - = render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id), :album_id => nil - - - - else - = form_for Album.new do |album| - = album.error_messages - %p - = album.label :name - = album.text_field :name - - = album.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) - - .options_and_submit - = album.submit "Create", :class => 'button' - + = form_for StatusMessage.new, :remote => true do |status| + = status.error_messages + %p + = status.label :message, t('.post_a_message_to', :aspect => aspect) + = status.text_area :message, :rows => 2, :value => params[:prefill] + + = status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id) + + .options_and_submit + - if aspect == :all + = status.submit t('.share'), :title => "Share with all aspects" + - else + = status.submit t('.share'), :title => "Share with #{aspect}" + + - if aspect == :all + .public_toggle + = status.check_box( :public, {}, true, false ) + = t('.make_public') + = link_to '(?)', "#question_mark_pane", :class => 'question_mark' + + .fancybox_content + #question_mark_pane + = render 'shared/public_explain' + + + #publisher_photo_upload + = t('or') + = render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 582cc170a9..9f41d2fe52 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -81,35 +81,6 @@ en: reshare: 'Reshare' author_info: view_profile: 'View profile' - albums: - album: - you: "you" - new_album: - create: "create" - add_a_new_album: "Add a new album" - show: - edit_album: "Edit Album" - albums: "albums" - updated: "updated" - edit: - album_name: "Album name" - editing: "Editing" - updated: "updated" - update_album: "Update album" - delete_album: "Delete Album" - index: - new_album: "New Album" - create: - success: "You've created an album called %{name}." - failure: "Failed to create album." - update: - success: "Album %{name} successfully edited." - failure: "Failed to edit album %{name}." - destroy: - success: "Album %{name} deleted." - helper: - friends_albums: "Friends Albums" - your_albums: "Your Albums" aspects: no_friends_message: nobody: "We know you have friends — bring them to Diaspora!" @@ -159,7 +130,6 @@ en: getting_started: signup_steps: "Complete your sign-up by doing these things:" 'step_1': - albums: "Albums" you_dont_have_any_photos: "You don't have any photos! Go to the" page_to_upload_some: "page to upload some." comments: @@ -268,7 +238,6 @@ en: 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." requests: diff --git a/config/routes.rb b/config/routes.rb index 3bd37a0181..05461014a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,6 @@ Diaspora::Application.routes.draw do resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] resources :photos - resources :albums resources :services match '/auth/:provider/callback' => 'services#create' diff --git a/lib/collect_user_photos.rb b/lib/collect_user_photos.rb index d95aa386a5..50799f3764 100644 --- a/lib/collect_user_photos.rb +++ b/lib/collect_user_photos.rb @@ -7,18 +7,16 @@ module PhotoMover FileUtils::mkdir_p temp_dir Dir.chdir 'tmp/exports' - albums = user.visible_posts(:person_id => user.person.id, :_type => 'Album') + photos = user.visible_posts(:person_id => user.person.id, :_type => 'Photo') - albums.each do |album| - album_dir = "#{user.id}/#{album.name}" - FileUtils::mkdir_p album_dir + photos_dir = "#{user.id}/photos" + FileUtils::mkdir_p photos_dir - album.photos.each do |photo| - current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.image_filename}" - new_photo_location = "#{album_dir}/#{photo.image_filename}" + photos.each do |photo| + current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.image_filename}" + new_photo_location = "#{photos_dir}/#{photo.image_filename}" - FileUtils::cp current_photo_location new_photo_location - end + FileUtils::cp current_photo_location new_photo_location end system("tar", "cf #{user.id}.tar #{user.id}") diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 3121c491af..35c2057d80 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -69,7 +69,6 @@ module Diaspora self.aspects.find_all_by_post_ids( id.to_id ) end - def aspects_with_person person contact_for(person).aspects end @@ -84,9 +83,6 @@ module Diaspora self.aspects.all.collect{|x| x.id} end - def albums_by_aspect aspect - aspect == :all ? raw_visible_posts.find_all_by__type("Album") : aspect.posts.find_all_by__type("Album") - end end end end diff --git a/spec/controllers/albums_controller_spec.rb b/spec/controllers/albums_controller_spec.rb deleted file mode 100644 index 78a4b42906..0000000000 --- a/spec/controllers/albums_controller_spec.rb +++ /dev/null @@ -1,54 +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. - -require 'spec_helper' - -describe AlbumsController do - render_views - before do - @user = make_user - @aspect = @user.aspects.create(:name => "lame-os") - @album = @user.post :album, :to => @aspect.id, :name => 'things on fire' - sign_in :user, @user - end - - describe '#create' do - it 'all aspects' do - params = {"album" => {"name" => "Sunsets","to" => "all"}} - post :create, params - end - it 'one aspect' do - params = {"album" => {"name" => "Sunsets","to" => @aspect.id.to_s}} - post :create, params - end - - context 'with invalid params' do - it 'should render a flash error message when album name is blank' do - params = {"album" => {"name" => "", "to" => "all"}} - post :create, params - flash[:error].should == "Failed to create album." - end - it 'should redirect back to album page for that given aspect' do - params = {"album" => {"name" => "", "to" => "all"}} - post :create, params - response.should redirect_to albums_path(:aspect => "all") - end - end - end - - describe "#update" do - it "should update the name of an album" do - put :update, :id => @album.id, :album => { :name => "new_name"} - @album.reload.name.should eql("new_name") - end - - it "doesn't overwrite random attributes" do - new_user = make_user - params = {:name => "Bruisers", :person_id => new_user.person.id} - put('update', :id => @album.id, "album" => params) - @album.reload.person_id.should == @user.person.id - @album.name.should == 'Bruisers' - end - end -end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 8bde057e53..fc3ce5fd07 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -11,41 +11,26 @@ describe PhotosController do let!(:aspect) {user.aspects.create(:name => 'winners')} let(:aspect2) {user2.aspects.create(:name => 'winners')} - let!(:album) {user.post(:album, :to => aspect.id, :name => "room on fire")} - let!(:album2) {user2.post(:album, :to => aspect2.id, :name => "room on fire")} let(:filename) {'button.png'} let(:fixture_name) {File.join(File.dirname(__FILE__), '..', 'fixtures', filename)} let(:image) {File.open(fixture_name)} - let!(:photo){ user.post(:photo, :album_id => album.id, :user_file => image, :to => aspect.id)} - let(:photo_no_album){ user.post(:photo, :user_file => image, :to => aspect.id)} - let!(:photo2){ user2.post(:photo, :album_id => album2.id, :user_file => image, :to => aspect2.id)} + let!(:photo){ user.post(:photo, :user_file => image, :to => aspect.id)} + let!(:photo2){ user2.post(:photo, :user_file => image, :to => aspect2.id)} before do friend_users(user, aspect, user2, aspect2) sign_in :user, user - user.reload - aspect.reload - aspect2.reload @controller.stub!(:current_user).and_return(user) end describe '#create' do - let(:foo) {{:album_id => album.id.to_s}} - before do @controller.stub!(:file_handler).and_return(image) end - it 'can make a photo in an album' do - pending - proc{ post :create, :photo => foo, :qqfile => fixture_name }.should change(Photo, :count).by(1) - end - it 'can make a picture without an album' do - pending - end - - it 'does not let you create a photo in an album you do not own' do + it 'can make a photo' do pending + proc{ post :create, :qqfile => fixture_name }.should change(Photo, :count).by(1) end end @@ -54,7 +39,6 @@ describe PhotosController do get :index assigns[:person].should == user.person assigns[:photos].should == [photo] - assigns[:albums].should == [album] end it 'sets the person to a friend if person_id is set' do @@ -62,7 +46,6 @@ describe PhotosController do assigns[:person].should == user2.person assigns[:photos].should == [] - assigns[:albums].should == [] end it 'sets the aspect to photos?' do @@ -77,23 +60,17 @@ describe PhotosController do get :show, :id => photo.id assigns[:photo].should == photo - assigns[:album].should == album assigns[:ownership].should == true end end describe '#edit' do - it 'should let you edit a photo with an album' do + it 'should let you edit a photo' do get :edit, :id => photo.id response.code.should == "200" end - it 'should let you edit a photo you own that does not have an album' do - get :edit, :id => photo_no_album.id - response.code.should == "200" - end - it 'should not let you edit a photo that is not yours' do get :edit, :id => photo2.id response.should redirect_to(:action => :index) diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index 011f294539..c8ed0fa690 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -30,9 +30,8 @@ describe SocketsController do end it 'should actionhash photos' do - @album = @user.post(:album, :name => "Loser faces", :to => @aspect.id) - photo = @user.post(:photo, :album_id => @album.id, :user_file => File.open(@fixture_name)) - json = @controller.action_hash(@user.id, photo, :aspect_ids => @user.aspects_with_post(@album.id).map{|g| g.id}) + photo = @user.post(:photo, :album_id => nil, :to => @aspect.id, :user_file => File.open(@fixture_name)) + json = @controller.action_hash(@user.id, photo, :aspect_ids => :all) json.include?('photo').should be_true end diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index 97b7a3e483..6c860d3967 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -85,6 +85,12 @@ module HelperMethods UserFixer.fixed_user end + def uploaded_photo + fixture_filename = 'button.png' + fixture_name = File.join(File.dirname(__FILE__), 'fixtures', fixture_filename) + File.open(fixture_name) + end + class UserFixer def self.regenerate_user_fixtures users = {:users => build_user_fixtures} diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb deleted file mode 100644 index 540d498298..0000000000 --- a/spec/models/album_spec.rb +++ /dev/null @@ -1,83 +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. - -require 'spec_helper' - -describe Album do - let(:user) { make_user } - let(:person) { user.person } - let(:aspect) { user.aspects.create(:name => "Foo") } - let(:album) { user.post(:album, :name => "test collection", :to => aspect.id) } - - it 'is valid' do - album.should be_valid - end - - it 'validates presence of a name' do - album.name = nil - album.should_not be_valid - end - - it 'has many photos' do - album.associations[:photos].type.should == :many - end - - it 'should be mutable' do - post = user.post :album, :name => "hello", :to => aspect.id - post.mutable?.should == true - end - - it 'has a diaspora_handle' do - album.diaspora_handle.should == user.diaspora_handle - end - - context 'when an album has two attached images' do - before do - 2.times do - photo = Factory.build(:photo, :person => person, :album => album) - album.photos << photo - end - end - - context 'when the album is deleted' do - it 'removes all child photos' do - expect{ album.destroy }.to change(Photo, :count).from(2).to(0) - end - end - end - - context 'traversing photos' do - let(:attrs) { {:person => person, :album => album} } - let!(:photo_1) { Factory(:photo, attrs.merge(:created_at => 2.days.ago)) } - let!(:photo_2) { Factory(:photo, attrs.merge(:created_at => 1.day.ago)) } - let!(:photo_3) { Factory(:photo, attrs.merge(:created_at => Time.now)) } - - describe '#next_photo' do - it 'returns the next photo' do - album.next_photo(photo_1).id.should == photo_2.id - end - - it 'returns the first photo when given the last photo in the album' do - album.next_photo(photo_3).id.should == photo_1.id - end - end - - describe '#prev_photo' do - it 'returns the previous photo' do - album.prev_photo(photo_2).id.should == photo_1.id - end - - it 'returns the last photo when given the first photo in the album' do - album.prev_photo(photo_1).id.should == photo_3.id - end - end - end - - describe 'serialization' do - it 'has a diaspora_handle' do - album.to_diaspora_xml.include?(user.diaspora_handle).should be_true - end - end - -end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 0e2513e1dc..fd7994494b 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -8,13 +8,12 @@ describe Photo do before do @user = make_user @aspect = @user.aspects.create(:name => "losers") - @album = @user.post :album, :name => "foo", :to => @aspect.id @fixture_filename = 'button.png' @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename) @fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml') - @photo = Photo.new(:album => @album) + @photo = Photo.new @photo.person = @user.person @photo.diaspora_handle = @user.person.diaspora_handle @@ -45,10 +44,9 @@ describe Photo do it 'has a constructor' do image = File.open(@fixture_name) photo = Photo.instantiate( - :person => @user.person, :album => @album, :user_file => image) - photo.created_at.nil?.should be true - photo.image.read.nil?.should be false - photo.album.should == @album + :person => @user.person, :user_file => image) + photo.created_at.nil?.should be_true + photo.image.read.nil?.should be_false end end @@ -112,9 +110,6 @@ describe Photo do it 'serializes the url' do @xml.include?(@photo.image.url).should be true end - it 'serializes the album_id' do - @xml.include?(@photo.album_id.to_s).should be true - end it 'serializes the diaspora_handle' do @xml.include?(@user.diaspora_handle).should be true end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/models/user/attack_vectors_spec.rb index 9f9b74f6bd..8287da54e7 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/models/user/attack_vectors_spec.rb @@ -148,16 +148,16 @@ describe "attack vectors" do end it 'does not let me update other persons post' do - original_message = user2.post :album, :name => 'store this!', :to => aspect2.id + pending "this needs to be a photo" + original_message = user2.post(:photo, :user_file => uploaded_photo, :caption => "store this!", :to => aspect2.id) user.receive_salmon(user2.salmon(original_message).xml_for(user.person)) original_message.diaspora_handle = user3.diaspora_handle - original_message.name = "bad bad bad" + original_message.caption = "bad bad bad" xml = user3.salmon(original_message).xml_for(user.person) user.receive_salmon(xml) - original_message.reload.name.should == "store this!" - + original_message.reload.caption.should == "store this!" end end end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 94244efd9a..242eeab6ee 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -42,10 +42,11 @@ describe User do post.persisted?.should be_false end - it 'does not save an album' do - post = user.build_post(:album, :name => "hey", :to => aspect.id) + it 'does not save a photo' do + post = user.build_post(:photo, :user_file => uploaded_photo, :to => aspect.id) post.persisted?.should be_false end + end describe '#dispatch_post' do @@ -55,15 +56,6 @@ describe User do aspect.posts.should include post end - - - - it 'should put an album in the aspect post array' do - album = user.post :album, :name => "Georges", :to => aspect.id - 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 @@ -95,10 +87,11 @@ describe User do describe '#update_post' do it 'should update fields' do - album = user.post(:album, :name => "Profile Photos", :to => aspect.id) - update_hash = {:name => "Other Photos"} - user.update_post(album, update_hash) - album.name.should == "Other Photos" + photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Old caption", :to => aspect.id) + update_hash = {:caption => "New caption"} + user.update_post(photo, update_hash) + + photo.caption.should match(/New/) end end diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index e9ed004489..0f3cb0dcd7 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -14,7 +14,6 @@ describe User do let(:person_three) { Factory.create :person } - context 'with two posts' do let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id } let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id } @@ -174,23 +173,4 @@ describe User do end end - describe '#albums_by_aspect' do - let!(:first_aspect) {user2.aspects.create(:name => 'bruisers')} - let!(:second_aspect) {user2.aspects.create(:name => 'losers')} - before do - user2.post :album, :name => "Georges", :to => first_aspect.id - user2.post :album, :name => "Borges", :to => first_aspect.id - user2.post :album, :name => "Luises", :to => second_aspect.id - user2.reload - end - - it 'should find all albums if passed :all' do - user2.albums_by_aspect(:all).should have(3).albums - end - - it 'should return the right number of albums' do - user2.albums_by_aspect(first_aspect.reload).should have(2).albums - user2.albums_by_aspect(second_aspect.reload).should have(1).album - end - end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index e17b182b0f..c4e4792277 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -15,7 +15,8 @@ describe User do let(:user3) { make_user } let(:aspect3) { user3.aspects.create(:name => 'heroes') } let(:status) {user.post(:status_message, :message => "Original", :to => aspect.id)} - let(:album) {user.post(:album, :name => "Original", :to => aspect.id)} + + let(:photo) {user.post(:photo, :user_file => uploaded_photo, :caption => "Original", :to => aspect.id)} before do friend_users(user, aspect, user2, aspect2) @@ -74,15 +75,15 @@ describe User do end it 'updates posts marked as mutable' do - user2.receive_salmon(user.salmon(album).xml_for(user2.person)) - album.name = 'foo' - xml = user.salmon(album).xml_for(user2.person) + user2.receive_salmon(user.salmon(photo).xml_for(user2.person)) + photo.caption = 'foo' + xml = user.salmon(photo).xml_for(user2.person) - album.reload.name.should == 'Original' + photo.reload.caption.should match(/Original/) user2.receive_salmon(xml) - album.reload.name.should == 'foo' + photo.reload.caption.should match(/foo/) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3af16945b2..020fa1fa91 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -246,11 +246,11 @@ describe User do end describe '#update_post' do - it 'sends a notification to aspects' do user.should_receive(:push_to_aspects).twice - album = user.post(:album, :name => "cat", :to => aspect.id) - user.update_post(album, :name => 'bat') + photo = user.post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => aspect.id) + + user.update_post(photo, :caption => 'hellp') end end -- GitLab