コード例 #1
0
    def send_notification(self,
                          filename,
                          recipient,
                          errors=None,
                          failed=False):
        """Send mail notification with information about errors."""
        data = {}
        if failed:
            data["title"] = self.ERROR_TITLE.format(filename=filename)
            data["email_text"] = self.EXCEPTION_TEXT
            body = settings.EMAIL_BULK_SYNC_EXCEPTION.render(sync_data=data)
        elif errors:
            data["objects"] = [{
                "url": get_object_url(obj),
                "code": obj.slug,
                "title": obj.title,
            } for (obj, _) in errors]
            data["title"] = self.ERROR_TITLE.format(filename=filename)
            data["email_text"] = self.ERROR_TEXT.format(filename=filename)
            body = settings.EMAIL_BULK_SYNC_FAILED.render(sync_data=data)
        else:
            data["title"] = self.SUCCESS_TITLE.format(filename=filename)
            data["email_text"] = self.SUCCESS_TEXT.format(filename=filename)
            body = settings.EMAIL_BULK_SYNC_SUCCEEDED.render(sync_data=data)

        common.send_email(recipient, self.ISSUETRACKER_SYNC_TITLE, body)
コード例 #2
0
  def send_notification(self,
                        parent_type,
                        parent_id,
                        errors=None,
                        failed=False):
    """Send mail notification with information about errors."""
    parent_model = models.get_model(parent_type)
    parent = parent_model.query.get(parent_id)

    data = {"title": parent.title}
    if failed:
      body = settings.EMAIL_BULK_CHILD_SYNC_EXCEPTION.render()
    elif errors:
      data["assessments"] = [
          {
              "url": get_object_url(obj),
              "code": obj.slug,
              "title": obj.title,
          } for (obj, _) in errors
      ]
      body = settings.EMAIL_BULK_CHILD_SYNC_FAILED.render(sync_data=data)
    else:
      body = settings.EMAIL_BULK_CHILD_SYNC_SUCCEEDED.render(sync_data=data)

    receiver = login.get_current_user()
    common.send_email(receiver.email, self.ISSUETRACKER_SYNC_TITLE, body)
コード例 #3
0
def send_error_notification(message):
  """Send error notification to APPENGINE_EMAIL user."""
  try:
    user_email = common.get_app_engine_email()
    common.send_email(user_email, "Error in nightly cron job", message)
  except:  # pylint: disable=bare-except
    logger.exception("Failed on sending notification")
コード例 #4
0
ファイル: cron.py プロジェクト: google/ggrc-core
def send_error_notification(message):
  """Send error notification to APPENGINE_EMAIL user."""
  try:
    user_email = common.get_app_engine_email()
    common.send_email(user_email, "Error in nightly cron job", message)
  except:  # pylint: disable=bare-except
    logger.exception("Failed on sending notification")
コード例 #5
0
def send_notification(update_errors, partial_errors, asmnt_ids):
  """Send bulk complete job finished."""

  not_updated_asmnts = []
  if update_errors:
    not_updated_asmnts = db.session.query(all_models.Assessment).filter(
        all_models.Assessment.slug.in_(update_errors)
    ).all()

  partially_upd_asmnts = []
  if partial_errors:
    partially_upd_asmnts = db.session.query(all_models.Assessment).filter(
        all_models.Assessment.slug.in_(partial_errors)
    ).all()

  not_updated_ids = set(asmnt.id for asmnt in not_updated_asmnts)
  partially_upd_ids = set(asmnt.id for asmnt in partially_upd_asmnts)
  success_ids = set(asmnt_ids) - not_updated_ids - partially_upd_ids

  success_asmnts = []
  if success_ids:
    success_asmnts = db.session.query(all_models.Assessment).filter(
        all_models.Assessment.id.in_(success_ids)
    ).all()

  bulk_data = {
      "update_errors": _create_notif_data(not_updated_asmnts),
      "partial_errors": _create_notif_data(partially_upd_asmnts),
      "succeeded": _create_notif_data(success_asmnts),
  }
  body = settings.EMAIL_BULK_COMPLETE.render(sync_data=bulk_data)
  common.send_email(login.get_current_user().email, BULK_UPDATE_TITLE, body)
コード例 #6
0
  def send_notification(self,
                        parent_type,
                        parent_id,
                        errors=None,
                        failed=False):
    """Send mail notification with information about errors."""
    parent_model = models.get_model(parent_type)
    parent = parent_model.query.get(parent_id)

    data = {"title": parent.title}
    if failed:
      body = settings.EMAIL_BULK_CHILD_SYNC_EXCEPTION.render()
    elif errors:
      data["assessments"] = [
          {
              "url": get_object_url(obj),
              "code": obj.slug,
              "title": obj.title,
          } for (obj, _) in errors
      ]
      body = settings.EMAIL_BULK_CHILD_SYNC_FAILED.render(sync_data=data)
    else:
      body = settings.EMAIL_BULK_CHILD_SYNC_SUCCEEDED.render(sync_data=data)

    receiver = login.get_current_user()
    common.send_email(receiver.email, self.ISSUETRACKER_SYNC_TITLE, body)
