adding a test for decremented invites, as, and check the invite is valid in the controller
This commit is contained in:
parent
319b3c4d3b
commit
11505a386c
8 changed files with 26 additions and 12 deletions
|
|
@ -18,6 +18,8 @@ class InvitationsController < ApplicationController
|
||||||
|
|
||||||
# this is for legacy invites. We try to look the person who sent them the
|
# this is for legacy invites. We try to look the person who sent them the
|
||||||
# invite, and use their new invite code
|
# invite, and use their new invite code
|
||||||
|
# owe will be removing this eventually
|
||||||
|
# @depreciated
|
||||||
def edit
|
def edit
|
||||||
user = User.find_by_invitation_token(params[:invitation_token])
|
user = User.find_by_invitation_token(params[:invitation_token])
|
||||||
invitation_code = user.ugly_accept_invitation_code
|
invitation_code = user.ugly_accept_invitation_code
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
class RegistrationsController < Devise::RegistrationsController
|
class RegistrationsController < Devise::RegistrationsController
|
||||||
before_filter :check_registrations_open_or_vaild_invite!
|
before_filter :check_registrations_open_or_vaild_invite!, :check_valid_invite!
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@user = User.build(params[:user])
|
@user = User.build(params[:user])
|
||||||
|
|
@ -16,7 +16,7 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
|
Rails.logger.info("event=registration status=successful user=#{@user.diaspora_handle}")
|
||||||
else
|
else
|
||||||
@user.errors.delete(:person)
|
@user.errors.delete(:person)
|
||||||
|
|
||||||
flash[:error] = @user.errors.full_messages.join(";")
|
flash[:error] = @user.errors.full_messages.join(";")
|
||||||
Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
|
Rails.logger.info("event=registration status=failure errors='#{@user.errors.full_messages.join(', ')}'")
|
||||||
render :new
|
render :new
|
||||||
|
|
@ -28,6 +28,12 @@ class RegistrationsController < Devise::RegistrationsController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def check_valid_invite!
|
||||||
|
return true if invite.can_be_used?
|
||||||
|
flash[:error] = t('registrations.invalid_invite')
|
||||||
|
redirect_to new_user_session_path
|
||||||
|
end
|
||||||
|
|
||||||
def check_registrations_open_or_vaild_invite!
|
def check_registrations_open_or_vaild_invite!
|
||||||
return true if invite.present?
|
return true if invite.present?
|
||||||
if AppConfig[:registrations_closed]
|
if AppConfig[:registrations_closed]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ class InvitationCode < ActiveRecord::Base
|
||||||
token
|
token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_be_used?
|
||||||
|
self.count > 0
|
||||||
|
end
|
||||||
|
|
||||||
def add_invites!
|
def add_invites!
|
||||||
self.update_attributes(:count => self.count+100)
|
self.update_attributes(:count => self.count+100)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class User < ActiveRecord::Base
|
||||||
ConversationVisibility.sum(:unread, :conditions => "person_id = #{self.person.id}")
|
ConversationVisibility.sum(:unread, :conditions => "person_id = #{self.person.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
#should be deprecated
|
#@deprecated
|
||||||
def ugly_accept_invitation_code
|
def ugly_accept_invitation_code
|
||||||
begin
|
begin
|
||||||
self.invitations_to_me.first.sender.invitation_code
|
self.invitations_to_me.first.sender.invitation_code
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
.stream_element{:id => friend.id}
|
.stream_element{:id => friend.id}
|
||||||
.float-right
|
.float-right
|
||||||
|
- if friend.on_diaspora?
|
||||||
- if friend.already_invited?
|
|
||||||
= link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id), :class => 'button resend'
|
|
||||||
- elsif friend.on_diaspora?
|
|
||||||
= aspect_membership_dropdown(contact_proxy(friend), friend.person, 'left')
|
= aspect_membership_dropdown(contact_proxy(friend), friend.person, 'left')
|
||||||
- else
|
- else
|
||||||
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left', :dropdown_class => 'inviter', :service_uid => friend.uid
|
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left', :dropdown_class => 'inviter', :service_uid => friend.uid
|
||||||
|
|
|
||||||
|
|
@ -682,6 +682,7 @@ en:
|
||||||
update: "Update"
|
update: "Update"
|
||||||
cancel_my_account: "Cancel my account"
|
cancel_my_account: "Cancel my account"
|
||||||
closed: "Signups are closed on this Diaspora pod."
|
closed: "Signups are closed on this Diaspora pod."
|
||||||
|
invalid_invite: "The invite link you provided is no longer valid!"
|
||||||
|
|
||||||
requests:
|
requests:
|
||||||
manage_aspect_contacts:
|
manage_aspect_contacts:
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ Feature: invitation acceptance
|
||||||
Then I should be on the stream page
|
Then I should be on the stream page
|
||||||
|
|
||||||
Scenario: accept invitation from user
|
Scenario: accept invitation from user
|
||||||
Given I have been invited by a user
|
Given I have been invited by bob
|
||||||
And I am on my acceptance form page
|
And I am on my acceptance form page
|
||||||
And I fill in the following:
|
And I fill in the following:
|
||||||
| user_username | ohai |
|
| user_username | ohai |
|
||||||
|
|
@ -35,6 +35,10 @@ Feature: invitation acceptance
|
||||||
And I preemptively confirm the alert
|
And I preemptively confirm the alert
|
||||||
And I follow "awesome_button"
|
And I follow "awesome_button"
|
||||||
Then I should be on the stream page
|
Then I should be on the stream page
|
||||||
|
And I log out
|
||||||
|
And I sign in as "bob@bob.bob"
|
||||||
|
And I follow "By email"
|
||||||
|
Then I should see "9 invites left"
|
||||||
|
|
||||||
Scenario: sends an invitation
|
Scenario: sends an invitation
|
||||||
Given a user with email "bob@bob.bob"
|
Given a user with email "bob@bob.bob"
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,13 @@ end
|
||||||
|
|
||||||
Given /^I have been invited by an admin$/ do
|
Given /^I have been invited by an admin$/ do
|
||||||
admin = Factory(:user)
|
admin = Factory(:user)
|
||||||
bob.invitation_code
|
admin.invitation_code
|
||||||
i = EmailInviter.new("new_invitee@example.com", bob)
|
i = EmailInviter.new("new_invitee@example.com", admin)
|
||||||
i.send!
|
i.send!
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^I have been invited by a user$/ do
|
Given /^I have been invited by bob$/ do
|
||||||
@inviter = Factory(:user)
|
@inviter = Factory(:user, :email => 'bob@bob.bob')
|
||||||
i = EmailInviter.new("new_invitee@example.com", @inviter)
|
i = EmailInviter.new("new_invitee@example.com", @inviter)
|
||||||
i.send!
|
i.send!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue