Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
ilya 2010-08-31 10:48:29 -07:00
commit 12f7d16c0b
23 changed files with 292 additions and 305 deletions

View file

@ -1,20 +1,17 @@
class AlbumsController < ApplicationController class AlbumsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => [:index, :show]
def index def index
@albums = Album.mine_or_friends(params[:friends], current_user).paginate :page => params[:page], :order => 'created_at DESC' @albums = Album.mine_or_friends(params[:friends], current_user).paginate :page => params[:page], :order => 'created_at DESC'
respond_with @albums
end end
def create def create
@album = current_user.post(:album, params[:album]) @album = current_user.post(:album, params[:album])
respond_with @album
if @album.created_at
flash[:notice] = "Successfully created album."
redirect_to @album
else
flash[:error] = "Successfully failed."
redirect_to albums_path
end
end end
def new def new
@ -22,30 +19,26 @@ class AlbumsController < ApplicationController
end end
def destroy def destroy
@album = Album.first(:id => params[:id]) @album = Album.find_by_id params[:id]
@album.destroy @album.destroy
flash[:notice] = "Successfully destroyed album." respond_with :location => albums_url
redirect_to albums_url
end end
def show def show
@photo = Photo.new @photo = Photo.new
@album = Album.first(:id => params[:id]) @album = Album.find_by_id params[:id]
@album_photos = @album.photos @album_photos = @album.photos
respond_with @album
end end
def edit def edit
@album = Album.first(:id => params[:id]) @album = Album.find_by_id params[:id]
end end
def update def update
@album = Album.first(:id => params[:id]) @album = Album.find_params_by_id params[:id]
if @album.update_attributes(params[:album]) respond_with @album
flash[:notice] = "Successfully updated album."
redirect_to @album
else
render :action => 'edit'
end
end end
end end

View file

@ -1,15 +1,20 @@
class CommentsController < ApplicationController class CommentsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
def create def create
target = Post.first(:id => params[:comment][:post_id]) target = Post.find_by_id params[:comment][:post_id]
text = params[:comment][:text] text = params[:comment][:text]
if current_user.comment text, :on => target @comment = current_user.comment text, :on => target
render :text => "Woo!" respond_with @comment
else
render :text => "Boo!"
end
end end
end def show
@comment = Comment.find_by_id params[:id]
respond_with @comment
end
end

View file

@ -1,20 +1,17 @@
class GroupsController < ApplicationController class GroupsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
def index def index
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :order => 'created_at DESC' @posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :order => 'created_at DESC'
@group = :all @group = :all
end end
def create def create
@group = current_user.group(params[:group]) @group = current_user.group params[:group]
respond_with @group
if @group.created_at
flash[:notice] = "Successfully created group."
redirect_to @group
else
render :action => 'new'
end
end end
def new def new
@ -22,36 +19,31 @@ class GroupsController < ApplicationController
end end
def destroy def destroy
@group = Group.first(:id => params[:id]) @group = Group.find_by_id params[:id]
@group.destroy @group.destroy
flash[:notice] = "Successfully destroyed group." respond_with :location => groups_url
redirect_to groups_url
end end
def show def show
@group = Group.first(:id => params[:id]) @group = Group.find_by_id params[:id]
@friends = @group.people @friends = @group.people
@posts = current_user.visible_posts( :by_members_of => @group ).paginate :order => 'created_at DESC' @posts = current_user.visible_posts( :by_members_of => @group ).paginate :order => 'created_at DESC'
respond_with @group
end end
def edit def edit
@groups = current_user.groups @groups = current_user.groups
@group = Group.first(:id => params[:id]) @group = Group.find_by_id params[:id]
end end
def update def update
@group = Group.first(:id => params[:id]) @group = Group.find_by_id(params[:id])
if @group.update_attributes(params[:group]) @group.update_attributes(params[:group])
#flash[:notice] = "Successfully updated group." respond_with @group
redirect_to @group
else
render :action => 'edit'
end
end end
def move_friends def move_friends
pp params
params[:moves].each{ |move| params[:moves].each{ |move|
move = move[1] move = move[1]
unless current_user.move_friend(move) unless current_user.move_friend(move)
@ -63,8 +55,8 @@ class GroupsController < ApplicationController
flash[:notice] = "Groups edited successfully." flash[:notice] = "Groups edited successfully."
redirect_to Group.first, :action => "edit" redirect_to Group.first, :action => "edit"
end end
def move_friend def move_friend
unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to]) unless current_user.move_friend( :friend_id => params[:friend_id], :from => params[:from], :to => params[:to][:to])
flash[:error] = "didn't work #{params.inspect}" flash[:error] = "didn't work #{params.inspect}"

