Ejemplo n.º 1
0
def delete_data_senders(request):
    manager = get_database_manager(request.user)
    organization = get_organization(request)
    entity_type = request.POST['entity_type']
    all_ids = data_sender_short_codes(request, manager)
    superusers = rep_id_name_dict_of_users(manager)
    non_superuser_rep_ids = [
        id for id in all_ids if id not in superusers.keys()
    ]
    transport_info = TransportInfo("web", request.user.username, "")

    delete_datasenders_from_project(manager, non_superuser_rep_ids)
    delete_entity_instance(manager, non_superuser_rep_ids, entity_type,
                           transport_info)
    delete_datasender_users_if_any(non_superuser_rep_ids, organization)
    if organization.in_trial_mode:
        delete_datasender_for_trial_mode(manager, non_superuser_rep_ids,
                                         entity_type)
    log_activity(
        request,
        DELETED_DATA_SENDERS,
        "%s: [%s]" %
        (entity_type.capitalize(), ", ".join(non_superuser_rep_ids)),
    )
    messages = get_success_message(entity_type)
    return HttpResponse(json.dumps({'success': True, 'message': messages}))
Ejemplo n.º 2
0
def _soft_delete_unique_ids(all_ids, entity_type, dbm, request):
    if all_ids:
        transport_info = TransportInfo("web", request.user.username, "")
        delete_entity_instance(dbm, all_ids, entity_type, transport_info)
        _log_soft_deleted_unique_ids(all_ids, dbm, entity_type)
        log_activity(
            request, DELETED_IDENTIFICATION_NUMBER,
            "%s: [%s]" % (entity_type.capitalize(), ", ".join(all_ids)))
Ejemplo n.º 3
0
def _hard_delete_unique_ids(unique_ids, dbm, form_model, request):
    for unique_id in unique_ids:
        entity = get_by_short_code(dbm, unique_id, form_model.entity_type)
        _delete_unique_id_from_elastic_search(dbm, form_model.entity_type[0],
                                              entity.id)
        delete_data_record(dbm, form_model.form_code, unique_id)
        dbm._save_document(
            EntityActionDocument(form_model.entity_type[0], unique_id,
                                 HARD_DELETE))
        entity.delete()
    if unique_ids:
        _refresh_elastic_search_index(dbm)
        log_activity(
            request, DELETED_IDENTIFICATION_NUMBER,
            "%s: [%s]" % (request.POST['entity_type'], ", ".join(unique_ids)))