Exemplo n.º 1
0
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}})
Exemplo n.º 2
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
Exemplo n.º 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}})
Exemplo n.º 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}})
Exemplo n.º 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}})
Exemplo n.º 6
0
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}})
Exemplo n.º 7
0
 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]
Exemplo n.º 8
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}})
Exemplo n.º 9
0
def get_remoteci_data_json(user, r_id):
    query = v1_utils.QueryBuilder(_TABLE, {}, _R_COLUMNS)

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

    query.add_extra_condition(_TABLE.c.id == r_id)
    row = query.execute(fetchone=True)

    if row is None:
        raise dci_exc.DCINotFound('RemoteCI', r_id)

    return row['remotecis_data']
Exemplo n.º 10
0
def get_remoteci_data_json(user, r_id):
    query = v1_utils.QueryBuilder(_TABLE, {}, _R_COLUMNS)

    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.id == r_id)
    row = query.execute(fetchone=True)

    if row is None:
        raise dci_exc.DCINotFound('RemoteCI', r_id)

    return row['remotecis_data']
Exemplo n.º 11
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}})
Exemplo n.º 12
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)}})
Exemplo n.º 13
0
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}})
Exemplo n.º 14
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}})
Exemplo n.º 15
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}})
Exemplo n.º 16
0
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}})
Exemplo n.º 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}})
Exemplo n.º 18
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
Exemplo n.º 19
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)}})
Exemplo n.º 20
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}})
Exemplo n.º 21
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}})
Exemplo n.º 22
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}})
Exemplo n.º 23
0
def purge_archived_components(user):

    # get all archived components
    archived_components = base.get_archived_resources(_TABLE)

    store = dci_config.get_store('components')

    # for each component delete it and all the component_files associated
    # from within a transaction
    # if the SQL deletion or the Store deletion fail then
    # rollback the transaction, otherwise commit.
    for cmpt in archived_components:
        get_cmpt_files = v1_utils.QueryBuilder(models.COMPONENT_FILES)
        get_cmpt_files.add_extra_condition(
            models.COMPONENT_FILES.c.component_id == cmpt['id'])
        cmpt_files = get_cmpt_files.execute(fetchall=True, use_labels=False)
        for cmpt_file in cmpt_files:
            tx = flask.g.db_conn.begin()
            file_path = files_utils.build_file_path(cmpt['topic_id'],
                                                    cmpt['id'],
                                                    cmpt_file['id'])
            try:
                q_delete_cfile = models.COMPONENT_FILES.delete().\
                    where(models.COMPONENT_FILES.c.id == cmpt_file['id'])
                flask.g.db_conn.execute(q_delete_cfile)
                store.delete(file_path)
                tx.commit()
            except dci_exc.StoreExceptions as e:
                if e.status_code == 404:
                    LOG.warn('file %s not found in store' % file_path)
                else:
                    raise e
            except Exception as e:
                tx.rollback()
                LOG.error(
                    'Error while removing component file %s, message: %s' %
                    (file_path, str(e)))
                raise dci_exc.DCIException(str(e))
        flask.g.db_conn.execute(
            _TABLE.delete().where(_TABLE.c.id == cmpt['id']))

    return flask.Response(None, 204, content_type='application/json')
Exemplo n.º 24
0
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}})
Exemplo n.º 25
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}})
Exemplo n.º 26
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}})
Exemplo n.º 27
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}})
Exemplo n.º 28
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}})
Exemplo n.º 29
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)}})
Exemplo n.º 30
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}})