Example #1
0
def admin_serialize_context(store, context, language=GLSetting.memory_copy.default_language):

    steps = [ anon_serialize_step(store, s, language)
              for s in context.steps.order_by(models.Step.number) ]

    ret_dict = {
        "id": context.id,
        "creation_date": datetime_to_ISO8601(context.creation_date),
        "last_update": datetime_to_ISO8601(context.last_update),
        "selectable_receiver": context.selectable_receiver,
        "tip_max_access": context.tip_max_access,
        "file_max_download": context.file_max_download,
        "receivers": [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        "tip_timetolive": context.tip_timetolive / (60 * 60 * 24),
        "submission_timetolive": context.submission_timetolive / (60 * 60),
        "select_all_receivers": context.select_all_receivers,
        "postpone_superpower": context.postpone_superpower,
        "can_delete_submission": context.can_delete_submission,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
        "steps": steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Example #2
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language) for s in context.steps]

    ret_dict = {
        'id': context.id,
        'receivers': [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_small_cards': context.show_small_cards,
        'show_receivers': context.show_receivers,
        'enable_comments': context.enable_comments,
        'enable_private_messages': context.enable_private_messages,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'steps_arrangement': context.steps_arrangement,
        'reset_steps': False,
        'steps': steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Example #3
0
def update_step(store, step_id, request, language):
    """
    Update the specified step with the details.
    raises :class:`globaleaks.errors.StepIdNotFound` if the step does
    not exist.

    :param store: the store on which perform queries.
    :param step_id: the step_id of the step to update
    :param request: the step definition dict
    :param language: the language of the step definition dict
    :return: a serialization of the object
    """
    step = models.Step.get(store, step_id)
    try:
        if not step:
            raise errors.StepIdNotFound

        fill_localized_keys(request, models.Step.localized_strings, language)

        step.update(request)

        for child in request['children']:
            db_update_field(store, child['id'], child, language)

    except Exception as dberror:
        log.err('Unable to update step: {e}'.format(e=dberror))
        raise errors.InvalidInputFormat(dberror)

    return anon_serialize_step(store, step, language)
Example #4
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language)
                for s in context.steps.order_by(models.Step.number)]

    ret_dict = {
        'id': context.id,
        'creation_date': datetime_to_ISO8601(context.creation_date),
        'last_update': datetime_to_ISO8601(context.last_update),
        'receivers': [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'can_postpone_expiration': context.can_postpone_expiration,
        'can_delete_submission': context.can_delete_submission,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_small_cards': context.show_small_cards,
        'show_receivers': context.show_receivers,
        'enable_private_messages': context.enable_private_messages,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'reset_steps': False,
        'steps': steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Example #5
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    ret_dict = {
        'id': context.id,
        'custodians': [c.id for c in context.custodians],
        'receivers': [r.id for r in context.receivers],
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_context': context.show_context,
        'show_receivers': context.show_receivers,
        'show_small_cards': context.show_small_cards,
        'enable_comments': context.enable_comments,
        'enable_messages': context.enable_messages,
        'enable_two_way_comments': context.enable_two_way_comments,
        'enable_two_way_messages': context.enable_two_way_messages,
        'enable_attachments': context.enable_attachments,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order':
        context.show_receivers_in_alphabetical_order,
        'questionnaire_layout': context.questionnaire_layout,
        'reset_questionnaire': False,
        'steps':
        [anon_serialize_step(store, s, language) for s in context.steps]
    }

    return get_localized_values(ret_dict, context, context.localized_keys,
                                language)
Example #6
0
def create_step(store, step, language):
    """
    Transaction that perform db_create_step
    """
    s = db_create_step(store, step, language)

    return anon_serialize_step(store, s, language)
Example #7
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language)
           for s in context.steps.order_by(models.Step.number)]

    ret_dict = {
        "id": context.id,
        "creation_date": datetime_to_ISO8601(context.creation_date),
        "last_update": datetime_to_ISO8601(context.last_update),
        "tip_max_access": context.tip_max_access,
        "file_max_download": context.file_max_download,
        "receivers": [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        "tip_timetolive": context.tip_timetolive / (60 * 60 * 24),
        "submission_timetolive": context.submission_timetolive / (60 * 60),
        "select_all_receivers": context.select_all_receivers,
        "postpone_superpower": context.postpone_superpower,
        "can_delete_submission": context.can_delete_submission,
        "maximum_selectable_receivers": context.maximum_selectable_receivers,
        "show_small_cards": context.show_small_cards,
        "show_receivers": context.show_receivers,
        "enable_private_messages": context.enable_private_messages,
        "presentation_order": context.presentation_order,
        "steps": steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings, language)
Example #8
0
def update_step(store, step_id, request, language):
    """
    Update the specified step with the details.
    raises :class:`globaleaks.errors.StepIdNotFound` if the step does
    not exist.

    :param store: the store on which perform queries.
    :param step_id: the step_id of the step to update
    :param request: the step definition dict
    :param language: the language of the step definition dict
    :return: a serialization of the object
    """
    step = models.Step.get(store, step_id)
    try:
        if not step:
            raise errors.StepIdNotFound

        fill_localized_keys(request, models.Step.localized_strings, language)

        step.update(request)

        for child in request['children']:
            db_update_field(store, child['id'], child, language)

    except Exception as dberror:
        log.err('Unable to update step: {e}'.format(e=dberror))
        raise errors.InvalidInputFormat(dberror)

    return anon_serialize_step(store, step, language)
Example #9
0
def create_step(store, step, language):
    """
    Transaction that perform db_create_step
    """
    s = db_create_step(store, step, language)

    return anon_serialize_step(store, s, language)
Example #10
0
def admin_serialize_context(store, context, language):
    """
    Serialize the specified context

    :param store: the store on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    steps = [anon_serialize_step(store, s, language) for s in context.steps]

    ret_dict = {
        'id': context.id,
        'receivers': [r.id for r in context.receivers],
        # tip expressed in day, submission in hours
        'tip_timetolive': context.tip_timetolive / (60 * 60 * 24),
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_small_cards': context.show_small_cards,
        'show_receivers': context.show_receivers,
        'enable_comments': context.enable_comments,
        'enable_private_messages': context.enable_private_messages,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order':
        context.show_receivers_in_alphabetical_order,
        'steps_arrangement': context.steps_arrangement,
        'reset_steps': False,
        'steps': steps
    }

    return get_localized_values(ret_dict, context, context.localized_strings,
                                language)
Example #11
0
def db_get_context_steps(store, context_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the context with the specified id.
    """
    context = store.find(models.Context, models.Context.id == context_id).one()

    if not context:
        log.err("Requested invalid context")
        raise errors.ContextIdNotFound

    return [anon_serialize_step(store, s, language) for s in context.steps]
Example #12
0
def db_get_context_steps(store, context_id, language):
    """
    Returns:
        (dict) the questionnaire associated with the context with the specified id.
    """
    context = store.find(models.Context, models.Context.id == context_id).one()

    if not context:
        log.err("Requested invalid context")
        raise errors.ContextIdNotFound

    return [anon_serialize_step(store, s, language) for s in context.steps]
Example #13
0
def get_step(store, step_id, language):
    """
    Serialize the specified step

    :param store: the store on which perform queries.
    :param step_id: the id corresponding to the step.
    :param language: the language in which to localize data
    :return: the currently configured step.
    :rtype: dict
    """
    step = store.find(models.Step, models.Step.id == step_id).one()
    if not step:
        raise errors.StepIdNotFound

    return anon_serialize_step(store, step, language)
Example #14
0
def get_step(store, step_id, language):
    """
    Serialize the specified step

    :param store: the store on which perform queries.
    :param step_id: the id corresponding to the step.
    :param language: the language in which to localize data
    :return: the currently configured step.
    :rtype: dict
    """
    step = store.find(models.Step, models.Step.id == step_id).one()
    if not step:
        raise errors.StepIdNotFound

    return anon_serialize_step(store, step, language)
Example #15
0
def update_step(store, step_id, request, language):
    return anon_serialize_step(
        store, db_update_step(store, step_id, request, language), language)
Example #16
0
def update_step(store, step_id, request, language):
    return anon_serialize_step(store, db_update_step(store, step_id, request, language), language)