Esempio n. 1
0
def update_issue(current_user, issue_id):
    if not current_user.admin:
        return jsonify({'message': 'Cannot perform that function!'})

    issue = Issue.query.filter_by(id=issue_id).first()
    if not issue:
        return jsonify({'message': 'No Issue found with your inputs'})
    data = request.get_json()
    if 'new_stage' in data:
        # add a tracking on the issue
        comment = 'moved from '+issue.status+' to '+data.get('new_stage')
        employee = Employee.query.filter_by(id=1).first()
        json_issue_tracking = {'date': datetime.now(), 'comment': comment, 'issue': issue, 'employee': employee}
        issue_tracking = IssueTracking(json_issue_tracking)
        issue.status = data.get('new_stage')
        db.session.add(issue_tracking)
    else:
        name = data.get('name')
        start_date = parse_date(data.get('start_date', ''))
        due_date = parse_date(data.get('due_date', ''))
        status = data.get('status')
        priority = data.get('priority', 'medium')
        project = Project.query.filter_by(id=data.get('project_id')).first()
        employee = Employee.query.filter_by(id=data.get('employee_id')).first()

        json_issue = {'name': name, 'start_date': start_date, 'due_date': due_date, 'status': status,
                      'project': project, 'employee': employee, 'priority': priority}
        issue.update(json_issue=json_issue)
    db.session.merge(issue)
    db.session.commit()

    return jsonify({'message': 'Issue Updated!'})
Esempio n. 2
0
def create_issue(current_user):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'}), 401

    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    status = data.get('status')
    priority = data.get('priority', 'medium')
    project = Project.query.filter_by(id=data.get('project_id')).first()
    employee = Employee.query.filter_by(id=data.get('employee_id')).first()

    if not project or not employee or not start_date or not due_date or not name:
        return jsonify({
            'message':
            'No employee | sprint | start_date | due_date | name found with your inputs'
        }), 400
    json_issue = {
        'name': name,
        'start_date': start_date,
        'due_date': due_date,
        'status': status,
        'project': project,
        'employee': employee,
        'priority': priority
    }
    new_issue = Issue(json_issue=json_issue)
    db.session.add(new_issue)
    db.session.flush()
    id_ = new_issue.id
    db.session.commit()

    return jsonify({'message': 'New Issue created!', 'id': id_})
Esempio n. 3
0
def update_task(current_user, task_id):
    if not current_user.admin:
        return jsonify({'message': 'Cannot perform that function!'})

    task = Task.query.filter_by(id=task_id).first()
    if not task:
        return jsonify({'message': 'No Task found with your inputs'})
    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    status = data.get('status')
    priority = data.get('priority', 'medium')
    sprint = Sprint.query.filter_by(id=data.get('sprint_id')).first()
    employee = Employee.query.filter_by(id=data.get('employee_id')).first()

    json_task = {
        'name': name,
        'start_date': start_date,
        'due_date': due_date,
        'status': status,
        'sprint': sprint,
        'employee': employee,
        'priority': priority
    }
    task.update(json_task=json_task)
    db.session.merge(task)
    db.session.commit()

    return jsonify({'message': 'Task Updated!'})
Esempio n. 4
0
def create_project(current_user):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'})

    data = request.get_json()
    print(data)
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    comment = data.get('comment', None)
    teams = data.get('teams', [])
    company = Company.query.filter_by(id=data.get('company_id')).first()

    json_project = {
        'name': name,
        'start_date': start_date,
        'due_date': due_date,
        'comment': comment,
        'company': company
    }
    new_project = Project(json_project=json_project)
    for item in teams:
        team = Team.query.filter_by(id=item['id']).first()
        new_project.teams = new_project.teams + [team]
    db.session.add(new_project)
    db.session.commit()

    return jsonify({'message': 'New project created!'})
