Skip to content

Commit

Permalink
Merge pull request #68 from OpenLXP/ses_update
Browse files Browse the repository at this point in the history
Ses update
  • Loading branch information
KarenAJ authored Jun 14, 2024
2 parents 1ecd79b + 4acb07e commit dc81c16
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 42 deletions.
13 changes: 13 additions & 0 deletions app/configurations/fixtures/openlxp_email.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"model": "openlxp_notifications.email",
"pk": 1,
"fields": {
"sender": "[email protected]",
"reference": "Subscribed_list_update",
"subject": 1,
"template_type": 1,
"recipients": []
}
}
]
9 changes: 9 additions & 0 deletions app/configurations/fixtures/openlxp_email_subject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"model": "openlxp_notifications.subject",
"pk": 1,
"fields": {
"subject": "ECC New Resource Alert!"
}
}
]
11 changes: 11 additions & 0 deletions app/configurations/fixtures/openlxp_email_templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"model": "openlxp_notifications.template",
"pk": 1,
"fields": {
"template_type": "edlm-subscribed-list-update",
"message": "Hi {name:}!!<br></br><br></br>\r\n \r\nA new resource has been added to your list in the Enterprise Course Catalog (ECC): {list_name:} at {date_time:} by {author:}.<br></br>\r\n \r\nDive into the ECC and explore this latest addition to fuel your learning journey. 🌱<br></br>\r\n \r\nTo view your list, hop over to {list_url:}.<br></br><br></br>\r\n \r\nHappy learning!<br></br>\r\n \r\nThe EDLM Team",
"template_inputs": null
}
}
]
13 changes: 8 additions & 5 deletions app/configurations/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

from openlxp_notifications.models import email
from rest_framework.test import APITestCase

from configurations.models import XDSConfiguration
Expand All @@ -13,11 +14,14 @@ class TestSetUp(APITestCase):
def setUp(self):
"""Function to set up necessary data for testing"""

self.patcher = patch('users.models.email_verification')
self.mock_email_verification = self.patcher.start()
# self.patcher = patch('users.models.email_verification')
# self.mock_email_verification = self.patcher.start()

self.patcher_2 = patch('xds_api.serializers.send_log_email_with_msg')
self.mock_send_email = self.patcher_2.start()
self.patcher = patch('core.signals.trigger_update')
self.mock_send_email = self.patcher.start()

self.email_not = email(reference='Subscribed_list_update')
self.email_not.save()

# create user, save user, login using client
self.auth_email = "[email protected]"
Expand Down Expand Up @@ -103,5 +107,4 @@ def setUp(self):

def tearDown(self):
self.patcher.stop()
self.patcher_2.stop()
return super().tearDown()
5 changes: 2 additions & 3 deletions app/configurations/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from openlxp_authentication.models import SAMLConfiguration
from openlxp_authentication.serializers import SAMLConfigurationSerializer
from rest_framework.response import Response
from rest_framework.views import APIView
from social_django.utils import load_strategy

from openlxp_authentication.models import SAMLConfiguration
from openlxp_authentication.serializers import SAMLConfigurationSerializer

from .models import XDSConfiguration, XDSUIConfiguration
from .serializers import (XDSConfigurationSerializer,
XDSUIConfigurationSerializer)
Expand Down
34 changes: 34 additions & 0 deletions app/core/signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
import logging
from django.conf import settings
from django.db.models.signals import m2m_changed
from django.dispatch import receiver
from notifications.signals import notify
from openlxp_notifications.management.commands. \
trigger_subscribed_list_update import \
trigger_update
from openlxp_notifications.models import email

from .models import InterestList

logger = logging.getLogger('dict_config_logger')


@receiver(m2m_changed, sender=InterestList.experiences.through)
def interest_list_notify(sender, instance, action, reverse, pk_set, **kwargs):
if action == 'post_add' and not reverse:
notify.send(instance, recipient=instance.subscribers.all(),
verb='experiences added', added=pk_set,
list_name=instance.name)
# setting variables for email request

recipient_list = list(instance.subscribers.values_list(
"email", "first_name", 'last_name'))
owner = instance.owner
list_name = instance.name

if settings.LOGIN_REDIRECT_URL:
list_url = (settings.LOGIN_REDIRECT_URL + "/"
+ str(instance.id))
else:
list_url = "ECC -> Subscribed Lists: " + instance.name

