コード例 #1
0
def load_project_dump(user, dump):
    try:
        project = services.store_project_from_dict(dump, user)
    except err.TaigaImportError as e:
        # On Error
        ## remove project
        if e.project:
            e.project.delete_related_content()
            e.project.delete()

        ## send email to the user
        error_subject = _("Error loading project dump")
        error_message = e.message or _("Error loading your project dump file")

        ctx = {
            "user": user,
            "error_subject": error_message,
            "error_message": error_subject,
        }
        email = mail_builder.import_error(user, ctx)
        email.send()

        ## logged the error to sysadmins
        text = ADMIN_ERROR_LOAD_PROJECT_DUMP_MESSAGE.format(
            user_full_name=user,
            user_email=user.email,
            reason=e.message or _("  -- no detail info --"),
            details=json.dumps(e.errors, indent=4))
        logger.error(text, exc_info=sys.exc_info())

    else:
        # On Success
        ctx = {"user": user, "project": project}
        email = mail_builder.load_dump(user, ctx)
        email.send()
コード例 #2
0
ファイル: tasks.py プロジェクト: charlesqichen/taiga-back
def load_project_dump(user, dump):
    try:
        project = services.store_project_from_dict(dump, user)
    except err.TaigaImportError as e:
        # On Error
        ## remove project
        if e.project:
            e.project.delete_related_content()
            e.project.delete()

        ## send email to the user
        error_subject = _("Error loading project dump")
        error_message = e.message or _("Error loading your project dump file")

        ctx = {"user": user, "error_subject": error_message, "error_message": error_subject}
        email = mail_builder.import_error(user, ctx)
        email.send()

        ## logged the error to sysadmins
        text = ADMIN_ERROR_LOAD_PROJECT_DUMP_MESSAGE.format(
            user_full_name=user,
            user_email=user.email,
            reason=e.message or _("  -- no detail info --"),
            details=json.dumps(e.errors, indent=4),
        )
        logger.error(text, exc_info=sys.exc_info())

    else:
        # On Success
        ctx = {"user": user, "project": project}
        email = mail_builder.load_dump(user, ctx)
        email.send()
コード例 #3
0
ファイル: tasks.py プロジェクト: spetpet/taiga-back
def load_project_dump(user, dump):
    try:
        project = dict_to_project(dump, user.email)
    except Exception:
        ctx = {
            "user": user,
            "error_subject": _("Error loading project dump"),
            "error_message": _("Error loading project dump"),
        }
        email = mail_builder.import_error(user, ctx)
        email.send()
        logger.error("Error loading dump %s (by %s)", project.slug, user, exc_info=sys.exc_info())
        return

    ctx = {"user": user, "project": project}
    email = mail_builder.load_dump(user, ctx)
    email.send()
コード例 #4
0
def load_project_dump(user, dump):
    try:
        project = dict_to_project(dump, user)
    except Exception:
        ctx = {
            "user": user,
            "error_subject": _("Error loading project dump"),
            "error_message": _("Error loading project dump"),
        }
        email = mail_builder.import_error(user, ctx)
        email.send()
        logger.error('Error loading dump %s (by %s)',
                     project.slug,
                     user,
                     exc_info=sys.exc_info())
        return

    ctx = {"user": user, "project": project}
    email = mail_builder.load_dump(user, ctx)
    email.send()
コード例 #5
0
def load_project_dump(user, dump):
    try:
        project = dict_to_project(dump, user)
    except Exception:
        # Error
        ctx = {
            "user": user,
            "error_subject": _("Error loading project dump"),
            "error_message": _("Error loading project dump"),
        }
        email = mail_builder.import_error(user, ctx)
        email.send()
        logger.error('Error loading dump by %s <%s>',
                     user,
                     user.email,
                     exc_info=sys.exc_info())

        # TODO: [Rollback] Remove project because it can be corrupted

    else:
        # Success
        ctx = {"user": user, "project": project}
        email = mail_builder.load_dump(user, ctx)
        email.send()