View file

@ -1,14 +1,12 @@
class PeopleController < ApplicationController class PeopleController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => [:index, :show]
def index def index
unless params[:q] @people = Person.search params[:q]
@people = current_user.friends.paginate :page => params[:page], :order => 'created_at DESC' respond_with @people
render :index
else
@people = Person.search(params[:q])
render :json => @people.to_json(:only => :_id)
end
end end
def show def show
@ -22,12 +20,13 @@ class PeopleController < ApplicationController
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
@post_count = @posts.count @post_count = @posts.count
respond_with @person
end end
def destroy def destroy
current_user.unfriend(current_user.visible_person_by_id(params[:id])) current_user.unfriend(current_user.visible_person_by_id(params[:id]))
flash[:notice] = "unfriended person." respond_with :location => people_url
redirect_to people_url
end end
end end

View file

@ -1,20 +1,28 @@
class PhotosController < ApplicationController class PhotosController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
def create def create
album = Album.find_by_id params[:album_id]
begin begin
@photo = current_user.post(:photo, params) @photo = current_user.post(:photo, params)
render :nothing => true if @photo.created_at respond_with @photo
rescue TypeError rescue TypeError
flash[:error] = "Photo upload failed. Are you sure an image was added?" message = "Photo upload failed. Are you sure an image was added?"
redirect_to Album.first(:id => params[:album_id]) respond_with :location => album, :error => message
rescue CarrierWave::IntegrityError rescue CarrierWave::IntegrityError
flash[:error] = "Photo upload failed. Are you sure that was an image?" message = "Photo upload failed. Are you sure that was an image?"
redirect_to Album.first(:id => params[:album_id]) respond_with :location => album, :error => message
rescue RuntimeError => e rescue RuntimeError => e
flash[:error] = "Photo upload failed. Are you sure that your seatbelt is fastened?" message = "Photo upload failed. Are you sure that your seatbelt is fastened?"
redirect_to Album.first(:id => params[:album_id]) respond_with :location => album, :error => message
raise e raise e
end end
end end
@ -26,29 +34,27 @@ class PhotosController < ApplicationController
end end
def destroy def destroy
@photo = Photo.first(:id => params[:id]) @photo = Photo.find_by_id params[:id]
@photo.destroy @photo.destroy
flash[:notice] = "Successfully deleted photo." respond_with :location => @photo.album
redirect_to @photo.album
end end
def show def show
@photo = Photo.first(:id => params[:id]) @photo = Photo.find_by_id params[:id]
@album = @photo.album @album = @photo.album
respond_with @photo, @album
end end
def edit def edit
@photo= Photo.first(:id => params[:id]) @photo = Photo.find_by_id params[:id]
@album = @photo.album @album = @photo.album
end end
def update def update
@photo= Photo.first(:id => params[:id]) @photo = Photo.find_by_id params[:id]
if @photo.update_attributes(params[:photo]) @photo.update_attributes params[:photo]
flash[:notice] = "Successfully updated photo."
redirect_to @photo respond_with @photo
else
render :action => 'edit'
end
end end
end end

View file

@ -3,7 +3,7 @@ class PublicsController < ApplicationController
include Diaspora::Parser include Diaspora::Parser
def hcard def hcard
@person = Person.first(:_id => params[:id]) @person = Person.find_by_id params[:id]
unless @person.nil? || @person.owner.nil? unless @person.nil? || @person.owner.nil?
render 'hcard' render 'hcard'

View file

