예제 #1
0
def create(data):
    spaceData = []
    if 'spaceId' in data:
        spaceData = db_utils.find(database_name, domain, {'spaceId': data['spaceId']})
    if len(spaceData) == 1:
        return (404, {'data': 'space exists'})
    else:
        data['spaceId'] = str(sequence_service.nextval(100, 'spaceId', 'na'))
        print(data)
        updated_record = db_utils.upsert(database_name, domain, data)
    return (200, {'data': updated_record})
예제 #2
0
def recompute_order(space_id, project_id, order):
    stages = db_utils.find(
        space_id, domain,
        {'$and': [{
            'projectId': project_id
        }, {
            'order': {
                '$gt': order
            }
        }]}, [('order', pymongo.ASCENDING)])
    for stage in stages:
        stage['order'] = nextval(space_id, 'stageOrder', project_id)
        db_utils.upsert(space_id, domain, stage)
예제 #3
0
def recompute_order(space_id, project_id, order):
    last_stage = stage_service.get_last_stage(space_id, project_id)
    tasks = db_utils.find(
        space_id, domain,
        {'$and': [{
            'projectId': project_id
        }, {
            'order': {
                '$gt': order
            }
        }]}, [('order', pymongo.ASCENDING)])
    for task in tasks:
        task['order'] = nextval(space_id, 'taskOrder', project_id)
        db_utils.upsert(space_id, domain, task)
예제 #4
0
def update(request, space_id, project_id, data):
    project = db_utils.find(space_id, 'Project', {'_id': project_id})[0]
    data['projectId'] = project_id
    snapshot = []
    last_stage = stage_service.get_last_stage(space_id, project_id)
    if data['type'] == 'Epic' and ('color' not in data
                                   or data['color'] == None):
        data['color'] = 'color_' + str(
            (nextval(space_id, 'epicColor', project_id) % 10) + 1)
    if '_id' not in data:
        data['taskId'] = project['name'][:4].upper() + '-' + str(
            nextval(space_id, 'taskId', project_id))
        data['order'] = nextval(space_id, 'taskOrder', project_id)
    else:
        snapshot = db_utils.find(space_id, domain, {'_id': data['_id']})
    if data['stageId'] == last_stage['_id']:
        data['status'] = 'complete'
    updated_record = db_utils.upsert(space_id, domain, data, request.user_id)
    if '_id' in data and len(snapshot) == 1:
        log_service.add(space_id, domain, snapshot[0], updated_record, [
            'type', 'title', 'description', 'assignedTo', 'parentTaskId',
            'priority', 'timeEstimate', 'storyPoints'
        ], request.user_id)
    return (200, {'data': updated_record})
예제 #5
0
def get_session(space_id, auth_key):
    start_time = int(round(time.time() * 1000))
    response = requests.get(ONEAUTH_API + 'space/' + space_id + '/session/' +
                            auth_key)
    if response.status_code != 200:
        print(response)
        return (response.status_code, response.json())
    oa_response = jwt_utils.decode(response.json()['token'])
    existing_user_data = user_service.find_by_user_id(space_id,
                                                      oa_response['userId'])
    if len(existing_user_data) == 1:
        updated_record = user_service.update_user(
            space_id, {
                '_id': existing_user_data[0]['_id'],
                'firstName': oa_response['firstName'],
                'lastName': oa_response['lastName'],
                'email': oa_response['email']
            })
        updated_record['token'] = response.json()['token']
        return (200, {'data': updated_record})
    else:
        if user_service.is_first_user(space_id):
            sequence_service.create_sequence(space_id, 'userColor', '', 1)
        new_data = user_service.insert_user(
            space_id, {
                '_id':
                oa_response['userId'],
                'firstName':
                oa_response['firstName'],
                'lastName':
                oa_response['lastName'],
                'email':
                oa_response['email'],
                'color':
                'color_' +
                str((sequence_service.nextval(space_id, 'userColor', '') %
                     10) + 1)
            })
        new_data['token'] = response.json()['token']
        return (200, {'data': new_data})
예제 #6
0
def update(request, space_id, data):
    if '_id' not in data:
        data['order'] = nextval(space_id, 'stageOrder', data['projectId'])
    updated_record = db_utils.upsert(space_id, domain, data, request.user_id)
    return (200, {'data': updated_record})