Skip to content
Extraits de code Groupes Projets
request.rb 2,23 ko
Newer Older
  • Learn to ignore specific revisions
  • #    Copyright 2010 Diaspora Inc.
    #
    #    This file is part of Diaspora.
    #
    #    Diaspora is free software: you can redistribute it and/or modify
    #    it under the terms of the GNU Affero General Public License as published by
    #    the Free Software Foundation, either version 3 of the License, or
    #    (at your option) any later version.
    #
    #    Diaspora is distributed in the hope that it will be useful,
    #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #    GNU Affero General Public License for more details.
    #
    #    You should have received a copy of the GNU Affero General Public License
    #    along with Diaspora.  If not, see <http://www.gnu.org/licenses/>.
    #
    
    
    
      include MongoMapper::Document
      include Diaspora::Webhooks
      include ROXML
    
      xml_accessor :_id
      xml_accessor :person, :as => Person
    
    maxwell's avatar
    maxwell a validé
      xml_accessor :destination_url
      xml_accessor :callback_url
    
      xml_accessor :exported_key, :cdata => true
    
    Daniel Grippi's avatar
    Daniel Grippi a validé
      key :person_id,       ObjectId
    
    Raphael's avatar
    Raphael a validé
      key :aspect_id,        ObjectId
    
    Daniel Grippi's avatar
    Daniel Grippi a validé
      key :callback_url,    String
      key :exported_key,    String
    
      
      validates_presence_of :destination_url, :callback_url
    
    Daniel Grippi's avatar
    Daniel Grippi a validé
      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 = {})
    
        self.new(:destination_url => options[:to],
    
    danielvincent's avatar
    danielvincent a validé
                 :callback_url    => person.receive_url, 
                 :person          => person,
    
    Raphael's avatar
    Raphael a validé
                 :aspect_id        => options[:into])
    
    danielvincent's avatar
    danielvincent a validé
      def reverse_for accepting_user
        self.person          = accepting_user.person
    
        self.exported_key    = accepting_user.exported_key
    
        self.destination_url = self.callback_url
    
    danielvincent's avatar
    danielvincent a validé
        self.save
    
      def clean_link
        if self.destination_url
          self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')
          self.destination_url = self.destination_url + '/' if self.destination_url[-1,1] != '/'
        end
      end