@ -1,29 +1,31 @@
class RequestsController < ApplicationController class RequestsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
include RequestsHelper include RequestsHelper
respond_to :html
respond_to :json, :only => :index
def index def index
@remote_requests = Request.for_user( current_user ) @remote_requests = Request.for_user current_user
@request = Request.new @request = Request.new
respond_with @remote_requests
end end
def destroy def destroy
if params[:accept] if params[:accept]
if params[:group_id] if params[:group_id]
@friend = current_user.accept_and_respond( params[:id], params[:group_id]) @friend = current_user.accept_and_respond( params[:id], params[:group_id])
flash[:notice] = "you are now friends" flash[:notice] = "you are now friends"
redirect_to current_user.group_by_id(params[:group_id]) respond_with :location => current_user.group_by_id(params[:group_id])
else else
flash[:error] = "please select a group!" flash[:error] = "please select a group!"
redirect_to requests_url respond_with :location => requests_url
end end
else else
current_user.ignore_friend_request params[:id] current_user.ignore_friend_request params[:id]
flash[:notice] = "ignored friend request" respond_with :location => requests_url, :notice => "Ignored friend request."
redirect_to requests_url
end end
end end
def new def new
@ -31,11 +33,12 @@ class RequestsController < ApplicationController
end end
def create def create
group = current_user.group_by_id(params[:request][:group_id])
begin begin
rel_hash = relationship_flow(params[:request][:destination_url]) rel_hash = relationship_flow(params[:request][:destination_url])
rescue Exception => e rescue Exception => e
flash[:error] = "no diaspora seed found with this email!" respond_with :location => group, :error => "No diaspora seed found with this email!"
redirect_to current_user.group_by_id(params[:request][:group_id])
return return
end end
@ -45,17 +48,17 @@ class RequestsController < ApplicationController
@request = current_user.send_request(rel_hash, params[:request][:group_id]) @request = current_user.send_request(rel_hash, params[:request][:group_id])
rescue Exception => e rescue Exception => e
raise e unless e.message.include? "already friends" raise e unless e.message.include? "already friends"
flash[:notice] = "You are already friends with #{params[:request][:destination_url]}!" message = "You are already friends with #{params[:request][:destination_url]}!"
redirect_to current_user.group_by_id(params[:request][:group_id]) respond_with :location => group, :notice => message
return return
end end
if @request if @request
flash[:notice] = "a friend request was sent to #{@request.destination_url}" message = "A friend request was sent to #{@request.destination_url}."
redirect_to current_user.group_by_id(params[:request][:group_id]) respond_with :location => group, :notice => message
else else
flash[:error] = "Something went horribly wrong..." message = "Something went horribly wrong."
redirect_to current_user.group_by_id(params[:request][:group_id]) respond_with :location => group, :error => message
end end
end end

View file

@ -1,31 +1,23 @@
class StatusMessagesController < ApplicationController class StatusMessagesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
def create def create
params[:status_message][:to] = params[:group_ids] params[:status_message][:to] = params[:group_ids]
@status_message = current_user.post(:status_message, params[:status_message]) @status_message = current_user.post(:status_message, params[:status_message])
respond_with @status_message
if @status_message.created_at
render :nothing => true
else
redirect_to root_url
end
end end
def destroy def destroy
@status_message = StatusMessage.where(:id => params[:id]).first @status_message = StatusMessage.find_by_id params[:id]
@status_message.destroy @status_message.destroy
flash[:notice] = "Successfully destroyed status message." respond_with :location => root_url
redirect_to root_url
end end
def show def show
@status_message = StatusMessage.where(:id => params[:id]).first @status_message = StatusMessage.find_by_id params[:id]
respond_with @status_message
respond_to do |format|
format.html
format.xml { render :xml => @status_message.build_xml_for }
format.json { render :json => @status_message }
end
end end
end end

View file