try:
email_type = email.objects.get(
reference='Subscribed_list_update')

# trigger email notification
trigger_update(
email_type, recipient_list, owner,
list_name, list_url)
except email.DoesNotExist:
logger.error('Email configuration for subscribed list '
'updates does not exist. Please add a '
'"Subscribed_list_update" email template '
'for the email alert. ')
10 changes: 5 additions & 5 deletions app/core/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

from openlxp_notifications.models import email
from rest_framework.test import APITestCase


Expand All @@ -9,11 +10,11 @@ class TestSetUp(APITestCase):
def setUp(self):
"""Function to set up necessary data for testing"""

self.patcher = patch('users.models.email_verification')
self.mock_email_verification = self.patcher.start()
self.patcher = patch('core.signals.trigger_update')
self.mock_send_email = self.patcher.start()

self.patcher_2 = patch('xds_api.serializers.send_log_email_with_msg')
self.mock_send_email = self.patcher_2.start()
self.email_not = email(reference='Subscribed_list_update')
self.email_not.save()

self.email = "[email protected]"
self.password = "test1234"
Expand All @@ -39,5 +40,4 @@ def setUp(self):

def tearDown(self):
self.patcher.stop()
self.patcher_2.stop()
return super().tearDown()
5 changes: 4 additions & 1 deletion app/openlxp_xds_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': os.environ.get('DB_HOST'),
'PORT': 3306,
}
'OPTIONS': {
'charset': 'utf8mb4',
}
},
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
Expand Down
4 changes: 0 additions & 4 deletions app/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
from rest_framework import exceptions
from rest_framework.permissions import DjangoModelPermissions

from openlxp_notifications.management.utils.ses_client import \
email_verification


class Organization(TimeStampedModel):
"""Model to store an organization for filtering"""
Expand Down Expand Up @@ -91,7 +88,6 @@ def __str__(self):
return self.email

def save(self, *args, **kwargs):
email_verification(self.email)
return super(XDSUser, self).save(*args, **kwargs)


Expand Down
13 changes: 8 additions & 5 deletions app/users/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

from openlxp_notifications.models import email
from rest_framework.test import APITestCase

from configurations.models import XDSConfiguration
Expand All @@ -13,11 +14,14 @@ class TestSetUp(APITestCase):
def setUp(self):
"""Function to set up necessary data for testing"""

self.patcher = patch('users.models.email_verification')
self.mock_email_verification = self.patcher.start()
# self.patcher = patch('users.models.email_verification')
# self.mock_email_verification = self.patcher.start()

self.patcher_2 = patch('xds_api.serializers.send_log_email_with_msg')
self.mock_send_email = self.patcher_2.start()
self.patcher = patch('core.signals.trigger_update')
self.mock_send_email = self.patcher.start()

self.email_not = email(reference='Subscribed_list_update')
self.email_not.save()

# create user, save user, login using client
self.auth_email = "[email protected]"
Expand Down Expand Up @@ -103,5 +107,4 @@ def setUp(self):

def tearDown(self):
self.patcher.stop()
self.patcher_2.stop()
return super().tearDown()
5 changes: 1 addition & 4 deletions app/xds_api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging

from openlxp_notifications.management.commands.conformance_alerts import \
send_log_email_with_msg
from rest_framework import serializers

from configurations.models import CourseInformationMapping
Expand Down Expand Up @@ -107,14 +105,13 @@ def update(self, instance, validated_data):
instance.experiences.remove(exp)

# writing content to file
msg = ("Count of New Courses added: " + str(course_added_count))
# msg = ("Count of New Courses added: " + str(course_added_count))

list_subscribers = []
for each_subscriber in instance.subscribers.all():
list_subscribers.append(each_subscriber.email)

instance.save()
send_log_email_with_msg(list_subscribers, msg)
return instance


Expand Down
13 changes: 8 additions & 5 deletions app/xds_api/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

from openlxp_notifications.models import email
from rest_framework.test import APITestCase

from configurations.models import XDSConfiguration
Expand All @@ -13,11 +14,14 @@ class TestSetUp(APITestCase):
def setUp(self):
"""Function to set up necessary data for testing"""

