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 8e2c75d59..c2e6e3300 100644 --- a/Gemfile +++ b/Gemfile @@ -3,31 +3,43 @@ source 'http://gemcutter.org' gem 'rails', '3.0.0.beta4' gem 'bundler', '0.9.26' -gem 'mongo_mapper', :git => "http://github.com/BadMinus/mongomapper.git" -gem 'devise', :git => "http://github.com/BadMinus/devise.git" -gem 'jnunemaker-validatable', :git => "http://github.com/BadMinus/validatable.git" + +gem 'thin' + +#Security +gem 'gpgme' +gem 'devise', :git => 'http://github.com/BadMinus/devise.git' + +#Mongo +gem 'mongo_mapper', :git => 'http://github.com/BadMinus/mongomapper.git' +gem 'jnunemaker-validatable', :git => 'http://github.com/BadMinus/validatable.git' gem 'mongo_ext' gem 'bson_ext' -gem "haml" -gem 'roxml', :git => "git://github.com/Empact/roxml.git" +#Views +gem 'haml' +gem 'will_paginate', '3.0.pre' -gem 'gpgme' +gem 'roxml', :git => 'git://github.com/Empact/roxml.git' + +#Standards gem 'pubsubhubbub' -#mai crazy async stuff -#gem 'em-synchrony', :git => 'git://github.com/igrigorik/em-synchrony.git', :require => 'em-synchrony/em-http' + gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http' -#gem 'rack-fiber_pool', :require => 'rack/fiber_pool' -gem 'addressable', :require => "addressable/uri" +gem 'addressable', :require => 'addressable/uri' gem 'em-websocket' gem 'thin' gem 'will_paginate', '3.0.pre' gem 'redfinger' +#File uploading +gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch +gem 'mini_magick' + group :test do gem 'rspec', '>= 2.0.0.beta.17' gem 'rspec-rails', '2.0.0.beta.17' - gem "mocha" + gem 'mocha' gem 'webrat' gem 'redgreen' gem 'autotest' @@ -36,10 +48,10 @@ group :test do end group :development do - gem "nifty-generators" - gem "ruby-debug" + gem 'nifty-generators' + gem 'ruby-debug' end group :deployment do - gem 'sprinkle', :git => "git://github.com/rsofaer/sprinkle.git" + gem 'sprinkle', :git => 'git://github.com/rsofaer/sprinkle.git' end 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 new file mode 100644 index 000000000..11b7fb404 --- /dev/null +++ b/app/controllers/photos_controller.rb @@ -0,0 +1,33 @@ +class PhotosController < ApplicationController + #before_filter :authenticate_user! + + def index + @photos = Photo.paginate :page => params[:page], :order => 'created_at DESC' + end + + def create + @photo = Photo.new(params[:photo]) + + if @photo.save + flash[:notice] = "Successfully uploaded photo." + redirect_to photos_url + else + render :action => 'new' + end + end + + def new + @photo = Photo.new + end + + def destroy + @photo = Photo.where(:id => params[:id]).first + @photo.destroy + flash[:notice] = "Successfully deleted photo." + redirect_to root_url + end + + 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/photo.rb b/app/models/photo.rb new file mode 100644 index 000000000..3e8407a81 --- /dev/null +++ b/app/models/photo.rb @@ -0,0 +1,6 @@ +class Photo + require 'carrierwave/orm/mongomapper' + include MongoMapper::Document + + mount_uploader :image, ImageUploader +end diff --git a/app/models/user.rb b/app/models/user.rb index beb4f1f6c..4c22fcabd 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 new file mode 100644 index 000000000..eb6b9a8b4 --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,17 @@ +class ImageUploader < CarrierWave::Uploader::Base + include CarrierWave::MiniMagick + + storage :grid_fs + + def store_dir + "files/#{model.id}" + end + + def extension_white_list + %w(jpg jpeg gif png) + end + + version :small_thumb do + process :resize_to_fill => [100,100] + end +end 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..945679d5b --- /dev/null +++ b/app/views/photos/_new_photo.haml @@ -0,0 +1,5 @@ += form_for Photo.new, :html => {:multipart => 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..e7da24728 --- /dev/null +++ b/app/views/users/edit.html.haml @@ -0,0 +1,25 @@ +%h3 Editing 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/app/views/users/show.html.haml b/app/views/users/show.html.haml index f922e19b8..dbf775230 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -1,5 +1,5 @@ %h1 user page! -.span-18.last +.span-20.last %h1= "#{@user.real_name}" - if @user_profile %p diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb new file mode 100644 index 000000000..271f2334e --- /dev/null +++ b/config/initializers/carrierwave.rb @@ -0,0 +1,6 @@ +CarrierWave.configure do |config| + config.grid_fs_database = "#diaspora-#{Rails.env}" + config.grid_fs_host = 'localhost' + config.grid_fs_access_url = "/images" + config.storage = :grid_fs +end diff --git a/config/routes.rb b/config/routes.rb index e1ca70581..279d74984 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,10 +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/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb new file mode 100644 index 000000000..f9e91dad7 --- /dev/null +++ b/spec/controllers/request_controller_spec.rb @@ -0,0 +1,9 @@ +describe 'webfinger' do + redner_views + + describe "profile" do + it 'should fetch the public webfinger profile on request' do + post + end + end +end diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb new file mode 100644 index 000000000..ce21cdc6b --- /dev/null +++ b/spec/controllers/requests_controller_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe RequestsController do + redner_views + + describe "profile" do + it 'should fetch the public webfinger profile on request' do + post + end + end +end diff --git a/spec/fixtures/bp.jpeg b/spec/fixtures/bp.jpeg new file mode 100644 index 000000000..33f75aa04 Binary files /dev/null and b/spec/fixtures/bp.jpeg differ diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb new file mode 100644 index 000000000..9936f6c9b --- /dev/null +++ b/spec/models/photo_spec.rb @@ -0,0 +1,19 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Photo do + it 'should save a photo to GridFS' do + photo = Photo.new + 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 diff --git a/spec/models/webfinger_spec.rb b/spec/models/webfinger_spec.rb new file mode 100644 index 000000000..9969a5f38 --- /dev/null +++ b/spec/models/webfinger_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe 'webfinger' do + redner_views + describe "profile" do + it 'should fetch the public webfinger profile on request' do + + end + end +end