@ -1,37 +1,26 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_filter :authenticate_user!, :except => [:new, :create] before_filter :authenticate_user!, :except => [:new, :create]
def index
@groups_array = current_user.groups.collect{|x| [x.to_s, x.id]}
unless params[:q] respond_to :html
@people = Person.all respond_to :json, :only => :show
render :index
else
@people = Person.search(params[:q])
end
end
def show def show
@user= User.first(:id => params[:id]) @user = User.find_by_id params[:id]
@user_profile = @user.person.profile @user_profile = @user.person.profile
respond_with @user
end end
def edit def edit
@user = current_user @user = current_user
@person = @user.person @person = @user.person
@profile = @user.profile @profile = @user.profile
@photos = Photo.where(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' @photos = Photo.find_all_by_person_id(@person.id).paginate :page => params[:page], :order => 'created_at DESC'
end end
def update def update
@user = User.where(:id => params[:id]).first @user = User.find_by_id params[:id]
@user.update_profile params[:user]
if @user.update_profile(params[:user]) respond_with @user
flash[:notice] = "Successfully updated your profile"
redirect_to @user.person
else
render :action => 'edit'
end
end end
end end

View file

@ -1,6 +1,7 @@
class Album < Post class Album < Post
xml_reader :name xml_reader :name
key :name, String key :name, String
many :photos, :class_name => 'Photo', :foreign_key => :album_id many :photos, :class_name => 'Photo', :foreign_key => :album_id
@ -13,11 +14,7 @@ class Album < Post
def self.mine_or_friends(friend_param, current_user) def self.mine_or_friends(friend_param, current_user)
if friend_param friend_param ? Album.find_all_by_person_id(current_user.friend_ids) : current_user.person.albums
Album.find_all_by_person_id(current_user.friend_ids)
else
current_user.person.albums
end
end end
def prev_photo(photo) def prev_photo(photo)

View file

@ -10,16 +10,17 @@ class Comment
xml_accessor :post_id xml_accessor :post_id
xml_accessor :_id xml_accessor :_id
key :text, String key :text, String
timestamps! key :post_id, ObjectId
key :post_id, ObjectId
belongs_to :post, :class_name => "Post"
key :person_id, ObjectId key :person_id, ObjectId
belongs_to :post, :class_name => "Post"
belongs_to :person, :class_name => "Person" belongs_to :person, :class_name => "Person"
validates_presence_of :text validates_presence_of :text
timestamps!
def push_upstream def push_upstream
Rails.logger.info("GOIN UPSTREAM") Rails.logger.info("GOIN UPSTREAM")

View file

@ -1,19 +1,19 @@
class Group class Group
include MongoMapper::Document include MongoMapper::Document
key :name, String key :name, String
validates_presence_of :name key :person_ids, Array
key :person_ids, Array
key :request_ids, Array key :request_ids, Array
key :post_ids, Array key :post_ids, Array
many :people, :in => :person_ids, :class_name => 'Person' many :people, :in => :person_ids, :class_name => 'Person'
many :requests, :in => :request_ids, :class_name => 'Request' many :requests, :in => :request_ids, :class_name => 'Request'
many :posts, :in => :post_ids, :class_name => 'Post' many :posts, :in => :post_ids, :class_name => 'Post'
belongs_to :user, :class_name => 'User' belongs_to :user, :class_name => 'User'
validates_presence_of :name
timestamps! timestamps!
def to_s def to_s
@ -24,5 +24,15 @@ class Group
id = id.to_id id = id.to_id
posts.detect{|x| x.person.id == id } posts.detect{|x| x.person.id == id }
end end
def as_json(opts = {})
{
:group => {
:name => self.name,
:people => self.people.each{|person| person.as_json},
:posts => self.posts.each {|post| post.as_json },
}
}
end
end end

View file

@ -8,21 +8,16 @@ class Person
xml_accessor :profile, :as => Profile xml_accessor :profile, :as => Profile
xml_reader :exported_key xml_reader :exported_key
key :url, String
key :email, String, :unique => true key :email, String, :unique => true
key :url, String
key :serialized_key, String key :serialized_key, String
key :owner_id, ObjectId
key :owner_id, ObjectId
key :user_refs, Integer, :default => 0 key :user_refs, Integer, :default => 0
belongs_to :owner, :class_name => 'User'
one :profile, :class_name => 'Profile' one :profile, :class_name => 'Profile'
many :albums, :class_name => 'Album', :foreign_key => :person_id many :albums, :class_name => 'Album', :foreign_key => :person_id
belongs_to :owner, :class_name => 'User'
timestamps! timestamps!
@ -81,8 +76,19 @@ class Person
owner.nil? owner.nil?
end end
protected def as_json(opts={})
{
:person => {
:id => self.id,
:name => self.real_name,
:email => self.email,
:url => self.url,
:exported_key => exported_key
}
}
end
protected
def clean_url def clean_url
self.url ||= "http://localhost:3000/" if self.class == User self.url ||= "http://localhost:3000/" if self.class == User
if self.url if self.url
@ -92,9 +98,8 @@ class Person
end end
private private
def remove_all_traces def remove_all_traces
Post.all(:person_id => id).each{|p| p.delete} Post.all(:person_id => id).each{|p| p.delete}
Album.all(:person_id => id).each{|p| p.delete} Album.all(:person_id => id).each{|p| p.delete}
end end
end end

View file

@ -8,13 +8,18 @@ class Photo < Post
xml_reader :album_id xml_reader :album_id
key :album_id, ObjectId key :album_id, ObjectId
key :caption, String key :caption, String
key :remote_photo_path
key :remote_photo_name
belongs_to :album, :class_name => 'Album' belongs_to :album, :class_name => 'Album'
timestamps! timestamps!
validates_presence_of :album validates_presence_of :album
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
before_destroy :ensure_user_picture
def self.instantiate(params = {}) def self.instantiate(params = {})
image_file = params[:user_file].first image_file = params[:user_file].first
@ -25,19 +30,13 @@ class Photo < Post
photo.save photo.save
photo photo
end end
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
before_destroy :ensure_user_picture
key :remote_photo_path
key :remote_photo_name
def validate_album_person def validate_album_person
album.person_id == person_id album.person_id == person_id
end end
def remote_photo def remote_photo
image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url
end end
def remote_photo= remote_path def remote_photo= remote_path

View file

@ -16,12 +16,11 @@ class Post
many :comments, :class_name => 'Comment', :foreign_key => :post_id many :comments, :class_name => 'Comment', :foreign_key => :post_id
belongs_to :person, :class_name => 'Person' belongs_to :person, :class_name => 'Person'
timestamps!
cattr_reader :per_page cattr_reader :per_page
@@per_page = 10 @@per_page = 10
timestamps!
before_destroy :propogate_retraction before_destroy :propogate_retraction
after_destroy :destroy_comments after_destroy :destroy_comments
@ -29,7 +28,7 @@ class Post
self.create params self.create params
end end
#ENCRYPTION #ENCRYPTION
xml_accessor :creator_signature xml_accessor :creator_signature
key :creator_signature, String key :creator_signature, String
@ -45,14 +44,23 @@ class Post
signable_accessors.collect{|accessor| signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';' (self.send accessor.to_sym).to_s}.join ';'
end end
def as_json(opts={})
{
:post => {
:id => self.id,
:person => self.person.as_json,
}
}
end
protected protected
def destroy_comments def destroy_comments
comments.each{|c| c.destroy} comments.each{|c| c.destroy}
end end
def propogate_retraction def propogate_retraction
self.person.owner.retract(self) self.person.owner.retract(self)
end end
end end

View file

@ -8,11 +8,10 @@ class Profile
xml_accessor :first_name xml_accessor :first_name
xml_accessor :last_name xml_accessor :last_name
xml_accessor :image_url xml_accessor :image_url
key :first_name, String key :first_name, String
key :last_name, String key :last_name, String
key :image_url, String key :image_url, String
validates_presence_of :first_name, :last_name validates_presence_of :first_name, :last_name

View file

@ -11,18 +11,18 @@ class Request
xml_accessor :callback_url xml_accessor :callback_url
xml_accessor :exported_key, :cdata => true xml_accessor :exported_key, :cdata => true
key :person_id, ObjectId
key :group_id, ObjectId
key :destination_url, String key :destination_url, String
key :callback_url, String key :callback_url, String
key :person_id, ObjectId key :exported_key, String
key :exported_key, String
key :group_id, ObjectId
belongs_to :person belongs_to :person
validates_presence_of :destination_url, :callback_url validates_presence_of :destination_url, :callback_url
before_validation :clean_link before_validation :clean_link
scope :for_user, lambda{ |user| where(:destination_url => user.receive_url) } scope :for_user, lambda{ |user| where(:destination_url => user.receive_url) }
scope :from_user, lambda{ |user| where(:destination_url.ne => user.receive_url) } scope :from_user, lambda{ |user| where(:destination_url.ne => user.receive_url) }
def self.instantiate(options = {}) def self.instantiate(options = {})
@ -41,29 +41,28 @@ class Request
self.save self.save
end end
#ENCRYPTION #ENCRYPTION
xml_accessor :creator_signature xml_accessor :creator_signature
key :creator_signature, String key :creator_signature, String
def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition|
definition.accessor}
accessors.delete 'person'
accessors.delete 'creator_signature'
accessors
end
def signable_string
signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';'
end
def signature_valid?; true; end
protected def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition|
definition.accessor}
accessors.delete 'person'
accessors.delete 'creator_signature'
accessors
end
def signable_string
signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';'
end
def signature_valid?; true; end
protected
def clean_link def clean_link
if self.destination_url if self.destination_url
self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://') self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')

