myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2018] branches/invitation_throttling/app/control


From: noreply
Subject: [myexperiment-hackers] [2018] branches/invitation_throttling/app/controllers/networks_controller. rb: Throttling.
Date: Sat, 29 Nov 2008 20:38:53 -0500 (EST)

Revision
2018
Author
alekses6
Date
2008-11-29 20:38:53 -0500 (Sat, 29 Nov 2008)

Log Message

Throttling. Group invites now also have limits.

Modified Paths

Diff

Modified: branches/invitation_throttling/app/controllers/networks_controller.rb (2017 => 2018)


--- branches/invitation_throttling/app/controllers/networks_controller.rb	2008-11-28 19:42:35 UTC (rev 2017)
+++ branches/invitation_throttling/app/controllers/networks_controller.rb	2008-11-30 01:38:53 UTC (rev 2018)
@@ -30,7 +30,22 @@
   
   # GET /networks/1;invite
   def invite
+    error_msg = ""
+    sending_allowed_with_reset_timestamp = ActivityLimit.check_limit(current_user, "group_invite", false)
+    unless sending_allowed_with_reset_timestamp[0]
+      # limit of invitation for this user is already exceeded
+      error_msg = "Please note that you can't send email invitations - your limit is reached, "
+      if sending_allowed_with_reset_timestamp[1].nil?
+        error_msg += "it will not be reset. Please contact myExperiment administration for details."
+      elsif sending_allowed_with_reset_timestamp[1] <= 60
+        error_msg += "please try again within a couple of minutes"
+      else
+        error_msg += "it will be reset in " + formatted_timespan(sending_allowed_with_reset_timestamp[1])
+      end
+    end
+    
     respond_to do |format|
+      flash.now[:error] = error_msg unless error_msg.blank?
       format.html # invite.rhtml
     end
   end
@@ -91,9 +106,10 @@
     else
       # captcha verified correctly, can proceed
     
-      addr_count, validated_addr_count, valid_addresses, db_user_addresses, err_addresses, overflow_addresses = Invitation.validate_address_list(params[:invitations][:address_list])
+      addr_count, validated_addr_count, valid_addresses, db_user_addresses, err_addresses = Invitation.validate_address_list(params[:invitations][:address_list], current_user)
       existing_invitation_emails = []
       valid_addresses_tokens = {} # a hash for pairs of 'email' => 'token'
+      overflow_addresses = []
       
       if validated_addr_count > 0
         emails_counter = 0; counter = 0
@@ -103,10 +119,14 @@
           if PendingInvitation.find_by_email_and_request_type_and_request_for(email_addr, "membership", params[:id])
             existing_invitation_emails << email_addr
           else 
-            token_code = Digest::SHA1.hexdigest( email_addr.reverse + SECRET_WORD )
-            valid_addresses_tokens[email_addr] = token_code
-            invitation = PendingInvitation.new(:email => email_addr, :request_type => "membership", :requested_by => current_user.id, :request_for => params[:id], :message => params[:invitations][:msg_text], :token => token_code)
-            invitation.save
+            if ActivityLimit.check_limit(current_user, "group_invite")[0]
+              token_code = Digest::SHA1.hexdigest( email_addr.reverse + SECRET_WORD )
+              valid_addresses_tokens[email_addr] = token_code
+              invitation = PendingInvitation.new(:email => email_addr, :request_type => "membership", :requested_by => current_user.id, :request_for => params[:id], :message => params[:invitations][:msg_text], :token => token_code)
+              invitation.save
+            else
+              overflow_addresses << email_addr
+            end
           end        
         end
           
@@ -173,7 +193,17 @@
           end
           
           unless overflow_addresses.empty?
-            error_msg += "<br/><br/>You can only send invitations to X unique, valid, non-blank email addresses.<br/>The following addresses were not processed because of maximum allowed amount was exceeded:<br/>" + overflow_addresses.join("<br/>")
+            error_msg += "<br/><br/>You have ran out of quota for sending invitations, "
+            reset_quota_after = ActivityLimit.check_limit(current_user, "group_invite", false)[1]
+            if reset_quota_after.nil?
+              error_msg += "it will not be reset. Please contact myExperiment administration for details."
+            elsif reset_quota_after <= 60
+              error_msg += "please try again within a couple of minutes."
+            else
+              error_msg += "it will be reset in " + formatted_timespan(reset_quota_after) + "."
+            end
+            
+            error_msg += "<br/>The following addresses were not processed because maximum allowed amount of invitations was exceeded:<br/>" + overflow_addresses.join("<br/>")
           end
           
           error_msg += "</span>"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]