コード例 #6
0
ファイル: tasks.py プロジェクト: Rademade/taiga-back
def load_project_dump(user, dump):
    try:
        project = dict_to_project(dump, user)
    except Exception:
        # Error
        ctx = {
            "user": user,
            "error_subject": _("Error loading project dump"),
            "error_message": _("Error loading project dump"),
        }
        email = mail_builder.import_error(user, ctx)
        email.send()
        logger.error('Error loading dump by %s <%s>',
                     user,
                     user.email,
                     exc_info=sys.exc_info())

        # TODO: [Rollback] Remove project because it can be corrupted

    else:
        # Success
        ctx = {"user": user, "project": project}
        email = mail_builder.load_dump(user, ctx)
        email.send()
コード例 #7
0
ファイル: test_emails.py プロジェクト: krp/taiga-back
    def handle(self, *args, **options):
        if len(args) != 1:
            print("Usage: ./manage.py test_emails <email-address>")
            return

        locale = options.get('locale')
        test_email = args[0]

        # Register email
        context = {"lang": locale,
                    "user": User.objects.all().order_by("?").first(),
                    "cancel_token": "cancel-token"}

        email = mail_builder.registered_user(test_email, context)
        email.send()

        # Membership invitation
        membership = Membership.objects.order_by("?").filter(user__isnull=True).first()
        membership.invited_by = User.objects.all().order_by("?").first()
        membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example"

        context = {"lang": locale, "membership": membership}
        email = mail_builder.membership_invitation(test_email, context)
        email.send()

        # Membership notification
        context = {"lang": locale,
                   "membership": Membership.objects.order_by("?").filter(user__isnull=False).first()}
        email = mail_builder.membership_notification(test_email, context)
        email.send()

        # Feedback
        context = {
            "lang": locale,
            "feedback_entry": {
                "full_name": "Test full name",
                "email": "*****@*****.**",
                "comment": "Test comment",
            },
            "extra": {
                "key1": "value1",
                "key2": "value2",
            },
        }
        email = mail_builder.feedback_notification(test_email, context)
        email.send()

        # Password recovery
        context = {"lang": locale, "user": User.objects.all().order_by("?").first()}
        email = mail_builder.password_recovery(test_email, context)
        email.send()

        # Change email
        context = {"lang": locale, "user": User.objects.all().order_by("?").first()}
        email = mail_builder.change_email(test_email, context)
        email.send()

        # Export/Import emails
        context = {
            "lang": locale,
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "error_subject": "Error generating project dump",
            "error_message": "Error generating project dump",
        }
        email = mail_builder.export_error(test_email, context)
        email.send()
        context = {
            "lang": locale,
            "user": User.objects.all().order_by("?").first(),
            "error_subject": "Error importing project dump",
            "error_message": "Error importing project dump",
        }
        email = mail_builder.import_error(test_email, context)
        email.send()

        deletion_date = timezone.now() + datetime.timedelta(seconds=60*60*24)
        context = {
            "lang": locale,
            "url": "http://dummyurl.com",
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "deletion_date": deletion_date,
        }
        email = mail_builder.dump_project(test_email, context)
        email.send()

        context = {
            "lang": locale,
            "user": User.objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
        }
        email = mail_builder.load_dump(test_email, context)
        email.send()

        # Notification emails
        notification_emails = [
            ("issues.Issue", "issues/issue-change"),
            ("issues.Issue", "issues/issue-create"),
            ("issues.Issue", "issues/issue-delete"),
            ("tasks.Task", "tasks/task-change"),
            ("tasks.Task", "tasks/task-create"),
            ("tasks.Task", "tasks/task-delete"),
            ("userstories.UserStory", "userstories/userstory-change"),
            ("userstories.UserStory", "userstories/userstory-create"),
            ("userstories.UserStory", "userstories/userstory-delete"),
            ("milestones.Milestone", "milestones/milestone-change"),
            ("milestones.Milestone", "milestones/milestone-create"),
            ("milestones.Milestone", "milestones/milestone-delete"),
            ("wiki.WikiPage", "wiki/wikipage-change"),
            ("wiki.WikiPage", "wiki/wikipage-create"),
            ("wiki.WikiPage", "wiki/wikipage-delete"),
        ]

        context = {
            "lang": locale,
            "project": Project.objects.all().order_by("?").first(),
            "changer": User.objects.all().order_by("?").first(),
            "history_entries": HistoryEntry.objects.all().order_by("?")[0:5],
            "user": User.objects.all().order_by("?").first(),
        }

        for notification_email in notification_emails:
            model = get_model(*notification_email[0].split("."))
            snapshot = {
                "subject": "Tests subject",
                "ref": 123123,
                "name": "Tests name",
                "slug": "test-slug"
            }
            queryset = model.objects.all().order_by("?")
            for obj in queryset:
                end = False
                entries = get_history_queryset_by_model_instance(obj).filter(is_snapshot=True).order_by("?")

                for entry in entries:
                    if entry.snapshot:
                        snapshot = entry.snapshot
                        end = True
                        break
                if end:
                    break
            context["snapshot"] = snapshot

            cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail,), {"name": notification_email[1]})
            email = cls()
            email.send(test_email, context)