View file

@ -3,6 +3,15 @@ class Retraction
include Diaspora::Webhooks include Diaspora::Webhooks
include Encryptable include Encryptable
xml_accessor :post_id
xml_accessor :person_id
xml_accessor :type
attr_accessor :post_id
attr_accessor :person_id
attr_accessor :type
def self.for(object) def self.for(object)
retraction = self.new retraction = self.new
if object.is_a? User if object.is_a? User
@ -16,14 +25,6 @@ class Retraction
retraction retraction
end end
xml_accessor :post_id
xml_accessor :person_id
xml_accessor :type
attr_accessor :post_id
attr_accessor :person_id
attr_accessor :type
def perform receiving_user_id def perform receiving_user_id
Rails.logger.debug "Performing retraction for #{post_id}" Rails.logger.debug "Performing retraction for #{post_id}"
begin begin
@ -55,21 +56,21 @@ class Retraction
Person.find_by_id(self.person_id) Person.find_by_id(self.person_id)
end end
#ENCRYPTION #ENCRYPTION
xml_accessor :creator_signature xml_accessor :creator_signature
def signable_accessors def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition| accessors = self.class.roxml_attrs.collect{|definition|
definition.accessor} definition.accessor}
accessors.delete 'person' accessors.delete 'person'
accessors.delete 'creator_signature' accessors.delete 'creator_signature'
accessors accessors
end end
def signable_string def signable_string
signable_accessors.collect{|accessor| signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s (self.send accessor.to_sym).to_s
}.join ';' }.join ';'
end end
end end

