Esempio n. 1
0
File: user.py Progetto: abrt/faf
 def contact_mails(self):
     contact_mail = queries.get_contact_email(self.db, self.mail)
     if contact_mail:
         reports = queries.get_reportcontactmails_by_id(self.db, contact_mail.id).all()
         return {"Contact Mail" : self.mail,
                 "Reports" : [get_url("reports", report.report_id) for report in reports]}
     return {}
Esempio n. 2
0
def delete_user_data():
    usermail = g.user.mail
    fas_user = queries.get_user_by_mail(db, usermail).first()
    bz_user = queries.get_bz_user(db, usermail)
    contact_email = queries.get_contact_email(db, usermail)

    if bz_user is not None:
        anonymous = create_anonymous_bzuser(db, uid=-1)
        delete_bugzilla_user(db, bz_user.id, anonymous.id)
        db.session.delete(bz_user)

    if fas_user is not None:
        queries.get_reportarchives_by_username(db, fas_user.username).delete(False)
        queries.get_problemreassigns_by_username(db, fas_user.username).delete(False)

    if contact_email is not None:
        queries.get_reportcontactmails_by_id(db, contact_email.id).delete(False)
        db.session.delete(contact_email)

    # Sign out user before deleting his account
    session.pop("openid", None)
    flash(u"You were signed out.", category='info')
    db.session.delete(fas_user)
    db.session.commit()

    return redirect(oid.get_next_url())
Esempio n. 3
0
 def contact_mails(self):
     contact_mail = queries.get_contact_email(self.db, self.mail)
     if contact_mail:
         reports = queries.get_reportcontactmails_by_id(
             self.db, contact_mail.id).all()
         return {
             "Contact Mail":
             self.mail,
             "Reports":
             [get_url("reports", report.report_id) for report in reports]
         }
     return {}
Esempio n. 4
0
def save_attachment(db, attachment):
    atype = attachment["type"].lower()

    if not attachment_type_allowed(atype):
        raise FafError(
            "Attachment type '{}' not allowed on this server".format(atype))

    report = get_report(db, attachment["bthash"])
    if not report:
        raise FafError("Report for given bthash not found")

    if atype in ["rhbz", "fedora-bugzilla", "rhel-bugzilla"]:
        bug_id = int(attachment["data"])

        reportbug = (db.session.query(
            ReportBz).filter((ReportBz.report_id == report.id)
                             & (ReportBz.bzbug_id == bug_id)).first())

        if reportbug:
            log.debug("Skipping existing attachment")
            return

        bug = get_bz_bug(db, bug_id)
        if not bug:
            if atype in bugtrackers:
                # download from bugtracker identified by atype
                tracker = bugtrackers[atype]

                if not tracker.installed(db):
                    raise FafError("Bugtracker used in this attachment"
                                   " is not installed")

                bug = tracker.download_bug_to_storage(db, bug_id)
            elif atype == "rhbz":
                # legacy value
                # - we need to guess the bugtracker:
                # either fedora-bugzilla or rhel-bugzilla,
                # former is more probable
                for possible_tracker in ["fedora-bugzilla", "rhel-bugzilla"]:
                    if possible_tracker not in bugtrackers:
                        continue

                    tracker = bugtrackers[possible_tracker]
                    if not tracker.installed(db):
                        continue

                    bug = tracker.download_bug_to_storage(db, bug_id)
                    if bug:
                        break

        if bug:
            new = ReportBz()
            new.report = report
            new.bzbug = bug
            db.session.add(new)
            db.session.flush()
        else:
            log.error("Failed to fetch bug #{0} from '{1}'".format(
                bug_id, atype))

    elif atype == "centos-mantisbt":
        bug_id = int(attachment["data"])

        reportbug = (db.session.query(ReportMantis).filter(
            (ReportMantis.report_id == report.id)
            & (ReportMantis.mantisbug_id == bug_id)).first())

        if reportbug:
            log.debug("Skipping existing attachment")
            return

        bug = get_mantis_bug(db, bug_id)
        if not bug:
            if atype in bugtrackers:
                # download from bugtracker identified by atype
                tracker = bugtrackers[atype]

                if not tracker.installed(db):
                    raise FafError("Bugtracker used in this attachment"
                                   " is not installed")

                bug = tracker.download_bug_to_storage(db, bug_id)

        if bug:
            new = ReportMantis()
            new.report = report
            new.mantisbug = bug
            db.session.add(new)
            db.session.flush()
        else:
            log.error("Failed to fetch bug #{0} from '{1}'".format(
                bug_id, atype))

    elif atype == "comment":
        comment = ReportComment()
        comment.report = report
        comment.text = attachment["data"]
        comment.saved = datetime.datetime.utcnow()
        db.session.add(comment)
        db.session.flush()

    elif atype == "email":
        db_contact_email = get_contact_email(db, attachment["data"])
        if db_contact_email is None:
            db_contact_email = ContactEmail()
            db_contact_email.email_address = attachment["data"]
            db.session.add(db_contact_email)

            db_report_contact_email = ReportContactEmail()
            db_report_contact_email.contact_email = db_contact_email
            db_report_contact_email.report = report
            db.session.add(db_report_contact_email)
        else:
            db_report_contact_email = \
                get_report_contact_email(db, db_contact_email.id, report.id)
            if db_report_contact_email is None:
                db_report_contact_email = ReportContactEmail()
                db_report_contact_email.contact_email = db_contact_email
                db_report_contact_email.report = report
                db.session.add(db_report_contact_email)

        try:
            db.session.flush()
        except IntegrityError:
            raise FafError("Email address already assigned to the report")

    elif atype == "url":
        url = attachment["data"]

        # 0ne URL can be attached to many Reports, but every reports must
        # have unique url's
        db_url = (db.session.query(ReportURL).filter(
            ReportURL.url == url).filter(
                ReportURL.report_id == report.id).first())

        if db_url:
            log.debug("Skipping existing URL")
            return

        db_url = ReportURL()
        db_url.report = report
        db_url.url = url
        db_url.saved = datetime.datetime.utcnow()

        try:
            db.session.flush()
        except IntegrityError:
            raise FafError("Unable to save URL")

    else:
        log.warning("Unknown attachment type")
