Exemple #1
0
def update_specification_state():
    # TODO: verify that current_user is owner of record and can edit it
    design_id = request.values['parent_id']
    state = request.form['state']
    transition = request.form['transition']
    comment = request.values['comment']
    specification = Specification.get_by_id(design_id)
    specification.update(state=state)
    specification.add_workflow_log_entry(capacity='Owner', action=transition, comment=comment)
    if state == specification.workflow.get_approval_state():
        for approver in specification.approvers:
            if not approver.approved_at:
                variables = {
                    'record': specification,
                    'approver': approver,
                    'comment': comment
                }
                send_email(subject='Approval Required for {0}: {1}'.format(specification.descriptor,
                                                                           specification.get_name()),
                           recipients=[approver.approver.email],
                           text_body=render_template('mail/approvals/new_approver.txt', **variables),
                           html_body=render_template('mail/approvals/new_approver.html', **variables))
    elif state == specification.workflow.released_state:
        # Only self-approval will trigger this
        comment = 'Revision ' + specification.revision
        specification.add_workflow_log_entry(capacity='PLAIDmin', action='Released', comment=comment)
    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Exemple #2
0
def create_task():
    """Create new Task."""
    form = CreateTaskForm(request.form)
    validated = form.validate_on_submit()

    if validated:
        title = form.title.data
        urgency = form.urgency.data
        assigned_to = form.assign_to.data
        need_date = form.create_need_date.data
        summary = form.summary.data
        task = Task.create(title=title,
                           urgency=urgency,
                           assigned_to=assigned_to,
                           requested_by=current_user,
                           need_date=need_date,
                           summary=summary)
        send_email(subject='Task Assigned: {0}'.format(task.title),
                   recipients=[task.assigned_to.email],
                   text_body=render_template('mail/new_task.txt', task=task),
                   html_body=render_template('mail/new_task.html', task=task))
        json = {'success': True, 'url': task.get_url()}
        return jsonify(json), 200, {'ContentType': 'application/json'}
    else:
        return make_response(
            render_template('task/create_task.html', form=form), 500)
Exemple #3
0
def update_task():
    task_id = request.form['pk']
    # UID for field will be ala [fieldname]-[classname]-[id]-editable, field name will be first section always
    field = request.form['name'].split('-')[0]
    field_value = request.form['value']
    task = Task.get_by_id(task_id)
    original_value = None

    if field == 'title':
        original_value = task.title
        task.update(title=field_value)
    elif field == 'summary':
        original_value = task.summary
        task.update(summary=field_value)
    elif field == 'state':
        original_value = task.state
        task.update(state=field_value)
    elif field == 'urgency':
        original_value = task.urgency
        task.update(urgency=field_value)
        field = 'criticality'  # To match what is visually displayed
    elif field == 'assigned_to':
        if task.assigned_to:
            original_value = task.assigned_to.get_name()
        assigned_to = User.get_by_id(field_value)
        task.update(assigned_to=assigned_to)
        send_email(subject='Task Assigned: {0}'.format(task.title),
                   recipients=[task.assigned_to.email],
                   text_body=render_template('mail/new_task.txt', task=task),
                   html_body=render_template('mail/new_task.html', task=task))
        field_value = assigned_to.get_name() if assigned_to else None
    elif field == 'need_date':
        try:
            original_value = task.need_date.date()
            # Need to append UTC hours due to moment.js and timezones
            task.update(need_date=parse(field_value).date() +
                        relativedelta(hours=+datetime.utcnow().hour))
        except ValueError:
            return "Incorrect date format: " + field_value, 500, {
                'ContentType': 'application/json'
            }
    elif field == 'thumbnail_id':
        thumbnail_id = None if field_value == 'default' else field_value
        task.update(thumbnail_id=thumbnail_id)
        return render_template('shared/thumbnail_return.html', record=task)

    task.add_change_log_entry(action='Edit',
                              field=field.title().replace('_', ' '),
                              original_value=original_value,
                              new_value=field_value)

    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}
Exemple #4
0
def approve():
    approver_ids = request.values.getlist('approver_id')
    record_id = request.values['parent_id']
    record_class = request.values['parent_class'].lower()
    record = get_record_by_id_and_class(record_id, record_class)
    for approver_id in approver_ids:
        approver = Approver.get_by_id(approver_id)
        resolution = request.values['approval_' + approver_id]
        comment = request.values['approval_comment_' + approver_id]
        if resolution == 'approve':
            approver.approved_at = dt.datetime.utcnow()
            approver.save()
            record.add_workflow_log_entry(current_user,
                                          capacity=approver.capacity,
                                          action='Approved',
                                          comment=comment)
            move_to_released = True
            for approval in record.approvers:
                if not approval.approved_at:
                    move_to_released = False
                    break
            if move_to_released:
                try:
                    comment = 'Revision ' + record.revision
                except AttributeError:
                    comment = None
                #TODO: PLAIDmin user
                record.add_workflow_log_entry(
                    current_user,
                    capacity='PLAIDmin',
                    action=record.workflow.released_state,
                    comment=comment)
                record.state = record.workflow.released_state
                send_email(subject='{0} {1}: {2}'.format(
                    record.descriptor, record.state, record.get_name()),
                           recipients=[record.owner.email],
                           text_body=render_template(
                               'mail/approvals/record_released.txt',
                               record=record),
                           html_body=render_template(
                               'mail/approvals/record_released.html',
                               record=record))
            record.save()
        elif resolution == 'edit':
            record.add_workflow_log_entry(current_user,
                                          capacity=approver.capacity,
                                          action='Required Edit',
                                          comment=comment)
            record.state = 'In Work'
            record.save()
            variables = {
                'record': record,
                'approver': approver,
                'comment': comment
            }
            send_email(subject='Edit Required on {0}: {1}'.format(
                record.descriptor, record.get_name()),
                       recipients=[approver.approver.email],
                       text_body=render_template(
                           'mail/approvals/record_required_edit.txt',
                           **variables),
                       html_body=render_template(
                           'mail/approvals/record_required_edit.html',
                           **variables))
        elif resolution == 'reassign':
            approver.approver_id = request.values['approval_reassign_' +
                                                  approver_id]
            approver.save()
            record.add_workflow_log_entry(current_user,
                                          capacity=approver.capacity,
                                          action='Reassigned',
                                          comment=comment)
            record.save()
            variables = {
                'record': record,
                'approver': approver,
                'comment': comment
            }
            # Send email to owner of record to let him know approver has changed
            send_email(subject='Approval Reassigned for {0}: {1}'.format(
                record.descriptor, record.get_name()),
                       recipients=[record.owner.email],
                       text_body=render_template(
                           'mail/approvals/changed_approver.txt', **variables),
                       html_body=render_template(
                           'mail/approvals/changed_approver.html',
                           **variables))
            # Send email to new approver to let him know he needs to approve this record
            send_email(
                subject='Approval Required: {0}'.format(record.get_name()),
                recipients=[approver.approver.email],
                text_body=render_template('mail/approvals/new_approver.txt',
                                          **variables),
                html_body=render_template('mail/approvals/new_approver.html',
                                          **variables))
    return jsonify({'success': True}), 200, {'ContentType': 'application/json'}