View file

@ -6,17 +6,17 @@ class User
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
key :friend_ids, Array key :friend_ids, Array
key :pending_request_ids, Array key :pending_request_ids, Array
key :visible_post_ids, Array key :visible_post_ids, Array
key :visible_person_ids, Array key :visible_person_ids, Array
one :person, :class_name => 'Person', :foreign_key => :owner_id one :person, :class_name => 'Person', :foreign_key => :owner_id
many :friends, :in => :friend_ids, :class_name => 'Person' many :friends, :in => :friend_ids, :class_name => 'Person'
many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request' many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
many :groups, :class_name => 'Group' many :groups, :class_name => 'Group'
@ -31,7 +31,6 @@ class User
self.person.send(method, *args) self.person.send(method, *args)
end end
def real_name def real_name
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
end end
@ -61,6 +60,7 @@ class User
end end
false false
end end
######## Posting ######## ######## Posting ########
def post(class_name, options = {}) def post(class_name, options = {})
options[:person] = self.person options[:person] = self.person
@ -96,7 +96,8 @@ class User
else else
groups = self.groups.find_all_by_id( group_ids ) groups = self.groups.find_all_by_id( group_ids )
end end
#send to the groups
#send to the groups
target_people = [] target_people = []
groups.each{ |group| groups.each{ |group|
@ -142,7 +143,6 @@ class User
end end
######### Posts and Such ############### ######### Posts and Such ###############
def retract( post ) def retract( post )
post.unsocket_from_uid(self.id) if post.respond_to? :unsocket_from_uid post.unsocket_from_uid(self.id) if post.respond_to? :unsocket_from_uid
retraction = Retraction.for(post) retraction = Retraction.for(post)
@ -281,6 +281,19 @@ class User
def all_group_ids def all_group_ids
self.groups.all.collect{|x| x.id} self.groups.all.collect{|x| x.id}
end end
def as_json(opts={})
{
:user => {
:posts => self.raw_visible_posts.each{|post| post.as_json},
:friends => self.friends.each {|friend| friend.as_json},
:groups => self.groups.each {|group| group.as_json},
:pending_requests => self.pending_requests.each{|request| request.as_json},
}
}
end
protected protected
def self.generate_key def self.generate_key

View file

@ -39,7 +39,7 @@
#session_action #session_action
#global_search #global_search
= form_tag(users_path, :method => 'get') do = form_tag(people_path, :method => 'get') do
%label{:for => 'q'} Search %label{:for => 'q'} Search
= text_field_tag 'q' = text_field_tag 'q'

View file

@ -1,24 +1,42 @@
/ %h1.big_text %h1.big_text
/ .back .back
/ = link_to '⇧ home', root_path = link_to "⇧ home", root_path
/ Friends
/ .button.right Search
/ = link_to 'Add Friend', requests_path
= @people.count.to_s + search_or_index %p
=form_tag '/users', :method => "get" do
= text_field_tag :q
= submit_tag "search"
= link_to "reset", users_path
= (@people.count).to_s + search_or_index
%table %table
%tr %tr
%th real name %th real name
%th email %th email
%th url %th url
- for person in @people - for person in @people
%tr %tr
%td= person.real_name %td= person.real_name
%td= person.email %td= person.email
%td= person.url %td= person.url
%td= link_to 'Show', person
%td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete -if current_user.friends.include? person
%p= link_to "Add a friend", requests_path - elsif person.id == current_user.person.id
%td
#pagination %td thats you!
= will_paginate @people -elsif current_user.pending_requests.find_by_person_id(person.id)
%td
%td ^-you have a friend request from this person
-elsif current_user.pending_requests.find_by_url(person.receive_url)
%td
%td friend request pending
-else
%td
%td
= form_for Request.new do |f|
= f.select(:group_id, @groups_array)
= f.hidden_field :destination_url, :value => person.email
= f.submit "add friend"

View file

@ -1,42 +0,0 @@
%h1.big_text
.back
= link_to "⇧ home", root_path
Search
%p
=form_tag '/users', :method => "get" do
= text_field_tag :q
= submit_tag "search"
= link_to "reset", users_path
= (@people.count).to_s + search_or_index
%table
%tr
%th real name
%th email
%th url
- for person in @people
%tr
%td= person.real_name
%td= person.email
%td= person.url
-if current_user.friends.include? person
- elsif person.id == current_user.person.id
%td
%td thats you!
-elsif current_user.pending_requests.find_by_person_id(person.id)
%td
%td ^-you have a friend request from this person
-elsif current_user.pending_requests.find_by_url(person.receive_url)
%td
%td friend request pending
-else
%td
%td
= form_for Request.new do |f|
= f.select(:group_id, @groups_array)
= f.hidden_field :destination_url, :value => person.email
= f.submit "add friend"

View file

@ -10,8 +10,8 @@ describe PeopleController do
end end
it "index should yield search results for substring of person name" do it "index should yield search results for substring of person name" do
pending "wait, what???"
Person.should_receive(:search) Person.should_receive(:search)
get :index, :q => "Eu" get :index, :q => "Eu"
end end