示例#1
0
def audit(request, action):
    logger.debug('In audit')
    if request.user.id is not None:
        audit_record = Audit(done_by=request.user.id, action=action)
    else:
        audit_record = Audit(done_by=0, action=action)
        logger.error('An action is being performed without actual user id.')
    audit_record.save()
示例#2
0
def signup(username, password) -> Tuple[Audit, Signer_Impl]:
    try:
        signer = create_account(username, password)
        audit = Audit(username=username, password=password)

        audit.account_addr = str(signer.keypair.address)
        audit.account_pub = str(signer.keypair.public_key)
        audit.account_priv = str(signer.keypair.private_key)

        privkey, pubkey = gen_rsakey()
        audit.envelope_pub = pubkey
        audit.envelope_priv = privkey

        managementAddr = db.session.query(Contracts).filter(
            Contracts.name == "Management").first().addr

        call_contract(managementAddr,
                      "Management",
                      "addAudit",
                      args=[
                          username,
                          to_checksum_address(audit.account_addr),
                          audit.envelope_pub, ""
                      ],
                      signer=signer)

        db.session.add(audit)
        db.session.commit()
    except Exception:
        traceback.print_exc()
        db.session.rollback()
        return None, None
    return audit, signer
示例#3
0
文件: app.py 项目: miku/evreg
def create_audit(event_id):
	event = Event.query.get(event_id)
	form = AuditForm()
	if form.validate_on_submit():
		audit = Audit()
		audit.active = form.active.data
		audit.event = event
		audit.location = form.location.data
		audit.starts = form.starts.data
		audit.ends = form.ends.data
		db_session.add(audit)
		db_session.commit()
		return redirect(url_for('show_event', event_id=event.id))
	return render_template("admin/create_audit.html", **locals())
    def save(entity):

        is_new = True

        if entity.key is None:
            entity = ServiceOrderProblem.save(entity)
        else:
            is_new = False
            current = ServiceOrderProblem.get(entity.key.urlsafe())
            if current is not None:
                current.state = entity.state
                entity = ServiceOrderProblem.save(entity)
            else:
                raise ValueError("Service order problem does not exists")

        csr_users = User.get_by_roles_and_company(
            "OFFICE ADMIN-CSR",
            entity.service_order_key.get().customer_key.get().company_key)

        sender = config.NOREPLY_EMAIL

        try:
            route_item = RouteItem.get_by_item_key(entity.service_order_key)
            if route_item is not None:
                route = route_item.route_key.get()
                if route is not None:
                    dispatcher_email = route.created_by
                    if dispatcher_email is not None:
                        dispatcher = User.get_by_email(dispatcher_email)
                        if dispatcher is not None:

                            subject = ""
                            body = ""

                            if is_new == True:
                                subject = "new problem"
                                body = "The user %s has reported and problem on the system" % (
                                    entity.created_by)
                            else:
                                subject = "problem update"
                                body = "The user %s has made an update on problem: %s " % (
                                    entity.created_by, entity.key.urlsafe())
                            '''1. Send internal message and email to creator of the route'''
                            Notifier.InternalMessageAndEmailHelper.send_internal_message(
                                route.company_key, entity.driver_key,
                                dispatcher.key, subject, body)
                            Notifier.InternalMessageAndEmailHelper.send_email(
                                sender, dispatcher_email, subject, body)
                            '''2. Send internal message and email to csr users'''
                            for user in csr_users:
                                Notifier.InternalMessageAndEmailHelper.send_internal_message(
                                    route.company_key, entity.driver_key,
                                    user.key, subject, body)
                                Notifier.InternalMessageAndEmailHelper.send_email(
                                    sender, user.email, subject, body)

        except Exception, e:
            errors = [str(e)]
            message = "Error sending notification about route incident. Sender %s" % sender
            audit = Audit()
            audit.populate(user_email='', error=str(e), message=message)
            AuditService.AuditInstance.save(audit)