Ejemplo n.º 1
0
    def send_subscription_notification(email, token):

        hostname = 'https://status.amlight.net'
        view_path = '/subscriber'

        link = hostname + view_path + '/' + email + '/' + token

        # Email content
        text = f"""\
                                Link to modify your subscription:
                                {link}
                                """

        html = f"""\
                                <html>
                                  <body>
                                    <p>Link to modify your subscription<br>
                                    </p>
                                    <a href="{link}">Modify your subscription</a>
                                  </body>
                                </html>
                                """

        subject = "Modification requested on Subscription!"

        mail_sender = MailSender(html, subject, text, email)
        mail_sender.send_mail()
Ejemplo n.º 2
0
    def notify_subscription_to_user_email(email, services, subservices):

        service_list = ''
        service_list_html = ''

        subservice_list = ''
        subservice_list_html = ''

        if len(services):
            service_list += '<br>'
            service_list_html += '<ul>'
            for service in services:
                service_list += f"""{service}<br>"""
                service_list_html += f"""<li>{service}</li>"""
            service_list += '<br>'
            service_list_html += '</ul>'
        else:
            service_list += '<br>None selected<br>'
            service_list_html += '<ul><li>None selected</li></ul>'

        if len(subservices):
            subservice_list += '<br>'
            subservice_list_html += '<ul>'
            for subservice in subservices:
                subservice_list += f"""{subservice}<br>"""
                subservice_list_html += f"""<li>{subservice}</li>"""
            subservice_list += '<br'
            subservice_list_html += '</ul>'
        else:
            subservice_list += '<br>None selected<br>'
            subservice_list_html += '<ul><li>None selected</li></ul>'

        # Email content
        text = f"""\
            You have subscribed to receive notifications from the following services:
            <br>
            {service_list}
            You have subscribed to receive notifications from the following sub-services:
            {subservice_list}"""

        html = f"""\
        <html>
            <body>
                <p>You have subscribed to receive notifications from the following Service(s)</p>
                {service_list_html}
                <p>You have subscribed to receive notifications from the following Sub-service(s)</p>
                {subservice_list_html}
            </body>
        </html>"""

        subject = "Subscription requested!"

        mail_sender = MailSender(html, subject, text, email)
        mail_sender.send_mail()
Ejemplo n.º 3
0
    def send_link_by_user_email(_email):
        """
        Method to send a notification link given the User email
        :param _email:
        :return:
        """

        # It gets the user's token given its email
        user = Subscriber.objects.filter(email=_email).values('token')

        token = str(
            user[0]
            ['token'])  # Need to cast, otherwise it will have a nontype error

        # hostname = 'http://127.0.0.1:8000'
        hostname = 'http://service2.amlight.net'

        # we should create a mechanism to get the hostname. This option works on views request
        # print(HttpRequest.get_host(self))

        view_path = '/subscriber'  # email and toke

        link = hostname + view_path + '/' + _email + '/' + token

        # Email content
        text = f"""\
                            Link to modify your subscription:
                            {link}
                            """

        html = f"""\
                            <html>
                              <body>
                                <p>Link to modify your subscription<br>
                                </p>
                                {link}
                              </body>
                            </html>
                            """

        subject = "Modification requested on Subscription!"

        mail_sender = MailSender(html, subject, text, _email)
        mail_sender.send_mail()
Ejemplo n.º 4
0
    def send_link_by_user_id(user_id):
        """
        Method to send a notification link given the User ID
        :param user_id:
        :return:
        """

        # It gets the user's email and token given its ID
        user = Subscriber.objects.filter(pk=user_id).values('email', 'token')

        email = user[0]['email']
        token = user[0]['token']

        # hostname = 'http://127.0.0.1:8000'
        hostname = 'http://service2.amlight.net'

        # we should create a mechanism to get the hostname. This option works on views request
        # print(HttpRequest.get_host(self))

        view_path = '/subscriber'

        link = hostname + view_path + '/' + email + '/' + token

        # Email content
        text = f"""\
                        Link to modify your subscription:
                        {link}
                        """

        html = f"""\
                        <html>
                          <body>
                            <p>Link to modify your subscription<br>
                            </p>
                            {link}
                          </body>
                        </html>
                        """

        subject = "Modification requested on Subscription!"

        mail_sender = MailSender(html, subject, text, email)
        mail_sender.send_mail()
Ejemplo n.º 5
0
    def ticket_notification(sub_service_id, changed_data, cleaned_data, cleaned_data_ext=None):
        """
        Method in charge to control the ticket notification process
        :param sub_service_id:
        :param changed_data:
        :param cleaned_data:
        :param cleaned_data_ext: It will get all the data related to the ticket logs
        :return:
        """

        # It gets all the users who belong to that Sub Service

        # It gets the list of services that has that Sub Service
        services = Service.objects.filter(topology__subservices=sub_service_id)
        subservices = SubService.objects.filter(id=sub_service_id)

        # Information to use in the email Body
        region = Region.objects.filter(
            client_domains__services__topology__subservices__in=subservices
        )
        topology = Topology.objects.filter(subservices__in=subservices)

        _changed_data = changed_data

        users_mail1 = list()
        users_mail2 = list()

        if services.count() != 0:
            # It gets the list of Key ID ot those services
            users_mail1 = Subscriber.objects.filter(services__in=services)

            # Remove duplicates
            users_mail1 = list(dict.fromkeys(users_mail1))

        if subservices.count() != 0:
            users_mail2 = Subscriber.objects.filter(subservices__in=subservices)

            # Remove duplicates
            users_mail2 = list(dict.fromkeys(users_mail2))

        users = list(set(users_mail1) | set(users_mail2))

        data = dict()
        data['ticket_id'] = cleaned_data.get('ticket_id')
        data['region'] = 'None'
        if region.count() != 0:
            data['region'] = region[0].name
        data['priority'] = 'None'
        if topology.count() != 0:
            data['priority'] = topology[0].priority
        data['service'] = None
        if services.count() != 0:
            data['service'] = services[0].name
        data['subservice'] = 'None'
        if subservices.count() != 0:
            data['subservice'] = subservices[0].name

        for user in users:
            text = f"""\
                            Changes on the ticket {data['ticket_id']}:
                            Region: {data['region']}
                            Priority: {data['priority']}
                            Service: {data['service']}
                            Sub-Service: {data['subservice']}
                            """

            html = f"""\
                            <html>
                              <body>
                                <p>Changes on the ticket 
                                    <span style="font-weight: bold;">{data['ticket_id']}</span>:
                                    <br>
                                    <ul>
                                        <li>
                                            <span style="font-weight: bold;">Region:</span> {data['region']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Priority:</span> {data['priority']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Service:</span> {data['service']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Sub-Service:</span> {data['subservice']}
                                        </li>
                                    </ul>
                                </p>
                              </body>
                            </html>
                            """

            subject = "Changes detected!"

            mail_sender = MailSender(html, subject, text, user.email)
            mail_sender.send_mail()
