Beispiel #1
0
def get_resource_by_id(user, resource, table, embed_many, ignore_columns=None):
    args = schemas.args(flask.request.args.to_dict())
    resource_name = table.name[0:-1]
    resource_id = resource['id']
    columns = v1_utils.get_columns_name_with_objects(table)

    query = v1_utils.QueryBuilder(table, args, columns, ignore_columns)

    if not auth.is_admin(user) and 'team_id' in resource:
        query.add_extra_condition(table.c.team_id == user['team_id'])

    if 'state' in resource:
        query.add_extra_condition(table.c.state != 'archived')

    query.add_extra_condition(table.c.id == resource_id)

    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, table.name, args['embed'], embed_many)

    if len(rows) < 1:
        raise dci_exc.DCINotFound(resource_name, resource_id)
    resource = rows[0]

    res = flask.jsonify({resource_name: resource})

    if 'etag' in resource:
        res.headers.add_header('ETag', resource['etag'])

    return res
def get_all_products(user):
    args = check_and_get_args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    if (user.is_not_super_admin() and user.is_not_read_only_user()
            and user.is_not_epm()):
        _JPT = models.JOIN_PRODUCTS_TEAMS

        query = v1_utils.QueryBuilder(
            models.PRODUCTS,
            args,
            _T_COLUMNS,
            root_join_table=_JPT,
            root_join_condition=sql.and_(
                _JPT.c.product_id == _TABLE.c.id,  # noqa
                _JPT.c.team_id.in_(user.teams_ids)))  # noqa

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'products': rows, '_meta': {'count': nb_rows}})
Beispiel #3
0
def get_all_jobs(user, topic_id=None):
    """Get all jobs.

    If topic_id is not None, then return all the jobs with a topic
    pointed by topic_id.
    """
    # get the diverse parameters
    args = check_and_get_args(flask.request.args.to_dict())

    # build the query thanks to the QueryBuilder class
    query = v1_utils.QueryBuilder(_TABLE, args, _JOBS_COLUMNS)

    # add extra conditions for filtering

    # # If not admin nor rh employee then restrict the view to the team
    if (user.is_not_super_admin() and user.is_not_read_only_user()
            and user.is_not_epm()):
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams_ids))

    # # If topic_id not None, then filter by topic_id
    if topic_id is not None:
        query.add_extra_condition(_TABLE.c.topic_id == topic_id)

    # # Get only the non archived jobs
    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'jobs': rows, '_meta': {'count': nb_rows}})
Beispiel #4
0
def get_all_jobs(user, jd_id=None):
    """Get all jobs.

    If jd_id is not None, then return all the jobs with a jobdefinition
    pointed by jd_id.
    """
    # get the diverse parameters
    args = schemas.args(flask.request.args.to_dict())

    # build the query thanks to the QueryBuilder class
    query = v1_utils.QueryBuilder(_TABLE, args, _JOBS_COLUMNS,
                                  ['configuration'])

    # add extra conditions for filtering

    # # If not admin then restrict the view to the team
    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.team_id == user['team_id'])

    # # If jd_id not None, then filter by jobdefinition_id
    if jd_id is not None:
        query.add_extra_condition(_TABLE.c.jobdefinition_id == jd_id)

    # # Get only the non archived jobs
    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'jobs': rows, '_meta': {'count': nb_rows}})
Beispiel #5
0
def get_all_issues(user):
    args = check_and_get_args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _I_COLUMNS)
    query.add_extra_condition(_TABLE.c.state != 'archived')
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name)

    return flask.jsonify({'issues': rows, '_meta': {'count': nb_rows}})
def get_all_permissions(user):
    args = schemas.args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'permissions': rows, '_meta': {'count': nb_rows}})
Beispiel #7
0
def get_all_tests_by_team(user, team_id):
    # todo: remove team_id
    args = check_and_get_args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)
    query.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name)

    return flask.jsonify({'tests': rows, '_meta': {'count': nb_rows}})
Beispiel #8
0
def get_all_feeders(user):
    args = schemas.args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _F_COLUMNS)

    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))

    query.add_extra_condition(_TABLE.c.state != 'archived')

    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'feeders': rows, '_meta': {'count': len(rows)}})
Beispiel #9
0
def get_all_tests(user, team_id):
    args = schemas.args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)
    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))
    query.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'tests': rows, '_meta': {'count': nb_rows}})
Beispiel #10
0
def get_logs(user):
    args = schemas.args(flask.request.args.to_dict())

    if args['limit'] is None:
        args['limit'] = 10

    query = v1_utils.QueryBuilder(_TABLE, args, _A_COLUMNS)

    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'], None)

    return flask.jsonify({'audits': rows, '_meta': {'count': nb_rows}})
