Example #1
0
def get_user_history(Id):
    userInfo = session.get('userProfile', 'not set')
    if userInfo['role'] !='admin':
        abort(401)
    # Get user details
    user = Users.query.get(Id)
    user = user.format()
    
    # Get all projects of the user
    project = Project.query.join(Map_users_proj, Map_users_proj.p_id==Project.p_id)\
        .add_columns(Project.p_id.label('id'), Project.p_name.label('name'))\
            .filter(Map_users_proj.users_id==Id)

    # Get all the projects
    sql = text("""select p_id,p_name,p_desc,p_start_date, p_end_date from project where p_id
                 not in (select p_id from map_users_proj where users_id ="""+str(Id)+""")""")
    all_project = db.session.execute(sql)
    all_project = [Project.format(p) for p in all_project]

    # Get the tickets of the user/dev/manager
    ticket = ""
    #user submitted tickets
    if user['role']=='user' or user['role']=='manager':
        ticket = Ticket.query.join(Project, Ticket.p_id==Project.p_id)\
            .add_columns(Ticket.t_id.label('id'), Ticket.t_title.label('title'), Project.p_name.label('project'))\
                .filter(Ticket.submitter_email==user['email'])

    #Developer Assigned tickets
    elif user['role']=='dev':
        ticket = Ticket.query.join(Project, Ticket.p_id==Project.p_id)\
                    .add_columns(Ticket.t_id.label('id'), Ticket.t_title.label('title'), Project.p_name.label('project'))\
                    .filter(Ticket.users_id==Id)

    delete_user = False
    if Id > 21 or userInfo['id'] == 1:
        delete_user = True

    data = {
        'users' : [user],
        'projects': project,
        'all_projects': all_project,
        'ticket': ticket,
        'delete_user': delete_user,
        'user_name': userInfo['name'],
        'role': userInfo['role'],
        'page' : 'userDetail'
    }
    return render_template('user-details.html',data=data)
Example #2
0
def get_dev_project():
    userInfo = session.get('userProfile', 'not set')
    dev_email = userInfo['email']

    if userInfo['role'] != 'dev' and userInfo['role'] != 'manager':
        abort(401)

    #fetch list of projects that the Developer is assigned to using the map table
    #join Project, map_users_proj on project id
    #join map_users_proj, users on user_id
    #The map_users_proj table contains the maping of project to user
    project = Project.query.join(Map_users_proj, Map_users_proj.p_id == Project.p_id)\
        .join(Users, Users.users_id == Map_users_proj.users_id).filter(Users.users_email == dev_email).all()
    project = [Project.format(pro) for pro in project]

    data = {
        'project': project,
        'user_name': userInfo['name'],
        'role': userInfo['role'],
        'notify': notification.notify(userInfo['id']),
        'page': 'projects'
    }
    return render_template('list.html', data=data)