Ejemplo n.º 6
0
    def notify_user(self, sub_service_id):
        # It gets all the users who belong to that Sub Service

        # It gets the list of services that has that Sub Service
        services = Service.objects.filter(subservice=sub_service_id)
        subservices = SubService.objects.filter(id=sub_service_id)

        # Information to use in the email Body
        region = Region.objects.filter(services__subservice__in=subservices)
        topology = SubServiceServices.objects.filter(
            subservice__in=subservices)

        changed_data = self.changed_data
        # print(self.cleaned_data)

        users_mail1 = []
        users_mail2 = []

        if services.count() != 0:
            # It gets the list of Key ID ot those services
            users_mail1 = Subscriber.objects.filter(services__in=services)

            # Remove duplicates
            users_mail1 = list(dict.fromkeys(users_mail1))

        if subservices.count() != 0:
            users_mail2 = Subscriber.objects.filter(
                subservices__in=subservices)

            # Remove duplicates
            users_mail2 = list(dict.fromkeys(users_mail2))

        users = list(set(users_mail1) | set(users_mail2))

        data = dict()
        data['ticket_id'] = self.cleaned_data['ticket_id']
        data['region'] = 'None'
        if region.count() != 0:
            data['region'] = region[0].region_name
        data['priority'] = 'None'
        if topology.count() != 0:
            data['priority'] = topology[0].priority
        data['service'] = services[0].service_name
        if services.count() != 0:
            data['service'] = services[0].service_name
        data['subservice'] = 'None'
        if subservices.count() != 0:
            data['subservice'] = subservices[0].sub_service_name

        for user in users:
            text = f"""\
                            Changes on the ticket {data['ticket_id']}:
                            Region: {data['region']}
                            Priority: {data['priority']}
                            Service: {data['service']}
                            Sub-Service: {data['subservice']}
                            """

            html = f"""\
                            <html>
                              <body>
                                <p>Changes on the ticket 
                                    <span style="font-weight: bold;">{data['ticket_id']}</span>:
                                    <br>
                                    <ul>
                                        <li>
                                            <span style="font-weight: bold;">Region:</span> {data['region']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Priority:</span> {data['priority']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Service:</span> {data['service']}
                                        </li>
                                        <li>
                                            <span style="font-weight: bold;">Sub-Service:</span> {data['subservice']}
                                        </li>
                                    </ul>
                                </p>
                              </body>
                            </html>
                            """

            subject = "Changes detected!"

            mail_sender = MailSender(html, subject, text, user.email)
            mail_sender.send_mail()
Ejemplo n.º 7
0
    def notify_user_email(self):
        """
        Method to send a mail notification
        about the subscription requested
        """
        email = self.cleaned_data["email"]

        service_list = ''
        service_list_html = ''

        subservice_list = ''
        subservice_list_html = ''

        services = self.cleaned_data["services"]
        subservices = self.cleaned_data["subservices"]

        if len(services):
            service_list += '<br>'
            service_list_html += '<ul>'
            for service in services:
                service_list += f"""{service}<br>"""
                service_list_html += f"""<li>{service}</li>"""
            service_list += '<br>'
            service_list_html += '</ul>'
        else:
            service_list += '<br>None selected<br>'
            service_list_html += '<ul><li>None selected</li></ul>'

        if len(subservices):
            subservice_list += '<br>'
            subservice_list_html += '<ul>'
            for subservice in subservices:
                subservice_list += f"""{subservice}<br>"""
                subservice_list_html += f"""<li>{subservice}</li>"""
            subservice_list += '<br'
            subservice_list_html += '</ul>'
        else:
            subservice_list += '<br>None selected<br>'
            subservice_list_html += '<ul><li>None selected</li></ul>'

        # Email content
        text = f"""\
                                You have subscribed to receive notifications from the following services:
                                <br>
                                {service_list}
                                You have subscribed to receive notifications from the following sub-services:
                                {subservice_list}
                                """

        html = f"""\
                                <html>
                                  <body>
                                    <p>You have subscribed to receive notifications from the following Service(s)
                                    <br>
                                    </p>
                                    {service_list_html}
                                    <p>You have subscribed to receive notifications from the following Sub-service(s)
                                    <br>
                                    </p>
                                    {subservice_list_html}
                                  </body>
                                </html>
                                """

        subject = "Subscription requested!"

        mail_sender = MailSender(html, subject, text, email)
        mail_sender.send_mail()