Beispiel #11
0
def get_all_users(user):
    args = check_and_get_args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _USERS_COLUMNS, ['password'])

    if user.is_not_super_admin() and user.is_not_epm():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams_ids))

    query.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'users': rows, '_meta': {'count': nb_rows}})
def get_all_components(user, topic_id):
    """Get all components of a topic."""

    args = check_and_get_args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _C_COLUMNS)

    query.add_extra_condition(
        sql.and_(_TABLE.c.topic_id == topic_id, _TABLE.c.state != 'archived'))

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'components': rows, '_meta': {'count': nb_rows}})
def list_components_files(user, c_id):
    component = v1_utils.verify_existence_and_get(c_id, _TABLE)
    topic = v1_utils.verify_existence_and_get(component['topic_id'],
                                              models.TOPICS)
    export_control.verify_access_to_topic(user, topic)

    args = check_and_get_args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(models.COMPONENTFILES, args, _CF_COLUMNS)
    query.add_extra_condition(models.COMPONENTFILES.c.component_id == c_id)

    nb_rows = query.get_number_of_rows(models.COMPONENTFILES,
                                       models.COMPONENTFILES.c.component_id == c_id)  # noqa
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, models.COMPONENTFILES.name, None, None)

    return flask.jsonify({'component_files': rows,
                          '_meta': {'count': nb_rows}})
Beispiel #14
0
def get_all_users(user, team_id=None):
    args = schemas.args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _USERS_COLUMNS, ['password'])
    # If it's not an admin, then get only the users of the caller's team
    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.team_id == user['team_id'])

    if team_id is not None:
        query.add_extra_condition(_TABLE.c.team_id == team_id)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'users': rows, '_meta': {'count': nb_rows}})
Beispiel #15
0
def get_all_jobstates(user, job_id):
    """Get all jobstates.
    """
    args = check_and_get_args(flask.request.args.to_dict())
    job = v1_utils.verify_existence_and_get(job_id, models.JOBS)
    if (user.is_not_super_admin() and user.is_not_read_only_user()
            and user.is_not_epm()):
        if job['team_id'] not in user.teams_ids:
            raise dci_exc.Unauthorized()

    query = v1_utils.QueryBuilder(_TABLE, args, _JS_COLUMNS)
    query.add_extra_condition(_TABLE.c.job_id == job_id)

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)
    return flask.jsonify({'jobstates': rows, '_meta': {'count': nb_rows}})
Beispiel #16
0
def _get_job(user, job_id, embed):
    # build the query thanks to the QueryBuilder class
    args = {'embed': embed}
    query = v1_utils.QueryBuilder(_TABLE, args, _JOBS_COLUMNS)

    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))

    query.add_extra_condition(_TABLE.c.id == job_id)
    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)
    if len(rows) != 1:
        raise dci_exc.DCINotFound('Job', job_id)
    job = rows[0]
    return job, nb_rows
Beispiel #17
0
def get_all_files(user, j_id=None):
    """Get all files.
    """
    args = schemas.args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _FILES_COLUMNS)

    # If it's not an admin then restrict the view to the team's file
    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))
    if j_id is not None:
        query.add_extra_condition(_TABLE.c.job_id == j_id)
    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)
    return json.jsonify({'files': rows, '_meta': {'count': nb_rows}})
Beispiel #18
0
def get_all_remotecis(user, t_id=None):
    args = schemas.args(flask.request.args.to_dict())

    # build the query thanks to the QueryBuilder class
    query = v1_utils.QueryBuilder(_TABLE, args, _R_COLUMNS)

    if not user.is_super_admin():
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams))

    if t_id is not None:
        query.add_extra_condition(_TABLE.c.team_id == t_id)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'remotecis': rows, '_meta': {'count': len(rows)}})
