Skip to content
Extraits de code Groupes Projets
requests_controller.rb 1,7 ko
Newer Older
Raphael's avatar
Raphael a validé
#   Copyright (c) 2010, Diaspora Inc.  This file is
Raphael's avatar
Raphael a validé
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael a validé
#   the COPYRIGHT file.
require File.join(Rails.root, 'lib/webfinger')
class RequestsController < ApplicationController
  before_filter :authenticate_user!
Jamie Wilkinson's avatar
Jamie Wilkinson a validé
  include RequestsHelper
Raphael's avatar
Raphael a validé
      if params[:aspect_id]
        @contact = current_user.accept_and_respond( params[:id], params[:aspect_id])
        flash[:notice] = I18n.t 'requests.destroy.success'
        respond_with :location => current_user.aspect_by_id(params[:aspect_id])
        flash[:error] = I18n.t 'requests.destroy.error'
        respond_with :location => requests_url
Raphael's avatar
Raphael a validé
      end
      current_user.ignore_contact_request params[:id]
      flash[:notice] = I18n.t 'requests.destroy.ignore'
 def create
   aspect = current_user.aspect_by_id(params[:request][:into])
Raphael's avatar
Raphael a validé
   account = params[:request][:to].strip
   person = Person.by_account_identifier(account)
   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
   else

     @contact = Contact.new(:user => current_user,
                            :person => person,
                            :aspect_ids => [aspect.id],
                            :pending => true)

     if @contact.save
       @contact.dispatch_request
       flash.now[:notice] = I18n.t('requests.create.sent')
       flash.now[:error] = @contact.errors.full_messages.join(', ')