def process_legal_flag(contact_info, copr): form = forms.CoprLegalFlagForm() legal_flag = models.LegalFlag(raise_message=form.comment.data, raised_on=int(time.time()), copr=copr, reporter=flask.g.user) db.session.add(legal_flag) db.session.commit() send_to = app.config["SEND_LEGAL_TO"] or ["root@localhost"] hostname = platform.node() navigate_to = "\nNavigate to http://{0}{1}".format( hostname, flask.url_for("admin_ns.legal_flag")) contact = "\nContact on owner is: {}".format(contact_info) reported_by = "\nReported by {0} <{1}>".format(flask.g.user.name, flask.g.user.mail) try: msg = MIMEText(form.comment.data + navigate_to + contact + reported_by, "plain") except UnicodeEncodeError: msg = MIMEText( form.comment.data.encode("utf-8") + navigate_to + contact + reported_by, "plain", "utf-8") msg["Subject"] = "Legal flag raised on {0}".format(copr.name) msg["From"] = "root@{0}".format(hostname) msg["To"] = ", ".join(send_to) s = smtplib.SMTP("localhost") s.sendmail("root@{0}".format(hostname), send_to, msg.as_string()) s.quit() flask.flash("Admin has been noticed about your report" " and will investigate the project shortly.") return flask.redirect(url_for_copr_details(copr))
def process_legal_flag(copr): form = forms.CoprLegalFlagForm() legal_flag = models.LegalFlag(raise_message=form.comment.data, raised_on=int(time.time()), copr=copr, reporter=flask.g.user) db.session.add(legal_flag) db.session.commit() send_to = app.config["SEND_LEGAL_TO"] or ["root@localhost"] msg = LegalFlagMessage(copr, flask.g.user, form.comment.data) send_mail(send_to, msg) flask.flash("Admin has been noticed about your report" " and will investigate the project shortly.") return flask.redirect(url_for_copr_details(copr))