コード例 #8
0
    def handle(self, *args, **options):
        locale = options.get('locale')
        email_address = options.get('email')

        # Register email
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "cancel_token": "cancel-token"
        }

        email = mail_builder.registered_user(email_address, context)
        email.send()

        # Membership invitation
        membership = Membership.objects.order_by("?").filter(
            user__isnull=True).first()
        membership.invited_by = get_user_model().objects.all().order_by(
            "?").first()
        membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example"

        context = {"lang": locale, "membership": membership}
        email = mail_builder.membership_invitation(email_address, context)
        email.send()

        # Membership notification
        context = {
            "lang":
            locale,
            "membership":
            Membership.objects.order_by("?").filter(
                user__isnull=False).first()
        }
        email = mail_builder.membership_notification(email_address, context)
        email.send()

        # Feedback
        context = {
            "lang": locale,
            "feedback_entry": {
                "full_name": "Test full name",
                "email": "*****@*****.**",
                "comment": "Test comment",
            },
            "extra": {
                "key1": "value1",
                "key2": "value2",
            },
        }
        email = mail_builder.feedback_notification(email_address, context)
        email.send()

        # Password recovery
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.password_recovery(email_address, context)
        email.send()

        # Change email
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.change_email(email_address, context)
        email.send()

        # Export/Import emails
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "error_subject": "Error generating project dump",
            "error_message": "Error generating project dump",
        }
        email = mail_builder.export_error(email_address, context)
        email.send()
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "error_subject": "Error importing project dump",
            "error_message": "Error importing project dump",
        }
        email = mail_builder.import_error(email_address, context)
        email.send()

        deletion_date = timezone.now() + datetime.timedelta(seconds=60 * 60 *
                                                            24)
        context = {
            "lang": locale,
            "url": "http://dummyurl.com",
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "deletion_date": deletion_date,
        }
        email = mail_builder.dump_project(email_address, context)
        email.send()

        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
        }
        email = mail_builder.load_dump(email_address, context)
        email.send()

        # Notification emails
        notification_emails = [
            ("issues.Issue", "issues/issue-change"),
            ("issues.Issue", "issues/issue-create"),
            ("issues.Issue", "issues/issue-delete"),
            ("tasks.Task", "tasks/task-change"),
            ("tasks.Task", "tasks/task-create"),
            ("tasks.Task", "tasks/task-delete"),
            ("userstories.UserStory", "userstories/userstory-change"),
            ("userstories.UserStory", "userstories/userstory-create"),
            ("userstories.UserStory", "userstories/userstory-delete"),
            ("milestones.Milestone", "milestones/milestone-change"),
            ("milestones.Milestone", "milestones/milestone-create"),
            ("milestones.Milestone", "milestones/milestone-delete"),
            ("wiki.WikiPage", "wiki/wikipage-change"),
            ("wiki.WikiPage", "wiki/wikipage-create"),
            ("wiki.WikiPage", "wiki/wikipage-delete"),
        ]

        context = {
            "lang": locale,
            "project": Project.objects.all().order_by("?").first(),
            "changer": get_user_model().objects.all().order_by("?").first(),
            "history_entries": HistoryEntry.objects.all().order_by("?")[0:5],
            "user": get_user_model().objects.all().order_by("?").first(),
        }

        for notification_email in notification_emails:
            model = apps.get_model(*notification_email[0].split("."))
            snapshot = {
                "subject": "Tests subject",
                "ref": 123123,
                "name": "Tests name",
                "slug": "test-slug"
            }
            queryset = model.objects.all().order_by("?")
            for obj in queryset:
                end = False
                entries = get_history_queryset_by_model_instance(obj).filter(
                    is_snapshot=True).order_by("?")

                for entry in entries:
                    if entry.snapshot:
                        snapshot = entry.snapshot
                        end = True
                        break
                if end:
                    break
            context["snapshot"] = snapshot

            cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail, ),
                       {"name": notification_email[1]})
            email = cls()
            email.send(email_address, context)

        # Transfer Emails
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "requester": get_user_model().objects.all().order_by("?").first(),
        }
        email = mail_builder.transfer_request(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "receiver": get_user_model().objects.all().order_by("?").first(),
            "token": "test-token",
            "reason": "Test reason"
        }
        email = mail_builder.transfer_start(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "old_owner": get_user_model().objects.all().order_by("?").first(),
            "new_owner": get_user_model().objects.all().order_by("?").first(),
            "reason": "Test reason"
        }
        email = mail_builder.transfer_accept(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "rejecter": get_user_model().objects.all().order_by("?").first(),
            "reason": "Test reason"
        }
        email = mail_builder.transfer_reject(email_address, context)
        email.send()

        # Contact with project admins email
        project = Project.objects.all().order_by("?").first()
        user = get_user_model().objects.all().order_by("?").first()
        context = {
            "full_name":
            user.get_full_name(),
            "project_name":
            project.name,
            "photo_url":
            get_user_photo_url(user),
            "user_profile_url":
            resolve_front_url("user", user.username),
            "project_settings_url":
            resolve_front_url("project-admin", project.slug),
            "comment":
            "Test comment notification."
        }
        email = mail_builder.contact_notification(email_address, context)
        email.send()

        # GitHub importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.github_import_success(email_address, context)
        email.send()

        # Jira importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.jira_import_success(email_address, context)
        email.send()

        # Trello importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.trello_import_success(email_address, context)
        email.send()

        # Asana importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.asana_import_success(email_address, context)
        email.send()

        # Error importer email
        context = {
            "user": get_user_model().objects.all().order_by("?").first(),
            "error_subject": "Error importing GitHub project",
            "error_message": "Error importing GitHub project",
            "project": 1234,
            "exception": "Exception message"
        }
        email = mail_builder.importer_import_error(email_address, context)
        email.send()
