diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index db0d8aba1428cee4e42ef14653f540ac1121ec9d..843f67c850c18905e8f3f61ccc179e795f155b48 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -31,7 +31,7 @@ class RequestsController < ApplicationController aspect = current_user.aspect_by_id(params[:request][:into]) account = params[:request][:to].strip person = Person.by_account_identifier(account) - existing_request = Request.from(person).to(current_user.person).where(:sent => false).first if person + existing_request = Request.from(person).to(current_user.person).first if person if existing_request current_user.accept_and_respond(existing_request.id, aspect.id) redirect_to :back diff --git a/app/models/request.rb b/app/models/request.rb index 15a5371135656ec184715d3cdef48a74269b9b4a..1456785aeebd14ec5b46c3ed6f432f5acfa84f93 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -15,7 +15,6 @@ class Request belongs_to :into, :class => Aspect belongs_to :from, :class => Person belongs_to :to, :class => Person - key :sent, Boolean, :default => false validates_presence_of :from, :to validate :not_already_connected_if_sent @@ -69,7 +68,7 @@ class Request end def self.hashes_for_person person - requests = Request.to(person).all(:sent => false) + requests = Request.to(person).all senders = Person.all(:id.in => requests.map{|r| r.from_id}, :fields => [:profile]) senders_hash = {} senders.each{|sender| senders_hash[sender.id] = sender} diff --git a/lib/tasks/migrations.rake b/lib/tasks/migrations.rake index c3ec99a4c54b5fa9e4fd36f9cb577e551a068b7a..8defa79f995927703a844648f01da43149e31444 100644 --- a/lib/tasks/migrations.rake +++ b/lib/tasks/migrations.rake @@ -29,9 +29,13 @@ namespace :migrations do task :contacts_as_requests do require File.join(Rails.root,"config/environment") + puts "Migrating contacts..." old_contacts = Contact.all(:pending => nil) old_contacts.each{|contact| contact.pending = false; contact.save} - puts "all done" + puts "Deleting stale requests..." + old_requests = Request.all(:sent => true) + old_requests.each{|request| request.delete} + puts "Done!" end desc 'allow to upgrade old image urls to use rel path'