Beispiel #19
0
def get_all_topics(user):
    def _get_user_product_ids():
        _JPT = models.JOIN_PRODUCTS_TEAMS
        query = v1_utils.QueryBuilder(
            models.PRODUCTS,
            {},
            {},
            root_join_table=_JPT,
            root_join_condition=sql.and_(
                _JPT.c.product_id == models.PRODUCTS.c.id,  # noqa
                _JPT.c.team_id.in_(user.teams_ids)))  # noqa
        user_products = query.execute(fetchall=True)
        return [up['products_id'] for up in user_products]

    args = check_and_get_args(flask.request.args.to_dict())
    # if the user is an admin then he can get all the topics
    q_get_topics = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)

    if (user.is_not_super_admin() and user.is_not_read_only_user()
            and user.is_not_epm()):
        if 'teams' in args['embed']:
            raise dci_exc.DCIException('embed=teams not authorized.',
                                       status_code=401)
        # if regular user, retrieve the topics associated to the user's team
        # get only topics with export_control==True or with explicit association
        # between the user's teams and the topic
        product_ids = _get_user_product_ids()
        q_get_topics.add_extra_condition(_TABLE.c.product_id.in_(product_ids))
        q_get_topics.add_extra_condition(
            sql.or_(
                _TABLE.c.export_control == True,  # noqa
                _TABLE.c.id.in_(v1_utils.user_topic_ids(user))))  # noqa

    q_get_topics.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = q_get_topics.get_number_of_rows()
    rows = q_get_topics.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'topics': rows, '_meta': {'count': nb_rows}})
def get_all_topics(user):
    args = schemas.args(flask.request.args.to_dict())
    # if the user is an admin then he can get all the topics
    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)

    if not auth.is_admin(user):
        if 'teams' in args['embed']:
            raise dci_exc.DCIException('embed=teams not authorized.',
                                       status_code=401)
        query.add_extra_condition(
            _TABLE.c.id.in_(v1_utils.user_topic_ids(user)))  # noqa
    query.add_extra_condition(_TABLE.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'topics': rows, '_meta': {'count': nb_rows}})
Beispiel #21
0
def get_all_jobstates(user, j_id=None):
    """Get all jobstates.
    """
    args = schemas.args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _JS_COLUMNS)
    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.team_id == user['team_id'])

    # used for counting the number of rows when j_id is not None
    if j_id is not None:
        query.add_extra_condition(_TABLE.c.job_id == j_id)

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'jobstates': rows, '_meta': {'count': nb_rows}})
Beispiel #22
0
def get_all_roles(user):
    args = schemas.args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _T_COLUMNS)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.label != 'SUPER_ADMIN')

    if user['role_id'] not in [
            auth.get_role_id('ADMIN'),
            auth.get_role_id('SUPER_ADMIN')
    ]:
        query.add_extra_condition(_TABLE.c.id == user['role_id'])

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'roles': rows, '_meta': {'count': nb_rows}})
Beispiel #23
0
def get_logs(user):
    args = schemas.args(flask.request.args.to_dict())

    if user['role_id'] not in [
            auth.get_role_id('ADMIN'),
            auth.get_role_id('SUPER_ADMIN')
    ]:
        raise auth.UNAUTHORIZED

    if args['limit'] is None:
        args['limit'] = 10

    query = v1_utils.QueryBuilder(_TABLE, args, _A_COLUMNS)

    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.team_id == user['team_id'])

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'], None)

    return flask.jsonify({'audits': rows, '_meta': {'count': nb_rows}})
Beispiel #24
0
def list_jobdefinitions(user, topic_ids, by_topic):
    """Get all jobdefinitions.

    If topic_id is not None, then return all the jobdefinitions with a topic
    pointed by topic_id.
    """
    # get the diverse parameters
    args = schemas.args(flask.request.args.to_dict())

    query = v1_utils.QueryBuilder(_TABLE, args, _JD_COLUMNS)

    if by_topic or not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.topic_id.in_(topic_ids))

    query.add_extra_condition(_TABLE.c.state != 'archived')

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'jobdefinitions': rows, '_meta': {'count': nb_rows}})
def get_users_from_team(user, team_id):
    args = check_and_get_args(flask.request.args.to_dict())
    _JUTR = models.JOIN_USERS_TEAMS
    query = v1_utils.QueryBuilder(
        models.USERS,
        args,
        users._USERS_COLUMNS,
        ['password', 'team_id'],
        root_join_table=_JUTR,
        root_join_condition=sql.and_(
            _JUTR.c.user_id == models.USERS.c.id,  # noqa
            _JUTR.c.team_id == team_id))  # noqa

    if user.is_not_epm() and user.is_not_in_team(team_id):
        raise dci_exc.Unauthorized()

    query.add_extra_condition(models.USERS.c.state != 'archived')

    rows = query.execute(fetchall=True)
    team_users = v1_utils.format_result(rows, models.USERS.name, args['embed'],
                                        users._EMBED_MANY)

    return flask.jsonify({'users': team_users, '_meta': {'count': len(rows)}})
Beispiel #26
0
def get_all_components(user, topic_id):
    """Get all components of a topic."""

    args = schemas.args(flask.request.args.to_dict())

    v1_utils.verify_team_in_topic(user, topic_id)

    query = v1_utils.QueryBuilder(_TABLE, args, _C_COLUMNS)

    query.add_extra_condition(
        sql.and_(_TABLE.c.topic_id == topic_id, _TABLE.c.state != 'archived'))

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    # Return only the component which have the export_control flag set to true
    #
    if not (auth.is_admin(user)):
        rows = [row for row in rows if row['export_control']]

    return flask.jsonify({'components': rows, '_meta': {'count': nb_rows}})