def create_employee(current_user):
    if not current_user.admin:
        return jsonify({'message': 'Cannot perform that function!'}), 401

    data = request.get_json()
    badge = data.get('badge')
    start_date = parse_date(data.get('start_date', ''))
    end_date = parse_date(data.get('end_date', ''))
    is_full_time = data.get('is_full_time')
    user = User.query.filter_by(id=data.get('user_id')).first()
    role = Role.query.filter_by(id=data.get('role_id')).first()
    team = Team.query.filter_by(id=data.get('team_id')).first()
    company = Company.query.filter_by(id=data.get('company_id')).first()

    if not company or not role or not team or not user:
        return jsonify({
            'message':
            'No company | role | team | user found with your inputs ids'
        })
    json_employee = {
        'badge': badge,
        'start_date': start_date,
        'end_date': end_date,
        'is_full_time': is_full_time,
        'user': user,
        'role': role,
        'team': team,
        'company': company
    }
    new_employee = Employee(json_employee=json_employee)
    db.session.add(new_employee)
    db.session.commit()

    return jsonify({'message': 'New Employee created!'})
Esempio n. 6
0
def create_task(current_user):
    if not current_user.admin:
        return jsonify({'message': 'Cannot perform that function!'})

    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    status = data.get('status')
    priority = data.get('priority', 'medium')
    sprint = Sprint.query.filter_by(id=data.get('sprint_id')).first()
    employee = Employee.query.filter_by(id=data.get('employee_id')).first()

    if not sprint or not employee or not start_date or not due_date or not name:
        return jsonify({
            'message':
            'No employee | sprint | start_date | due_date | name found with your inputs'
        })
    json_task = {
        'name': name,
        'start_date': start_date,
        'due_date': due_date,
        'status': status,
        'sprint': sprint,
        'employee': employee,
        'priority': priority
    }
    new_task = Task(json_task=json_task)
    db.session.add(new_task)
    db.session.commit()

    return jsonify({'message': 'New Task created!'})
def update_employee(current_user, employee_id):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'}), 200

    employee = Employee.query.filter_by(id=employee_id).first()
    data = request.get_json()
    badge = data.get('badge')
    start_date = parse_date(data.get('start_date', ''))
    end_date = parse_date(data.get('end_date', ''))
    is_full_time = data.get('is_full_time', False)
    active = data.get('active', True)
    role = Role.query.filter_by(id=data.get('role_id')).first()

    if not employee or not role:
        return jsonify({'message': 'Role not  found'}), 400

    employee.badge = badge
    employee.start_date = start_date
    employee.end_date = end_date
    employee.is_full_time = is_full_time
    employee.active = active
    employee.role = role

    db.session.merge(employee)
    db.session.commit()

    return jsonify({'message': 'employee updated!'})
Esempio n. 8
0
def text(message):
    """Sent by a client when the user entered a new message.
    The message is sent to all people in the room."""
    room_name = message.get('room')
    emp_id = message.get('employee_id')
    room_id = message.get('room_id')
    sending_date = parse_date(message.get('sending_date', ''))
    message = message.get('message')
    room = ChatRoom.query.filter_by(id=room_id).first()
    employee = Employee.query.filter_by(id=emp_id).first()

    if not (employee and room):
        emit('message', 'not employee nor room', room=room)
    json_message = {
        'message': message,
        'sending_date': sending_date,
        'employee': employee,
        'chatroom': room
    }
    msg = Message(json_message)
    db.session.add(msg)
    db.session.flush()
    out = {
        'id': msg.id,
        'date': str(msg.sending_date),
        'chatroom_id': msg.chatroom_id,
        'value': msg.message,
        'employee_id': msg.employee.id,
        'employee_name': msg.employee.user.name
    }
    db.session.commit()
    emit('message', out, room=room_name)