コード例 #7
0
def send_email(template, user_email, url_root, filename=""):
  """ Send email """
  subject = template["title"].format(filename=filename)
  data = {
      "body": template["body"],
      "url": urljoin(url_root, template["url"]),
      "title": subject
  }
  body = settings.EMAIL_IMPORT_EXPORT.render(import_export=data)
  common.send_email(user_email, subject, body)
コード例 #8
0
ファイル: job_emails.py プロジェクト: vjsavo4324/ggrc-core
def send_email(template, send_to, filename="", ie_id=None):
    """ Send email """
    subject = template["title"].format(filename=filename)

    url = urljoin(utils.get_url_root(), template["url"])
    if ie_id is not None:
        url = "{}#!&job_id={}".format(url, str(ie_id))

    data = {"body": template["body"], "url": url, "title": subject}
    body = settings.EMAIL_IMPORT_EXPORT.render(import_export=data)
    common.send_email(send_to, subject, body)
コード例 #9
0
ファイル: test_common.py プロジェクト: weizai118/ggrc-core
  def test_send_mail_no_raises(self):
    """Test check if send mail"""

    user_email = "*****@*****.**"
    subject = "Test subject"
    body = "Test body"

    try:
      common.send_email(user_email, subject, body)
    except AssertionError as error:
      self.fail(error)
コード例 #10
0
ファイル: job_emails.py プロジェクト: google/ggrc-core
def send_email(template, send_to, filename="", ie_id=None):
  """ Send email """
  subject = template["title"].format(filename=filename)

  url = urljoin(utils.get_url_root(), template["url"])
  if ie_id is not None:
    url = "{}#!&job_id={}".format(url, str(ie_id))

  data = {
      "body": template["body"],
      "url": url,
      "title": subject
  }
  body = settings.EMAIL_IMPORT_EXPORT.render(import_export=data)
  common.send_email(send_to, subject, body)
コード例 #11
0
def send_notification():
    """Send notifications about proposals."""
    proposals = proposal_helpers.get_email_proposal_list()
    review_notifications = review_helpers.get_review_notifications()
    subject = build_subject()
    for addressee, html in build_address_body(proposals, review_notifications):
        notif_common.send_email(
            user_email=addressee.email,
            subject=subject,
            body=html,
        )

    proposal_helpers.mark_proposals_sent(proposals)
    review_helpers.move_notifications_to_history(review_notifications)
    db.session.commit()
コード例 #12
0
def send_mentions(object_name, href, comments_data):
    """Send emails for people mentions.

    Params:
      object_name: object title,
      href: link to the object,
      comments_data: set of CommentData named tuples.
  """
    from ggrc.notifications.common import send_email

    email_mentions = _find_email_mentions(comments_data)

    for email, related_comments_data in email_mentions.iteritems():
        title, email_comments = _generate_mention_email(
            object_name, related_comments_data)
        body = settings.EMAIL_MENTIONED_PERSON.render(person_mention={
            "comments": email_comments,
            "url": href,
        })
        send_email(email, title, body)
    db.session.commit()
コード例 #13
0
  def send_notification(self, filename, recipient, errors=None, failed=False):
    """Send mail notification with information about errors."""
    data = {}
    if failed:
      data["title"] = self.ERROR_TITLE.format(filename=filename)
      data["email_text"] = self.EXCEPTION_TEXT
      body = settings.EMAIL_BULK_SYNC_EXCEPTION.render(sync_data=data)
    elif errors:
      data["objects"] = [
          {
              "url": get_object_url(obj),
              "code": obj.slug,
              "title": obj.title,
          } for (obj, _) in errors
      ]
      data["title"] = self.ERROR_TITLE.format(filename=filename)
      data["email_text"] = self.ERROR_TEXT.format(filename=filename)
      body = settings.EMAIL_BULK_SYNC_FAILED.render(sync_data=data)
    else:
      data["title"] = self.SUCCESS_TITLE.format(filename=filename)
      data["email_text"] = self.SUCCESS_TEXT.format(filename=filename)
      body = settings.EMAIL_BULK_SYNC_SUCCEEDED.render(sync_data=data)

    common.send_email(recipient, self.ISSUETRACKER_SYNC_TITLE, body)
コード例 #14
0
def send_error_notification(message):
    try:
        user_email = common.getAppEngineEmail()
        common.send_email(user_email, "Error in nightly cron job", message)
    except:  # pylint: disable=bare-except
        logger.exception("Failed on sending notification")
コード例 #15
0
ファイル: cron.py プロジェクト: VinnieJohns/ggrc-core
def send_error_notification(message):
  try:
    user_email = common.getAppEngineEmail()
    common.send_email(user_email, "Error in nightly cron job", message)
  except:  # pylint: disable=bare-except
    logger.exception("Failed on sending notification")
コード例 #16
0
ファイル: cron.py プロジェクト: runt18/ggrc-core
def send_error_notification(message):
    try:
        user_email = common.getAppEngineEmail()
        common.send_email(user_email, "Error in nightly cron job", message)
    except Exception as e:
        current_app.logger.error(e)