Beispiel #27
0
def get_all_remotecis(user, t_id=None):
    args = check_and_get_args(flask.request.args.to_dict())

    # build the query thanks to the QueryBuilder class
    query = v1_utils.QueryBuilder(_TABLE,
                                  args,
                                  _R_COLUMNS,
                                  ignore_columns=['keys', 'cert_fp'])

    if (user.is_not_super_admin() and user.is_not_read_only_user()
            and user.is_not_epm()):
        query.add_extra_condition(_TABLE.c.team_id.in_(user.teams_ids))

    if t_id is not None:
        query.add_extra_condition(_TABLE.c.team_id == t_id)

    query.add_extra_condition(_TABLE.c.state != 'archived')

    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'remotecis': rows, '_meta': {'count': len(rows)}})
Beispiel #28
0
def get_resource_by_id(user,
                       resource,
                       table,
                       embed_many=None,
                       ignore_columns=None,
                       resource_name=None,
                       embeds=None,
                       jsonify=True):
    args = check_and_get_args(flask.request.args.to_dict())
    if embeds is not None:
        # make a copy of the list to avoid side effect
        args['embed'] = args['embed'] + list(embeds)
    resource_name = resource_name or table.name[0:-1]
    resource_id = resource['id']
    columns = v1_utils.get_columns_name_with_objects(table)

    query = v1_utils.QueryBuilder(table, args, columns, ignore_columns)

    if 'state' in resource:
        query.add_extra_condition(table.c.state != 'archived')

    query.add_extra_condition(table.c.id == resource_id)

    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, table.name, args['embed'], embed_many)

    if len(rows) < 1:
        raise dci_exc.DCINotFound(resource_name, resource_id)
    resource = rows[0]

    if jsonify is True:
        res = flask.jsonify({resource_name: resource})
        if 'etag' in resource:
            res.headers.add_header('ETag', resource['etag'])
        return res
    else:
        return resource
Beispiel #29
0
def search_jobs(user):
    values = schemas.job_search.post(flask.request.json)
    jobdefinition_id = values.get('jobdefinition_id')
    configuration = values.get('configuration')
    config_op = configuration.pop('_op', 'and')

    args = schemas.args(flask.request.args.to_dict())
    query = v1_utils.QueryBuilder(_TABLE, args, _JOBS_COLUMNS,
                                  ['configuration'])

    # If it's not an admin then restrict the view to the team's file
    if not auth.is_admin(user):
        query.add_extra_condition(_TABLE.c.team_id == user['team_id'])

    if jobdefinition_id is not None:
        query.add_extra_condition(_TABLE.c.jobdefinition_id == jobdefinition_id)  # noqa

    if config_op == 'and':
        sa_op = sql.expression.and_
    elif config_op == 'or':
        sa_op = sql.expression.or_

    filering_rules = []
    for k, v in six.iteritems(configuration):
        path = []
        for sk in k.split('.'):
            path.append(sk)
        filering_rules.append(_TABLE.c.configuration[path].astext == v)
    query.add_extra_condition(sa_op(*filering_rules))

    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    rows = v1_utils.format_result(rows, _TABLE.name, args['embed'],
                                  _EMBED_MANY)

    return flask.jsonify({'jobs': rows, '_meta': {'count': nb_rows}})
def get_teams_of_user(user, user_id):
    args = check_and_get_args(flask.request.args.to_dict())
    _JUTR = models.JOIN_USERS_TEAMS
    query = v1_utils.QueryBuilder(
        models.TEAMS,
        args,
        teams._T_COLUMNS,
        root_join_table=_JUTR,
        root_join_condition=sql.and_(
            _JUTR.c.team_id == models.TEAMS.c.id,  # noqa
            _JUTR.c.user_id == user_id))  # noqa

    if user.is_not_super_admin() and user.id != user_id and user.is_not_epm():
        raise dci_exc.Unauthorized()

    query.add_extra_condition(models.TEAMS.c.state != 'archived')

    # get the number of rows for the '_meta' section
    nb_rows = query.get_number_of_rows()
    rows = query.execute(fetchall=True)
    users_teams = v1_utils.format_result(rows, models.TEAMS.name,
                                         args['embed'], teams._EMBED_MANY)

    return flask.jsonify({'teams': users_teams, '_meta': {'count': nb_rows}})