Exemple #1
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.
    """
    receivers = [id for id in store.find(models.ReceiverContext.receiver_id, models.ReceiverContext.context_id == context.id)]
    picture = db_get_model_img(store, models.Context, context.id)

    ret_dict = {
        'id': context.id,
        'tip_timetolive': context.tip_timetolive,
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_context': context.show_context,
        'show_recipients_details': context.show_recipients_details,
        'allow_recipients_selection': context.allow_recipients_selection,
        'show_small_receiver_cards': context.show_small_receiver_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,
        'enable_rc_to_wb_files': context.enable_rc_to_wb_files,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'questionnaire_id': context.questionnaire_id,
        'receivers': receivers,
        'picture': picture
    }

    return get_localized_values(ret_dict, context, context.localized_keys, language)
Exemple #2
0
def user_serialize_user(session, user, language):
    """
    Serialize user description

    :param session: the session on which perform queries.
    :param username: the username of the user to be serialized
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, user.tid, 'users', user.id)

    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': u'',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Exemple #3
0
def user_serialize_user(session, user, language):
    """
    Serialize user model

    :param user: the user object
    :param language: the language of the data
    :param session: the session on which perform queries.
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, 'users', user.id)

    # take only contexts for the current tenant
    contexts = [x[0] for x in session.query(models.ReceiverContext.context_id)
                                     .filter(models.ReceiverContext.receiver_id == user.id)]
    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': '',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'public_name': user.public_name,
        'mail_address': user.mail_address,
        'change_email_address': user.change_email_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture,
        'can_edit_general_settings': user.can_edit_general_settings,
        'tid': user.tid,
        'notification': user.notification,
        'encryption': user.crypto_pub_key != '',
        'escrow': user.crypto_escrow_prv_key != '',
        'two_factor_enable': user.two_factor_enable,
        'recipient_configuration': user.recipient_configuration,
        'can_postpone_expiration': user.can_postpone_expiration,
        'can_delete_submission': user.can_delete_submission,
        'can_grant_permissions': user.can_grant_permissions,
        'contexts': contexts,
        'send_account_activation_link': False
    }

    if user.tid in State.tenant_cache:
        ret_dict.update({
            'can_postpone_expiration': State.tenant_cache[user.tid].can_postpone_expiration or user.can_postpone_expiration,
            'can_delete_submission': State.tenant_cache[user.tid].can_delete_submission or user.can_delete_submission,
            'can_grant_permissions': State.tenant_cache[user.tid].can_grant_permissions or user.can_grant_permissions
        })

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Exemple #4
0
def admin_serialize_context(session, context, language):
    """
    Serialize the specified context

    :param session: the session on which perform queries
    :param context: The object to be serialized
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    receivers = [
        r[0] for r in session.query(models.ReceiverContext.receiver_id).filter(
            models.ReceiverContext.context_id == context.id).order_by(
                models.ReceiverContext.order)
    ]

    picture = db_get_model_img(session, 'contexts', context.id)

    ret_dict = {
        'id': context.id,
        'status': context.status,
        'languages': context.languages,
        'tip_timetolive': context.tip_timetolive,
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_recipients_details': context.show_recipients_details,
        'allow_recipients_selection': context.allow_recipients_selection,
        'show_small_receiver_cards': context.show_small_receiver_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,
        'enable_rc_to_wb_files': context.enable_rc_to_wb_files,
        'score_threshold_medium': context.score_threshold_medium,
        'score_threshold_high': context.score_threshold_high,
        'score_receipt_text_custom': context.score_receipt_text_custom,
        'score_receipt_text_l': context.score_receipt_text_l,
        'score_receipt_text_m': context.score_receipt_text_m,
        'score_receipt_text_h': context.score_receipt_text_h,
        'score_threshold_receipt': context.score_threshold_receipt,
        'order': context.order,
        'show_receivers_in_alphabetical_order':
        context.show_receivers_in_alphabetical_order,
        'show_steps_navigation_interface':
        context.show_steps_navigation_interface,
        'questionnaire_id': context.questionnaire_id,
        'additional_questionnaire_id': context.additional_questionnaire_id,
        'receivers': receivers,
        'picture': picture
    }

    return get_localized_values(ret_dict, context, context.localized_keys,
                                language)
