diff --git a/app/models/album.rb b/app/models/album.rb index b10f63acd..d153dcc9c 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -1,6 +1,7 @@ class Album < Post xml_reader :name + key :name, String 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) - if friend_param - Album.find_all_by_person_id(current_user.friend_ids) - else - current_user.person.albums - end + friend_param ? Album.find_all_by_person_id(current_user.friend_ids) : current_user.person.albums end def prev_photo(photo) diff --git a/app/models/comment.rb b/app/models/comment.rb index ef8e7a0f9..82de5ecdf 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,16 +10,17 @@ class Comment xml_accessor :post_id xml_accessor :_id - key :text, String - timestamps! - - key :post_id, ObjectId - belongs_to :post, :class_name => "Post" - + key :text, String + key :post_id, ObjectId key :person_id, ObjectId + + + belongs_to :post, :class_name => "Post" belongs_to :person, :class_name => "Person" validates_presence_of :text + + timestamps! def push_upstream Rails.logger.info("GOIN UPSTREAM") diff --git a/app/models/group.rb b/app/models/group.rb index 8a54a2766..0c5fa05b2 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,7 +1,7 @@ class Group include MongoMapper::Document - key :name, String + key :name, String key :person_ids, Array key :request_ids, Array key :post_ids, Array diff --git a/app/models/person.rb b/app/models/person.rb index 8c44ca60b..e0d8b17bf 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -8,21 +8,16 @@ class Person xml_accessor :profile, :as => Profile xml_reader :exported_key - - key :email, String, :unique => true - key :url, String - + key :url, String + key :email, String, :unique => true key :serialized_key, String - - key :owner_id, ObjectId + key :owner_id, ObjectId key :user_refs, Integer, :default => 0 - belongs_to :owner, :class_name => 'User' one :profile, :class_name => 'Profile' - many :albums, :class_name => 'Album', :foreign_key => :person_id - + belongs_to :owner, :class_name => 'User' timestamps! @@ -82,7 +77,6 @@ class Person end protected - def clean_url self.url ||= "http://localhost:3000/" if self.class == User if self.url @@ -92,9 +86,8 @@ class Person end private - def remove_all_traces Post.all(:person_id => id).each{|p| p.delete} Album.all(:person_id => id).each{|p| p.delete} end - end +end diff --git a/app/models/photo.rb b/app/models/photo.rb index 153aee214..412817585 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -8,13 +8,18 @@ class Photo < Post xml_reader :album_id key :album_id, ObjectId - key :caption, String + key :caption, String + key :remote_photo_path + key :remote_photo_name - belongs_to :album, :class_name => 'Album' + timestamps! validates_presence_of :album + validates_true_for :album_id, :logic => lambda {self.validate_album_person} + + before_destroy :ensure_user_picture def self.instantiate(params = {}) image_file = params[:user_file].first @@ -25,19 +30,13 @@ class Photo < Post photo.save photo 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 album.person_id == person_id end 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 def remote_photo= remote_path diff --git a/app/models/post.rb b/app/models/post.rb index 661fce4dc..00345837e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -16,12 +16,11 @@ class Post many :comments, :class_name => 'Comment', :foreign_key => :post_id belongs_to :person, :class_name => 'Person' + timestamps! cattr_reader :per_page @@per_page = 10 - timestamps! - before_destroy :propogate_retraction after_destroy :destroy_comments @@ -29,7 +28,7 @@ class Post self.create params end -#ENCRYPTION + #ENCRYPTION xml_accessor :creator_signature key :creator_signature, String @@ -46,13 +45,13 @@ class Post (self.send accessor.to_sym).to_s}.join ';' end -protected - def destroy_comments + protected + def destroy_comments comments.each{|c| c.destroy} end - def propogate_retraction - self.person.owner.retract(self) - end + def propogate_retraction + self.person.owner.retract(self) + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 9bea4fdb0..486e99b96 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -8,11 +8,10 @@ class Profile xml_accessor :first_name xml_accessor :last_name xml_accessor :image_url - key :first_name, String - key :last_name, String - key :image_url, String + key :last_name, String + key :image_url, String validates_presence_of :first_name, :last_name diff --git a/app/models/request.rb b/app/models/request.rb index d8dd322e0..afc1349eb 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -11,18 +11,18 @@ class Request xml_accessor :callback_url xml_accessor :exported_key, :cdata => true + key :person_id, ObjectId + key :group_id, ObjectId key :destination_url, String - key :callback_url, String - key :person_id, ObjectId - key :exported_key, String - key :group_id, ObjectId + key :callback_url, String + key :exported_key, String belongs_to :person validates_presence_of :destination_url, :callback_url 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) } def self.instantiate(options = {}) @@ -41,29 +41,28 @@ class Request self.save end -#ENCRYPTION + #ENCRYPTION - xml_accessor :creator_signature - 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 + xml_accessor :creator_signature + key :creator_signature, String - 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 if self.destination_url self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://') diff --git a/app/models/retraction.rb b/app/models/retraction.rb index e1f911d2d..afea944f6 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -3,6 +3,15 @@ class Retraction include Diaspora::Webhooks 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) retraction = self.new if object.is_a? User @@ -16,14 +25,6 @@ class Retraction retraction 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 Rails.logger.debug "Performing retraction for #{post_id}" begin @@ -55,21 +56,21 @@ class Retraction Person.find_by_id(self.person_id) end -#ENCRYPTION - xml_accessor :creator_signature + #ENCRYPTION + xml_accessor :creator_signature - def signable_accessors - accessors = self.class.roxml_attrs.collect{|definition| - definition.accessor} - accessors.delete 'person' - accessors.delete 'creator_signature' - accessors - end + 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 signable_string + signable_accessors.collect{|accessor| + (self.send accessor.to_sym).to_s + }.join ';' + end end diff --git a/app/models/user.rb b/app/models/user.rb index 3ede7ca8b..f16a2509c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,17 +6,17 @@ class User devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - key :friend_ids, Array + key :friend_ids, Array key :pending_request_ids, Array - key :visible_post_ids, Array - key :visible_person_ids, Array + key :visible_post_ids, Array + key :visible_person_ids, Array one :person, :class_name => 'Person', :foreign_key => :owner_id - 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 :pending_requests, :in => :pending_request_ids, :class_name => 'Request' - many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' + 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 :pending_requests, :in => :pending_request_ids, :class_name => 'Request' + many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post' many :groups, :class_name => 'Group' @@ -31,7 +31,6 @@ class User self.person.send(method, *args) end - def real_name "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" end @@ -61,6 +60,7 @@ class User end false end + ######## Posting ######## def post(class_name, options = {}) options[:person] = self.person @@ -96,7 +96,8 @@ class User else groups = self.groups.find_all_by_id( group_ids ) end -#send to the groups + + #send to the groups target_people = [] groups.each{ |group| @@ -142,7 +143,6 @@ class User end ######### Posts and Such ############### - def retract( post ) post.unsocket_from_uid(self.id) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post)