Esempio n. 5
0
def save_attachment(db, attachment):
    atype = attachment["type"].lower()

    if not attachment_type_allowed(atype):
        raise FafError("Attachment type '{}' not allowed on this server"
                       .format(atype))

    report = get_report(db, attachment["bthash"])
    if not report:
        raise FafError("Report for given bthash not found")

    if atype in ["rhbz", "fedora-bugzilla", "rhel-bugzilla"]:
        bug_id = int(attachment["data"])

        reportbug = (db.session.query(ReportBz)
                     .filter(
                         (ReportBz.report_id == report.id) &
                         (ReportBz.bzbug_id == bug_id)
                     )
                     .first())

        if reportbug:
            log.debug("Skipping existing attachment")
            return

        bug = get_bz_bug(db, bug_id)
        if not bug:
            if atype in bugtrackers:
                # download from bugtracker identified by atype
                tracker = bugtrackers[atype]

                if not tracker.installed(db):
                    raise FafError("Bugtracker used in this attachment"
                                   " is not installed")

                bug = tracker.download_bug_to_storage(db, bug_id)
            elif atype == "rhbz":
                # legacy value
                # - we need to guess the bugtracker:
                # either fedora-bugzilla or rhel-bugzilla,
                # former is more probable
                for possible_tracker in ["fedora-bugzilla", "rhel-bugzilla"]:
                    if possible_tracker not in bugtrackers:
                        continue

                    tracker = bugtrackers[possible_tracker]
                    if not tracker.installed(db):
                        continue

                    bug = tracker.download_bug_to_storage(db, bug_id)
                    if bug:
                        break

        if bug:
            new = ReportBz()
            new.report = report
            new.bzbug = bug
            db.session.add(new)
            db.session.flush()
        else:
            log.error("Failed to fetch bug #{0} from '{1}'"
                      .format(bug_id, atype))

    elif atype == "centos-mantisbt":
        bug_id = int(attachment["data"])

        reportbug = (db.session.query(ReportMantis)
                     .filter(
                         (ReportMantis.report_id == report.id) &
                         (ReportMantis.mantisbug_id == bug_id))
                     .first())

        if reportbug:
            log.debug("Skipping existing attachment")
            return

        bug = get_mantis_bug(db, bug_id)
        if not bug:
            if atype in bugtrackers:
                # download from bugtracker identified by atype
                tracker = bugtrackers[atype]

                if not tracker.installed(db):
                    raise FafError("Bugtracker used in this attachment"
                                   " is not installed")

                bug = tracker.download_bug_to_storage(db, bug_id)

        if bug:
            new = ReportMantis()
            new.report = report
            new.mantisbug = bug
            db.session.add(new)
            db.session.flush()
        else:
            log.error("Failed to fetch bug #{0} from '{1}'"
                      .format(bug_id, atype))

    elif atype == "comment":
        comment = ReportComment()
        comment.report = report
        comment.text = attachment["data"]
        comment.saved = datetime.datetime.utcnow()
        db.session.add(comment)
        db.session.flush()

    elif atype == "email":
        db_contact_email = get_contact_email(db, attachment["data"])
        if db_contact_email is None:
            db_contact_email = ContactEmail()
            db_contact_email.email_address = attachment["data"]
            db.session.add(db_contact_email)

            db_report_contact_email = ReportContactEmail()
            db_report_contact_email.contact_email = db_contact_email
            db_report_contact_email.report = report
            db.session.add(db_report_contact_email)
        else:
            db_report_contact_email = \
                get_report_contact_email(db, db_contact_email.id, report.id)
            if db_report_contact_email is None:
                db_report_contact_email = ReportContactEmail()
                db_report_contact_email.contact_email = db_contact_email
                db_report_contact_email.report = report
                db.session.add(db_report_contact_email)

        try:
            db.session.flush()
        except IntegrityError:
            raise FafError("Email address already assigned to the report")

    elif atype == "url":
        url = attachment["data"]

        # 0ne URL can be attached to many Reports, but every reports must
        # have unique url's
        db_url = (db.session.query(ReportURL)
                  .filter(ReportURL.url == url)
                  .filter(ReportURL.report_id == report.id)
                  .first())

        if db_url:
            log.debug("Skipping existing URL")
            return

        db_url = ReportURL()
        db_url.report = report
        db_url.url = url
        db_url.saved = datetime.datetime.utcnow()

        try:
            db.session.flush()
        except IntegrityError:
            raise FafError("Unable to save URL")

    else:
        log.warning("Unknown attachment type")