Exemple #5
0
def admin_serialize_context(session, context, language):
    """
    Serialize the specified context

    :param session: the session on which perform queries.
    :param language: the language in which to localize data.
    :return: a dictionary representing the serialization of the context.
    """
    receivers = [r[0] for r in session.query(models.ReceiverContext.receiver_id)
                                      .filter(models.ReceiverContext.context_id == context.id)
                                      .order_by(models.ReceiverContext.presentation_order)]
    picture = db_get_model_img(session, 'contexts', context.id)

    ret_dict = {
        'id': context.id,
        'status': context.status,
        'tip_timetolive': context.tip_timetolive,
        'select_all_receivers': context.select_all_receivers,
        'maximum_selectable_receivers': context.maximum_selectable_receivers,
        'show_recipients_details': context.show_recipients_details,
        'allow_recipients_selection': context.allow_recipients_selection,
        'show_small_receiver_cards': context.show_small_receiver_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,
        'enable_rc_to_wb_files': context.enable_rc_to_wb_files,
        'enable_scoring_system': context.enable_scoring_system,
        'score_threshold_medium': context.score_threshold_medium,
        'score_threshold_high': context.score_threshold_high,
        'score_receipt_text_custom': context.score_receipt_text_custom,
        'score_receipt_text_l': context.score_receipt_text_l,
        'score_receipt_text_m': context.score_receipt_text_m,
        'score_receipt_text_h': context.score_receipt_text_h,
        'score_threshold_receipt': context.score_threshold_receipt,
        'presentation_order': context.presentation_order,
        'show_receivers_in_alphabetical_order': context.show_receivers_in_alphabetical_order,
        'show_steps_navigation_interface': context.show_steps_navigation_interface,
        'questionnaire_id': context.questionnaire_id,
        'additional_questionnaire_id': context.additional_questionnaire_id,
        'receivers': receivers,
        'picture': picture
    }

    return get_localized_values(ret_dict, context, context.localized_keys, language)
Exemple #6
0
def user_serialize_user(session, user, language):
    """
    Serialize user description

    :param user:
    :param language:
    :param session: the session on which perform queries.
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, 'users', user.id)

    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': '',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'change_email_address': user.change_email_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture,
        'can_edit_general_settings': user.can_edit_general_settings,
        'can_delete_submission': user.can_delete_submission,
        'can_postpone_expiration': user.can_postpone_expiration,
        'can_grant_permissions': user.can_grant_permissions,
        'recipient_configuration': user.recipient_configuration,
        'tid': user.tid,
        'notification': user.notification,
        'encryption': user.crypto_pub_key != b'',
        'two_factor_enable': user.two_factor_enable
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)
Exemple #7
0
def user_serialize_user(session, user, language):
    """
    Serialize user description

    :param session: the session on which perform queries.
    :param username: the username of the user to be serialized
    :return: a serialization of the object
    """
    picture = db_get_model_img(session, 'users', user.id)
    user_tenants = db_get_usertenant_associations(session, user)

    ret_dict = {
        'id': user.id,
        'username': user.username,
        'password': '',
        'old_password': u'',
        'salt': '',
        'role': user.role,
        'state': user.state,
        'last_login': datetime_to_ISO8601(user.last_login),
        'name': user.name,
        'description': user.description,
        'mail_address': user.mail_address,
        'change_email_address': user.change_email_address,
        'language': user.language,
        'password_change_needed': user.password_change_needed,
        'password_change_date': datetime_to_ISO8601(user.password_change_date),
        'pgp_key_fingerprint': user.pgp_key_fingerprint,
        'pgp_key_public': user.pgp_key_public,
        'pgp_key_expiration': datetime_to_ISO8601(user.pgp_key_expiration),
        'pgp_key_remove': False,
        'picture': picture,
        'can_edit_general_settings': user.can_edit_general_settings,
        'can_delete_submission': user.can_delete_submission,
        'can_postpone_expiration': user.can_postpone_expiration,
        'can_grant_permissions': user.can_grant_permissions,
        'recipient_configuration': user.recipient_configuration,
        'tid': user.tid,
        'notification': user.notification,
        'usertenant_assocations': user_tenants
    }

    return get_localized_values(ret_dict, user, user.localized_keys, language)