Esempio n. 9
0
def turn_task_to_issue(current_user, task_id):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'})

    task = Task.query.filter_by(id=task_id).first()
    if not task:
        return jsonify({'message': 'No Task found with your inputs'})

    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    status = data.get('status')
    priority = data.get('priority', 'medium')
    sprint = Sprint.query.filter_by(id=data.get('sprint_id')).first()
    employee = Employee.query.filter_by(id=data.get('employee_id')).first()

    if not sprint or not employee or not start_date or not due_date or not name:
        return jsonify({
            'message':
            'No employee | sprint | start_date | due_date | name found with your inputs'
        })
    json_issue = {
        'name': name,
        'start_date': start_date,
        'due_date': due_date,
        'status': status,
        'project': sprint.project,
        'employee': employee,
        'priority': priority
    }

    new_issue = Issue(json_issue=json_issue)
    db.session.add(new_issue)

    for item in task.task_tracking:
        json_issue_tracking = {
            'date': item.date,
            'comment': item.comment,
            'issue': new_issue,
            'employee': item.employee
        }
        db.session.add(IssueTracking(json_issue_tracking=json_issue_tracking))
    db.session.delete(task)
    db.session.commit()

    return jsonify({'message': 'Task Moved to Issue'})
def create_sprint(current_user):
    if not current_user.admin:
        return jsonify({'message': 'Cannot perform that function!'})

    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    comment = data.get('comment', None)
    project = Project.query.filter_by(id=data.get('project_id')).first()

    json_sprint = {'name': name, 'start_date': start_date, 'due_date': due_date, 'comment': comment, 'project': project}
    new_sprint = Sprint(json_sprint=json_sprint)
    db.session.add(new_sprint)
    db.session.commit()

    return jsonify({'message': 'New sprint created!'})
Esempio n. 11
0
def update_sprint(current_user, sprint_id):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'}), 401

    sprint = Sprint.query.filter_by(id=sprint_id).first()
    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    if not sprint:
        return jsonify({'message': 'sprint not found'}), 400
    sprint.name = name
    sprint.start_date = start_date
    sprint.due_date = due_date
    db.session.merge(sprint)
    db.session.commit()

    return jsonify({'message': 'sprint updated!'})
Esempio n. 12
0
def update_task(current_user, task_id):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'})

    task = Task.query.filter_by(id=task_id).first()
    if not task:
        return jsonify({'message': 'No Task found with your inputs'})
    data = request.get_json()
    if 'new_stage' in data:
        # add a tracking on the issue
        comment = 'moved from ' + task.status + ' to ' + data.get('new_stage')
        employee = Employee.query.filter_by(id=data.get('employee_id')).first()
        json_task_tracking = {
            'date': datetime.now(),
            'comment': comment,
            'task': task,
            'employee': employee
        }
        task_tracking = TaskTracking(json_task_tracking)
        task.status = data.get('new_stage')
        db.session.add(task_tracking)
    else:
        name = data.get('name')
        start_date = parse_date(data.get('start_date', ''))
        due_date = parse_date(data.get('due_date', ''))
        status = data.get('status')
        priority = data.get('priority', 'medium')
        sprint = Sprint.query.filter_by(id=data.get('sprint_id')).first()
        employee = Employee.query.filter_by(id=data.get('employee_id')).first()

        json_task = {
            'name': name,
            'start_date': start_date,
            'due_date': due_date,
            'status': status,
            'sprint': sprint,
            'employee': employee,
            'priority': priority
        }
        task.update(json_task=json_task)
    db.session.merge(task)
    db.session.commit()

    return jsonify({'message': 'Task Updated!'})
Esempio n. 13
0
def update_project(current_user, project_id):
    if not current_user:
        return jsonify({'message': 'Cannot perform that function!'}), 401

    project = Project.query.filter_by(id=project_id).first()
    data = request.get_json()
    name = data.get('name')
    start_date = parse_date(data.get('start_date', ''))
    due_date = parse_date(data.get('due_date', ''))
    comment = data.get('comment', None)
    if not project:
        return jsonify({'message': 'Project not found'}), 400
    project.name = name
    project.start_date = start_date
    project.due_date = due_date
    project.comment = comment
    db.session.merge(project)
    db.session.commit()

    return jsonify({'message': 'project updated!'})