Skip to content

Commit

Permalink
control invites
Browse files Browse the repository at this point in the history
  • Loading branch information
asennoussi committed Oct 18, 2023
1 parent f6ec660 commit fa02c7e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
24 changes: 24 additions & 0 deletions accounts/migrations/0020_linkedaccounts_invites_sent_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.1 on 2023-10-18 15:09

import accounts.models
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0019_customuser_full_name'),
]

operations = [
migrations.AddField(
model_name='linkedaccounts',
name='invites_sent',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='customuser',
name='referral_code',
field=models.CharField(default=accounts.models.generate_referral_code, max_length=50, unique=True),
),
]
1 change: 1 addition & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class LinkedAccounts(models.Model):
last_history_id = models.CharField(default='', max_length=255)
whitelist_domains = ArrayField(
models.CharField(max_length=255), blank=True)
invites_sent = models.BooleanField(default=False)

def __str__(self):
return self.associated_email
Expand Down
7 changes: 7 additions & 0 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ class UserReferralsView(LoginRequiredMixin, ListView):
template_name = 'user_referrals.html'
context_object_name = 'referrals'

def get_context_data(self, **kwargs):
"""Returns the data passed to the template"""
context = super(UserReferralsView, self).get_context_data(**kwargs)
context['show_invite_button'] = LinkedAccounts.objects.filter(
invites_sent=False).exists()
return context

def get_queryset(self):
user = self.request.user
return Referral.objects.filter(inviter=user).select_related('referred_user')
Expand Down
4 changes: 3 additions & 1 deletion emailguru/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def send_invite_emails(user):

def schedule_chunk_emails(user, chunk_size=100):
linked_accounts = LinkedAccounts.objects.filter(
owner=user, active=True)
owner=user, active=True, invites_sent=False)
registered_emails = set(CustomUser.objects.values_list('email', flat=True))
all_contacts = set() # Initialize as an empty set
for la in linked_accounts:
Expand Down Expand Up @@ -345,6 +345,8 @@ def schedule_chunk_emails(user, chunk_size=100):
# Schedule the function to run after scheduled_mins minutes
queue.enqueue_in(timedelta(minutes=scheduled_mins),
send_email_chunk, email_chunk, user=la.owner)
la.invites_sent = True
la.save()
except Exception as e:
print(e)

Expand Down
2 changes: 2 additions & 0 deletions referral/templates/user_referrals.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
</button>
</div>
</div>
{%if show_invite_button%}
<div class="col-auto p-2" style="margin-left:auto">
<a href="{% url 'invite_contacts' %}" class="btn btn-md btn-secondary">
<svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M9 6a3 3 0 11-6 0 3 3 0 016 0zM17 6a3 3 0 11-6 0 3 3 0 016 0zM12.93 17c.046-.327.07-.66.07-1a6.97 6.97 0 00-1.5-4.33A5 5 0 0119 16v1h-6.07zM6 11a5 5 0 015 5v1H1v-1a5 5 0 015-5z"></path></svg>
Invite Contacts
</a>
</div>
{%endif%}
</div>


Expand Down

0 comments on commit fa02c7e

Please sign in to comment.