Remove sent boolean from requests, finish migration
This commit is contained in:
parent
dea8d248e2
commit
2cf332e120
3 changed files with 7 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ class RequestsController < ApplicationController
|
||||||
aspect = current_user.aspect_by_id(params[:request][:into])
|
aspect = current_user.aspect_by_id(params[:request][:into])
|
||||||
account = params[:request][:to].strip
|
account = params[:request][:to].strip
|
||||||
person = Person.by_account_identifier(account)
|
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
|
if existing_request
|
||||||
current_user.accept_and_respond(existing_request.id, aspect.id)
|
current_user.accept_and_respond(existing_request.id, aspect.id)
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ class Request
|
||||||
belongs_to :into, :class => Aspect
|
belongs_to :into, :class => Aspect
|
||||||
belongs_to :from, :class => Person
|
belongs_to :from, :class => Person
|
||||||
belongs_to :to, :class => Person
|
belongs_to :to, :class => Person
|
||||||
key :sent, Boolean, :default => false
|
|
||||||
|
|
||||||
validates_presence_of :from, :to
|
validates_presence_of :from, :to
|
||||||
validate :not_already_connected_if_sent
|
validate :not_already_connected_if_sent
|
||||||
|
|
@ -69,7 +68,7 @@ class Request
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.hashes_for_person person
|
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 = Person.all(:id.in => requests.map{|r| r.from_id}, :fields => [:profile])
|
||||||
senders_hash = {}
|
senders_hash = {}
|
||||||
senders.each{|sender| senders_hash[sender.id] = sender}
|
senders.each{|sender| senders_hash[sender.id] = sender}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,13 @@ namespace :migrations do
|
||||||
|
|
||||||
task :contacts_as_requests do
|
task :contacts_as_requests do
|
||||||
require File.join(Rails.root,"config/environment")
|
require File.join(Rails.root,"config/environment")
|
||||||
|
puts "Migrating contacts..."
|
||||||
old_contacts = Contact.all(:pending => nil)
|
old_contacts = Contact.all(:pending => nil)
|
||||||
old_contacts.each{|contact| contact.pending = false; contact.save}
|
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
|
end
|
||||||
|
|
||||||
desc 'allow to upgrade old image urls to use rel path'
|
desc 'allow to upgrade old image urls to use rel path'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue