diff --git a/.gitignore b/.gitignore index 40116a515..721b1f830 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ Gemfile.lock gpg/diaspora-development/*.gpg gpg/diaspora-production/*.gpg gpg/*/random_seed +public/uploads/* diff --git a/Gemfile b/Gemfile index 6221af125..e3813ce4d 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'em-websocket' #File uploading gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch -gem 'image_science' +gem 'mini_magick' group :test do gem 'rspec', '>= 2.0.0.beta.17' diff --git a/README b/README index 1c7ced351..0c9462da2 100644 --- a/README +++ b/README @@ -1 +1 @@ -broner \ No newline at end of file +bronenate diff --git a/app/controllers/gridfs_controller.rb b/app/controllers/gridfs_controller.rb new file mode 100644 index 000000000..14ff8e0de --- /dev/null +++ b/app/controllers/gridfs_controller.rb @@ -0,0 +1,14 @@ +class GridfsController < ActionController::Metal + def serve + gridfs_path = env["PATH_INFO"].gsub("/images/", "") + begin + gridfs_file = Mongo::GridFileSystem.new(MongoMapper.database).open(gridfs_path, 'r') + self.response_body = gridfs_file.read + self.content_type = gridfs_file.content_type + rescue + self.status = :file_not_found + self.content_type = 'text/plain' + self.response_body = "File totally imaginary #{gridfs_path}" + end + end +end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 6239603ec..11b7fb404 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -3,12 +3,10 @@ class PhotosController < ApplicationController def index @photos = Photo.paginate :page => params[:page], :order => 'created_at DESC' - end def create @photo = Photo.new(params[:photo]) - @photo.person = current_user if @photo.save flash[:notice] = "Successfully uploaded photo." @@ -31,6 +29,5 @@ class PhotosController < ApplicationController def show @photo = Photo.where(:id => params[:id]).first - end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 99f155736..8d61f9c9a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,7 +5,22 @@ class UsersController < ApplicationController @users = User.sort(:created_at.desc).all end def show - @user= Person.where(:id => params[:id]).first + @user= Person.first(:id => params[:id]) @user_profile = @user.profile end + + def edit + @user = User.first(:id => params[:id]) + @profile = @user.profile + end + + def update + @user = User.where(:id => params[:id]).first + if @user.update_attributes(params[:user]) + flash[:notice] = "Successfully updated user." + redirect_to @user + else + render :action => 'edit' + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index edb80a5db..952fa67b3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < Person :recoverable, :rememberable, :trackable, :validatable - before_validation :assign_key + before_validation_on_create :assign_key validates_presence_of :profile before_validation :do_bad_things diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 05ba9614a..eb6b9a8b4 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -1,5 +1,5 @@ class ImageUploader < CarrierWave::Uploader::Base - include CarrierWave::ImageScience + include CarrierWave::MiniMagick storage :grid_fs diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c763ace6e..12380d796 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -44,6 +44,9 @@ .span-24.last .span-3.append-1.last = link_to owner_picture, root_path + = link_to "Edit your profile", edit_user_path(current_user) + %br + %br = render 'people/sidebar' if user_signed_in? .span-20.last diff --git a/app/views/people/_sidebar.html.haml b/app/views/people/_sidebar.html.haml index 070647a55..5c9d8fa37 100644 --- a/app/views/people/_sidebar.html.haml +++ b/app/views/people/_sidebar.html.haml @@ -1,4 +1,3 @@ -%h3 your people %ul#friend_stream.nav - for friend in @friends %li= link_to friend.real_name, person_path(friend) diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml new file mode 100644 index 000000000..ef74f51da --- /dev/null +++ b/app/views/photos/_new_photo.haml @@ -0,0 +1,5 @@ += form_for Photo.new, :remote => true do |f| + = f.error_messages + %p + = f.file_field :image + = f.submit 'post it!', :class => 'button' diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml new file mode 100644 index 000000000..998a497a7 --- /dev/null +++ b/app/views/photos/_photo.haml @@ -0,0 +1,3 @@ +%li.message{:id => post.id} + = link_to (image_tag post.image.url(:small_thumb)), photo_path(post) + diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml new file mode 100644 index 000000000..04abb3bd2 --- /dev/null +++ b/app/views/photos/index.html.haml @@ -0,0 +1,9 @@ +%h1.big_text photos += render "photos/new_photo", :photo => @photo +%ul#stream + + - for photo in @photos + = render "photo", :post => photo +#pagination + = will_paginate @photos + diff --git a/app/views/photos/new.html.haml b/app/views/photos/new.html.haml new file mode 100644 index 000000000..b8fe5d3b5 --- /dev/null +++ b/app/views/photos/new.html.haml @@ -0,0 +1,9 @@ +- title "New Photo" + += form_for( @photo, :html => {:multipart => true}) do |f| + = f.error_messages + %p + = f.file_field :image + = f.submit 'post it!', :class => 'button' + +%p= link_to "Back to List", photos_path diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml new file mode 100644 index 000000000..adcbce23b --- /dev/null +++ b/app/views/photos/show.html.haml @@ -0,0 +1,10 @@ +- title "Photo" + +%p + %strong Photo: + = image_tag @photo.image.url + +%p + = link_to "Destroy", @photo, :confirm => 'Are you sure?', :method => :delete + | + = link_to "View All", photos_path diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml new file mode 100644 index 000000000..031191010 --- /dev/null +++ b/app/views/users/edit.html.haml @@ -0,0 +1,25 @@ +- title "Edit Profile" + += form_for @user do |f| + = f.error_messages + + = f.fields_for :profile do |p| + %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 + + %p + = f.label :email + = f.text_field :email + + %p + = f.label :url + = f.text_field :url + %p + = f.submit + +%p + = link_to "Show", user_path(@user) diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 6c68ccdad..271f2334e 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,6 +1,6 @@ CarrierWave.configure do |config| config.grid_fs_database = "#diaspora-#{Rails.env}" config.grid_fs_host = 'localhost' - config.grid_fs_access_url = "/GridFS" + config.grid_fs_access_url = "/images" config.storage = :grid_fs end diff --git a/config/routes.rb b/config/routes.rb index b49c9afae..279d74984 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,11 +2,14 @@ Diaspora::Application.routes.draw do |map| resources :blogs resources :bookmarks resources :people + resources :users resources :status_messages resources :comments resources :requests resources :photos + match "/images/files/*path" => "gridfs#serve" + match 'warzombie', :to => "dashboards#warzombie" match 'zombiefriends', :to => "dashboards#zombiefriends" match 'zombiefriendaccept', :to => "dashboards#zombiefriendaccept" diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 48ad321c3..9936f6c9b 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -1,13 +1,19 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Photo do - it 'should upload a photo to GridFS' do - + it 'should save a photo to GridFS' do photo = Photo.new - file = File.open('/spec/fixtures/bp.jpeg') + fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' + file = File.open(fixture_name) photo.image = file photo.save.should == true + binary = photo.image.read + fixture_binary = File.open(fixture_name).read + binary.should == fixture_binary + end + it 'should create thumbnails' do + pending('need to figure this out... tearing issue') end end