Esempio 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}))
Esempio n. 2
0
def delete_users(request):
    if request.method == 'GET':
        raise Http404

    django_ids = request.POST.get("all_ids").split(";")
    all_ids = NGOUserProfile.objects.filter(user__in=django_ids).values_list(
        'reporter_id', flat=True)
    manager = get_database_manager(request.user)
    organization = get_organization(request)
    transport_info = TransportInfo("web", request.user.username, "")
    ngo_admin_user_profile = get_ngo_admin_user_profiles_for(organization)[0]

    if ngo_admin_user_profile.reporter_id in all_ids:
        messages.error(
            request,
            _("Your organization's account Administrator %s cannot be deleted")
            % (ngo_admin_user_profile.user.first_name), "error_message")
    else:
        detail = user_activity_log_details(
            User.objects.filter(id__in=django_ids))
        delete_datasenders_from_project(manager, all_ids)
        for user_id in django_ids:
            handle_feature_toggle_impact_for_deleted_user(user_id)

        delete_entity_instance(manager, all_ids, REPORTER, transport_info)
        delete_datasender_users_if_any(all_ids, organization)

        if organization.in_trial_mode:
            delete_datasender_for_trial_mode(manager, all_ids, REPORTER)
        action = DELETED_USERS
        UserActivityLog().log(request, action=action, detail=detail)
        messages.success(request, _("User(s) successfully deleted."))

    return HttpResponse(json.dumps({'success': True}))
Esempio n. 3
0
    def test_should_delete_a_datasender_from_associated_projects(self):
        entity_ids = ['rep1', 'rep2']
        with patch("datawinners.project.models.Project") as mock_project_class:
            mock_project = Mock(spec=Project)
            mock_project_class.get.return_value = mock_project
            with patch("datawinners.project.models.get_all_projects"
                       ) as all_projects:
                all_projects.return_value = [{'value': {'_id': 1}}]
                dbm = Mock()
                dbm.database.return_value = ''

                delete_datasenders_from_project(dbm, entity_ids)

                self.assertEqual(mock_project.delete_datasender.call_count, 2)