Skip to content

Commit

Permalink
Added 'Cert' protocol to https
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalloor, Eric Abraham committed Nov 15, 2023
1 parent cc976e2 commit b1b5507
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions customer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def get_otp(user, user_type):

# send OTP Notification
from register.utils import send_whatsapp_message
from register.utils import is_dev
from register.utils import is_non_prod
wa_body = WA_OTP_MESSAGE_TEMPLATE
wa_body[
'to'] = f"91{DEV_NUMBER}" if is_dev() else f"91{user.contact}"
'to'] = f"91{DEV_NUMBER}" if is_non_prod() else f"91{user.contact}"
wa_body['template']['components'][0]['parameters'][0]['text'] = user.name.title()
wa_body['template']['components'][0]['parameters'][1][
'text'] = current_otp.otp_password
Expand Down
4 changes: 2 additions & 2 deletions customer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from register.constant import WA_NEW_MESSAGE, WA_NEW_MESSAGE_TEMPLATE
from register.models import Customer, Payment, Register, Tenant
from register.utils import get_customer_due_amount, get_mongo_client, send_whatsapp_message, \
is_mobile, get_client_ip, is_dev
is_mobile, get_client_ip, is_non_prod

logger = logging.getLogger()

Expand Down Expand Up @@ -284,6 +284,6 @@ def send_new_message_notification(from_sender):
wa_message = WA_NEW_MESSAGE.format(sender.name)
wa_body = WA_NEW_MESSAGE_TEMPLATE
wa_body[
'to'] = f"91{DEV_NUMBER}" if is_dev() else f"91{sender.tenant.contact}"
'to'] = f"91{DEV_NUMBER}" if is_non_prod() else f"91{sender.tenant.contact}"
wa_body['template']['components'][0]['parameters'][0]['text'] = sender.name
send_whatsapp_message(wa_body, wa_message, route='API_INFO')
6 changes: 3 additions & 3 deletions milkbasket/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = ENV_DEBUG

ALLOWED_HOSTS = ['milk.cyberboy.in', 'milkcrt.cyberboy.in', '127.0.0.1', 'm.cyberboy.in']
ALLOWED_HOSTS = ['milk.cyberboy.in', 'milkcrt.cyberboy.in', '127.0.0.1', '140.238.228.149', '146.56.53.63']

LOGIN_URL = reverse_lazy('landing')

Expand Down Expand Up @@ -166,7 +166,7 @@

# Sentry Logging
sentry_sdk.init(
dsn=SENTRY_DSN_DEV if RUN_ENVIRONMENT == 'dev' else SENTRY_DSN_PROD,
dsn=SENTRY_DSN_PROD if RUN_ENVIRONMENT == 'production' else SENTRY_DSN_DEV,
integrations=[
DjangoIntegration(),
],
Expand All @@ -182,7 +182,7 @@
# Sentry Env Config
environment="production",
auto_session_tracking=True,
# environment="dev" if RUN_ENVIRONMENT == 'dev' else "production",
# environment="dev" if is_non_prod() else "production",
# Profiling
_experiments={
"profiles_sample_rate": 1.0,
Expand Down
11 changes: 8 additions & 3 deletions register/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def send_wa_payment_notification(cust_number, cust_name, payment_amount, payment
transaction_number):
""" Send WA notification for Payment received """
wa_body = WA_PAYMENT_MESSAGE_TEMPLATE_V2
wa_body['to'] = f"91{DEV_NUMBER}" if is_dev() else f"91{cust_number}"
wa_body['to'] = f"91{DEV_NUMBER}" if is_non_prod() else f"91{cust_number}"
wa_body['template']['components'][1]['parameters'][0]['text'] = cust_name
wa_body['template']['components'][1]['parameters'][1]['text'] = payment_amount
wa_body['template']['components'][1]['parameters'][2]['text'] = payment_time
Expand Down Expand Up @@ -595,9 +595,14 @@ def calculate_milk_price(register_qs):
return total_due / 1000 if total_due else 0


def is_dev():
def is_non_prod():
""" Helper function to check the current environment. Reruns Boolean"""
return RUN_ENVIRONMENT == 'dev'
return RUN_ENVIRONMENT != 'production'


def get_protocol():
""" Helper function to get the correct protocol for respective environment. Reruns String"""
return 'http' if RUN_ENVIRONMENT == 'dev' else 'https'


# ===================== Custom Error Handler Views ==============================
Expand Down
14 changes: 7 additions & 7 deletions register/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from register.models import Register
from register.models import Tenant
from register.utils import authenticate_alexa, get_customer_contact, send_wa_payment_notification, \
get_whatsapp_media_by_id, get_client_ip, is_dev
get_whatsapp_media_by_id, get_client_ip, is_non_prod, get_protocol
from register.utils import generate_bill
from register.utils import get_customer_all_due
from register.utils import get_customer_due_amount
Expand Down Expand Up @@ -78,7 +78,7 @@ def index(request, year=None, month=None):
'month_year': month_year,
'register_date_month': register_date.month,
'register_date_year': register_date.year,
'protocol': 'https' if RUN_ENVIRONMENT == 'production' else 'http',
'protocol': get_protocol(),
'show_tooltip': str(not is_mobile(request)).lower(),
})
return render(request, template, context)
Expand Down Expand Up @@ -578,7 +578,7 @@ def account(request, year=None, month=None):
'menu_account': True,
'register_date_month': register_date.month,
'register_date_year': register_date.year,
'protocol': 'https' if RUN_ENVIRONMENT == 'production' else 'http',
'protocol': get_protocol(),
}
return render(request, template, context)

Expand Down Expand Up @@ -883,7 +883,7 @@ def report_initial(request):
'page_title': 'Milk Basket - Report',
'is_mobile': is_mobile(request),
'menu_report': True,
'protocol': 'https' if RUN_ENVIRONMENT == 'production' else 'http'
'protocol': get_protocol()
}
return render(request, template, context)

Expand Down Expand Up @@ -960,7 +960,7 @@ def customer_profile(request, cust_id=None):
context.update({
'menu_customer': True,
'customer_id': cust_id,
'protocol': 'https' if RUN_ENVIRONMENT == 'production' else 'http',
'protocol': get_protocol(),
})
return render(request, template, context)
return redirect('view_customers')
Expand Down Expand Up @@ -1099,7 +1099,7 @@ def broadcast_send(request, cust_id=None):
sms_body = SMS_DUE_MESSAGE.format(due[0]['name'], due[0]['due_month'],
due[0]['to_be_paid'])
wa_body = WA_DUE_MESSAGE_TEMPLATE_V3
wa_body['to'] = f"91{DEV_NUMBER}" if is_dev() else f"91{cust_number}"
wa_body['to'] = f"91{DEV_NUMBER}" if is_non_prod() else f"91{cust_number}"
wa_body['template']['components'][1]['parameters'][0]['text'] = due[0]['name']
wa_body['template']['components'][1]['parameters'][1]['text'] = due[0]['to_be_paid']
wa_body['template']['components'][1]['parameters'][2]['text'] = due[0]['due_month']
Expand All @@ -1112,7 +1112,7 @@ def broadcast_send(request, cust_id=None):
res = {'sms': False, 'whatsapp': False}

def proxy_send_sms_api():
res['sms'] = send_sms_api(DEV_NUMBER if is_dev() else cust_number,
res['sms'] = send_sms_api(DEV_NUMBER if is_non_prod() else cust_number,
sms_body,
DUE_TEMPLATE_ID)

Expand Down

0 comments on commit b1b5507

Please sign in to comment.