self.patcher = patch('users.models.email_verification')
self.mock_email_verification = self.patcher.start()
# self.patcher = patch('users.models.email_verification')
# self.mock_email_verification = self.patcher.start()

self.patcher_2 = patch('xds_api.serializers.send_log_email_with_msg')
self.mock_send_email = self.patcher_2.start()
self.patcher = patch('core.signals.trigger_update')
self.mock_send_email = self.patcher.start()

self.email_not = email(reference='Subscribed_list_update')
self.email_not.save()

# create user, save user, login using client
self.auth_email = "[email protected]"
Expand Down Expand Up @@ -106,5 +110,4 @@ def setUp(self):

def tearDown(self):
self.patcher.stop()
self.patcher_2.stop()
return super().tearDown()
4 changes: 2 additions & 2 deletions app/xds_api/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import OrderedDict
import json
import logging
from collections import OrderedDict

import requests
from django.core.exceptions import ObjectDoesNotExist
Expand All @@ -9,9 +9,9 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from core.management.utils.xds_internal import bleach_data_to_json

from configurations.models import XDSConfiguration
from core.management.utils.xds_internal import bleach_data_to_json
from core.models import CourseSpotlight, Experience, InterestList, SavedFilter
from xds_api.serializers import InterestListSerializer, SavedFilterSerializer
from xds_api.utils.xds_utils import (get_request,
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
db:
image: mysql:5.7
image: mysql:8.4
ports:
- '3306:3306'
environment:
Expand Down Expand Up @@ -33,15 +33,16 @@ services:
AWS_ACCESS_KEY_ID: "${AWS_ACCESS_KEY_ID}"
AWS_SECRET_ACCESS_KEY: "${AWS_SECRET_ACCESS_KEY}"
AWS_DEFAULT_REGION: "${AWS_DEFAULT_REGION}"
REQUESTS_CA_BUNDLE: '/etc/ssl/certs/ca-certificates.pem'
AWS_CA_BUNDLE: '/etc/ssl/certs/ca-certificates.pem'
REQUESTS_CA_BUNDLE: '/etc/ssl/certs/ca-certificates.crt'
AWS_CA_BUNDLE: '/etc/ssl/certs/ca-certificates.crt'
SECRET_KEY_VAL: "${SECRET_KEY_VAL}"
LOG_PATH: "${LOG_PATH}"
ENTITY_ID: "${ENTITY_ID}"
SP_PUBLIC_CERT: "${SP_PUBLIC_CERT}"
SP_PRIVATE_KEY: "${SP_PRIVATE_KEY}"
BAD_HOST: "${BAD_HOST}"
OVERIDE_HOST: "${OVERIDE_HOST}"
LOGIN_REDIRECT_URL: "${LOGIN_REDIRECT_URL}"
volumes:
- ./app:/opt/app/openlxp-xds
depends_on:
Expand Down
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ boto3~=1.16.54

coverage>=5.5,<6.0

mysql-connector-python == 8.0.28

django-mysql==4.4.0

Django>=3.2.3,<4.0

django-admin-interface>=0.28.3
Expand All @@ -14,9 +18,11 @@ django-cors-headers>=3.7.0,<3.8.0

django-elasticsearch-dsl>=7.2.2,<7.3.0

django-model-utils>=4.1.1,<4.2.0
isort==5.11.5

django-mysql>=3.10.0,<3.11.0
martor>=1.5.8,<1.6.0

django-model-utils>=4.1.1,<4.2.0

django-notifications-hq>=1.8.3, <2.0

Expand All @@ -34,11 +40,9 @@ gunicorn>=22.0.0, <22.1.0

martor>=1.5.8,<1.6.0

mysql-connector-python>=8.4.0, <8.5.0

openlxp-authentication >=1.1.2, <1.2

openlxp-notification>=1.3.0
openlxp-notification>=1.4.0, <1.5.0

Pillow>=10.2.0

Expand Down
4 changes: 4 additions & 0 deletions start-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

python manage.py waitdb
python manage.py migrate
python manage.py createcachetable
python manage.py loaddata admin_theme_data.json
python manage.py loaddata openlxp_email_templates.json
python manage.py loaddata openlxp_email_subject.json
python manage.py loaddata openlxp_email.json
cd /opt/app/
pwd
./start-server.sh

0 comments on commit dc81c16

Please sign in to comment.