From 1bb5f9f98399b2b9309374857624728a09e65a07 Mon Sep 17 00:00:00 2001
From: zhitomirskiyi <ilya@joindiaspora.com>
Date: Wed, 26 Jan 2011 18:08:57 -0800
Subject: [PATCH] only allow invites if invite count > 0 for current user

---
 app/controllers/services_controller.rb | 6 ++++++
 app/views/aspects/index.html.haml      | 2 --
 app/views/services/finder.html.haml    | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
index 578faf4fdf..f0e33f4682 100644
--- a/app/controllers/services_controller.rb
+++ b/app/controllers/services_controller.rb
@@ -52,6 +52,12 @@ class ServicesController < ApplicationController
   end
 
   def inviter
+    if current_user.invites == 0
+      flash[:error] = I18n.t 'invitations.create.no_more'
+      redirect_to :back
+      return
+    end
+
     @uid = params[:uid]
 
     if i_id = params[:invitation_id]
diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml
index 637bcdb096..835b179af4 100644
--- a/app/views/aspects/index.html.haml
+++ b/app/views/aspects/index.html.haml
@@ -44,5 +44,3 @@
     %h4= t('shared.invitations.invite_your_friends')
     = render "shared/invitations", :invites => @invites
 
-
-
diff --git a/app/views/services/finder.html.haml b/app/views/services/finder.html.haml
index 0da51b34c0..21f14f3b92 100644
--- a/app/views/services/finder.html.haml
+++ b/app/views/services/finder.html.haml
@@ -39,7 +39,7 @@
                 = t('invitations.new.already_invited')
                 %br
                 = link_to t('.resend'), service_inviter_path(:uid => uid, :provider => 'facebook', :invitation_id => friend[:invitation_id])
-              - else
+              - elsif current_user.invites > 0
                 = form_tag service_inviter_path do
                   = select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name'))
                   = hidden_field_tag :uid, uid
-- 
GitLab