コード例 #9
0
ファイル: test_emails.py プロジェクト: shreeshreee/taiga-back
    def handle(self, *args, **options):
        locale = options.get('locale')
        email_address = options.get('email')

        # Register email
        context = {"lang": locale,
                    "user": get_user_model().objects.all().order_by("?").first(),
                    "cancel_token": "cancel-token"}

        email = mail_builder.registered_user(email_address, context)
        email.send()

        # Membership invitation
        membership = Membership.objects.order_by("?").filter(user__isnull=True).first()
        membership.invited_by = get_user_model().objects.all().order_by("?").first()
        membership.invitation_extra_text = "Text example, Text example,\nText example,\n\nText example"

        context = {"lang": locale, "membership": membership}
        email = mail_builder.membership_invitation(email_address, context)
        email.send()

        # Membership notification
        context = {"lang": locale,
                   "membership": Membership.objects.order_by("?").filter(user__isnull=False).first()}
        email = mail_builder.membership_notification(email_address, context)
        email.send()

        # Feedback
        context = {
            "lang": locale,
            "feedback_entry": {
                "full_name": "Test full name",
                "email": "*****@*****.**",
                "comment": "Test comment",
            },
            "extra": {
                "key1": "value1",
                "key2": "value2",
            },
        }
        email = mail_builder.feedback_notification(email_address, context)
        email.send()

        # Password recovery
        context = {"lang": locale, "user": get_user_model().objects.all().order_by("?").first()}
        email = mail_builder.password_recovery(email_address, context)
        email.send()

        # Change email
        context = {"lang": locale, "user": get_user_model().objects.all().order_by("?").first()}
        email = mail_builder.change_email(email_address, context)
        email.send()

        # Export/Import emails
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "error_subject": "Error generating project dump",
            "error_message": "Error generating project dump",
        }
        email = mail_builder.export_error(email_address, context)
        email.send()
        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "error_subject": "Error importing project dump",
            "error_message": "Error importing project dump",
        }
        email = mail_builder.import_error(email_address, context)
        email.send()

        deletion_date = timezone.now() + datetime.timedelta(seconds=60*60*24)
        context = {
            "lang": locale,
            "url": "http://dummyurl.com",
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
            "deletion_date": deletion_date,
        }
        email = mail_builder.dump_project(email_address, context)
        email.send()

        context = {
            "lang": locale,
            "user": get_user_model().objects.all().order_by("?").first(),
            "project": Project.objects.all().order_by("?").first(),
        }
        email = mail_builder.load_dump(email_address, context)
        email.send()

        # Notification emails
        notification_emails = [
            ("issues.Issue", "issues/issue-change"),
            ("issues.Issue", "issues/issue-create"),
            ("issues.Issue", "issues/issue-delete"),
            ("tasks.Task", "tasks/task-change"),
            ("tasks.Task", "tasks/task-create"),
            ("tasks.Task", "tasks/task-delete"),
            ("userstories.UserStory", "userstories/userstory-change"),
            ("userstories.UserStory", "userstories/userstory-create"),
            ("userstories.UserStory", "userstories/userstory-delete"),
            ("milestones.Milestone", "milestones/milestone-change"),
            ("milestones.Milestone", "milestones/milestone-create"),
            ("milestones.Milestone", "milestones/milestone-delete"),
            ("wiki.WikiPage", "wiki/wikipage-change"),
            ("wiki.WikiPage", "wiki/wikipage-create"),
            ("wiki.WikiPage", "wiki/wikipage-delete"),
        ]

        context = {
            "lang": locale,
            "project": Project.objects.all().order_by("?").first(),
            "changer": get_user_model().objects.all().order_by("?").first(),
            "history_entries": HistoryEntry.objects.all().order_by("?")[0:5],
            "user": get_user_model().objects.all().order_by("?").first(),
        }

        for notification_email in notification_emails:
            model = apps.get_model(*notification_email[0].split("."))
            snapshot = {
                "subject": "Tests subject",
                "ref": 123123,
                "name": "Tests name",
                "slug": "test-slug"
            }
            queryset = model.objects.all().order_by("?")
            for obj in queryset:
                end = False
                entries = get_history_queryset_by_model_instance(obj).filter(is_snapshot=True).order_by("?")

                for entry in entries:
                    if entry.snapshot:
                        snapshot = entry.snapshot
                        end = True
                        break
                if end:
                    break
            context["snapshot"] = snapshot

            cls = type("InlineCSSTemplateMail", (InlineCSSTemplateMail,), {"name": notification_email[1]})
            email = cls()
            email.send(email_address, context)

        # Transfer Emails
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "requester": get_user_model().objects.all().order_by("?").first(),
        }
        email = mail_builder.transfer_request(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "receiver": get_user_model().objects.all().order_by("?").first(),
            "token": "test-token",
            "reason": "Test reason"
        }
        email = mail_builder.transfer_start(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "old_owner": get_user_model().objects.all().order_by("?").first(),
            "new_owner": get_user_model().objects.all().order_by("?").first(),
            "reason": "Test reason"
        }
        email = mail_builder.transfer_accept(email_address, context)
        email.send()

        context = {
            "project": Project.objects.all().order_by("?").first(),
            "rejecter": get_user_model().objects.all().order_by("?").first(),
            "reason": "Test reason"
        }
        email = mail_builder.transfer_reject(email_address, context)
        email.send()


        # Contact with project admins email
        project = Project.objects.all().order_by("?").first()
        user = get_user_model().objects.all().order_by("?").first()
        context = {
            "full_name": user.get_full_name(),
            "project_name": project.name,
            "photo_url": get_user_photo_url(user),
            "user_profile_url": resolve_front_url("user", user.username),
            "project_settings_url": resolve_front_url("project-admin", project.slug),
            "comment": "Test comment notification."
        }
        email = mail_builder.contact_notification(email_address, context)
        email.send()

        # GitHub importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.github_import_success(email_address, context)
        email.send()

        # Jira importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.jira_import_success(email_address, context)
        email.send()

        # Trello importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.trello_import_success(email_address, context)
        email.send()

        # Asana importer email
        context = {
            "project": Project.objects.all().order_by("?").first(),
            "user": get_user_model().objects.all().order_by("?").first()
        }
        email = mail_builder.asana_import_success(email_address, context)
        email.send()

        # Error importer email
        context = {
            "user": get_user_model().objects.all().order_by("?").first(),
            "error_subject": "Error importing GitHub project",
            "error_message": "Error importing GitHub project",
            "project": 1234,
            "exception": "Exception message"
        }
        email = mail_builder.importer_import_error(email_address, context)
        email.send()