Commit 0d9039d7 authored by Birin Sanchez's avatar Birin Sanchez

* Handle magic cart properly.

* Add migration for ExternalBundle and Limit derived from adding new
  services on previous commits.
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 44f8c0d0
......@@ -4,6 +4,7 @@ from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django import forms
from django.contrib.auth import get_user_model
......@@ -61,7 +62,8 @@ class CartRegistrationView(RegistrationView):
valid_cart_numbers = list(
set().union(settings.WOO_CART_BASIC,
settings.WOO_CART_COMPLETE,
settings.WOO_CART_GROUP)
settings.WOO_CART_GROUP_BASIC,
settings.WOO_CART_GROUP_COMPLETE)
)
if settings.WOO_CART_ZERO:
......@@ -70,6 +72,12 @@ class CartRegistrationView(RegistrationView):
if settings.WOO_CART_999:
valid_cart_numbers.append("999")
if settings.WOO_CART_5000:
valid_cart_numbers.append("5000")
if settings.WOO_CART_5999:
valid_cart_numbers.append("5999")
self.reward = kwargs.get('reward', None)
if self.reward not in valid_cart_numbers:
......@@ -83,7 +91,7 @@ class CartRegistrationView(RegistrationView):
def get_success_url(self, user):
if self.reward in ["0", "999"]:
if self.reward in ["0", "999", "5000", "5999"]:
# skip billing page for magic cart numbers
# (but still force authentication for login purposes)
......@@ -108,20 +116,63 @@ class CartRegistrationView(RegistrationView):
def register(self, form):
user = super().register(form)
if self.reward == 0 or self.reward in settings.WOO_CART_BASIC:
reward = ChosenReward(user=user, reward=self.reward)
magic_carts = ["0", "999", "5000", "5999"]
basic_carts = list(set().union(["0", "5000"],
settings.WOO_CART_BASIC,
settings.WOO_CART_GROUP_BASIC))
complete_carts = list(set().union(["999", "5999"],
settings.WOO_CART_COMPLETE,
settings.WOO_CART_GROUP_COMPLETE))
group_carts = list(set().union(["5000", "5999"],
settings.WOO_CART_GROUP_BASIC,
settings.WOO_CART_GROUP_COMPLETE))
is_magic = self.reward in magic_carts
if is_magic:
reward.is_pending = False
# List of services that need to be activated for the new user
to_activate = []
if self.reward in basic_carts:
# Register as BASIC user
user.account_type = AccountType.BASIC
elif self.reward == 999 or self.reward in settings.WOO_CART_COMPLETE:
if is_magic:
reward.is_pending = False
# Activate Chat and Social
to_activate.append(settings.LM_SERVICES.SOCIAL)
to_activate.append(settings.LM_SERVICES.CHAT)
elif self.reward in complete_carts:
# Register as COMPLETE user
user.account_type = AccountType.COMPLETE
elif self.reward == 3 or self.reward in settings.WOO_CART_GROUP:
if is_magic:
reward.is_pending = False
# Activate all but Group
to_activate.append(settings.LM_SERVICES.SOCIAL)
to_activate.append(settings.LM_SERVICES.CHAT)
to_activate.append(settings.LM_SERVICES.TUNNEL)
to_activate.append(settings.LM_SERVICES.MAIL)
to_activate.append(settings.LM_SERVICES.XMPP)
if self.reward in group_carts:
user.account_type = AccountType.GROUP
else:
# Register as UNDEFINED user
user.account_type = AccountType.UNDEFINED
reward = ChosenReward(user=user, reward=self.reward)
if is_magic:
reward.is_pending = False
# Activate Group
to_activate.append(settings.LM_SERVICES.GROUP)
now = timezone.now()
next_month = now + timezone.timedelta(days=30)
limits = user.limit_set.all()
for limit in limits:
if limit.service in to_activate:
limit.renewal_date = next_month
limit.is_active = True
# Tunnel special case
if limit.service == settings.LM_SERVICES.TUNNEL:
user.generate_tunnel_account()
limit.save()
user.save()
reward.save()
return user
......@@ -28,19 +28,29 @@ AUTH_LDAP_BIND_DN=cn=admin,dc=example,dc=com
AUTH_LDAP_USER_SEARCH_BASE_DN=ou=people,dc=example,dc=com
SQLITE_DB_PATH=/var/opt/purist/middleware/db.sqlite3
STATICFILES_DIRS=/var/opt/purist/brand,/var/opt/purist/downloads
WOO_URL=https://example.com
WOO_WP_API=True
WOO_VERSION=wc/v1
WOO_QUERY_STRING_AUTH = True
WOOSUB1_PRODUCT_LIST = 123,124
WOO_CART_PATH=cart
WOO_CART_BASIC = 1
WOO_CART_COMPLETE = 2
WOO_CART_GROUP_BASIC = 3
WOO_CART_GROUP_COMPLETE = 4
WOO_CART_ZERO = True
WOO_CART_999 = True
WOO_CART_5000 = True
WOO_CART_5999 = True
WOO_CART_BILLING_PATH = add_to_cart
WOO_CART_THANKS_PATH = get-started
OVPN_HOSTNAME=ssh.example.com
OVPN_PORT=22
OVPN_USERNAME=username
OVPN_FILEPATH="/path/to/{IDENTITY}/{IDENTITY}.ovpn"
TUNNEL_HOST=https://example.com
PASSWORD_RESET_TOKEN_EXPIRES=1800
WOO_CART_GROUP = 1,2,4
# Email configuration example to use Mailtrap for development (https://source.puri.sm/snippets/56)
# EMAIL_HOST = '127.0.0.1'
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-08 09:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('limitmonitor', '0006_delete_credit_model'),
]
operations = [
migrations.AlterField(
model_name='externalbundle',
name='service',
field=models.IntegerField(choices=[(0, 'Undefined'), (1, 'Tunnel'), (2, 'Chat'), (3, 'Mail'), (4, 'Social'), (5, 'XMPP'), (6, 'Group')], default=0),
),
migrations.AlterField(
model_name='limit',
name='service',
field=models.IntegerField(choices=[(0, 'Undefined'), (1, 'Tunnel'), (2, 'Chat'), (3, 'Mail'), (4, 'Social'), (5, 'XMPP'), (6, 'Group')], default=0),
),
]
......@@ -167,9 +167,12 @@ WOO_CONSUMER_SECRET = secret_config("WOO_CONSUMER_SECRET")
WOO_CART_BASIC = config("WOO_CART_BASIC", cast=Csv(str))
WOO_CART_COMPLETE = config("WOO_CART_COMPLETE", cast=Csv(str))
WOO_CART_GROUP = config("WOO_CART_GROUP", cast=Csv(str))
WOO_CART_GROUP_BASIC = config("WOO_CART_GROUP_BASIC", cast=Csv(str))
WOO_CART_GROUP_COMPLETE = config("WOO_CART_GROUP_COMPLETE", cast=Csv(str))
WOO_CART_ZERO = config("WOO_CART_ZERO", cast=bool)
WOO_CART_999 = config("WOO_CART_999", cast=bool)
WOO_CART_5000 = config("WOO_CART_5000", cast=bool)
WOO_CART_5999 = config("WOO_CART_5999", cast=bool)
WOO_CART_BILLING_PATH = config("WOO_CART_BILLING_PATH")
WOO_CART_THANKS_PATH = config("WOO_CART_THANKS_PATH")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment