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}))
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}))
def delete_entity(request): manager = get_database_manager(request.user) organization = get_organization(request) transport_info = TransportInfo("web", request.user.username, "") entity_type = request.POST['entity_type'] project = request.POST.get("project", "") all_ids = request.POST['all_ids'].split(';') 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") % (_get_full_name(ngo_admin_user_profile.user)), "error_message") else: delete_entity_instance(manager, all_ids, entity_type, transport_info) if entity_type == REPORTER: delete_datasender_from_project(manager, all_ids) delete_datasender_users_if_any(all_ids, organization) if organization.in_trial_mode: delete_datasender_for_trial_mode(manager, all_ids, entity_type) action = DELETED_DATA_SENDERS else: action = DELETED_SUBJECTS UserActivityLog().log(request, action=action, detail="%s: [%s]" % (entity_type.capitalize(), ", ".join(all_ids)), project=project.capitalize()) messages.success(request, get_success_message(entity_type)) return HttpResponse(json.dumps({'success': True}))
def roll_back_user_creation(user, reporter_id, role, organization): manager = get_database_manager(user) transport_info = TransportInfo("web", user.username, "") dissociate_user_as_datasender_with_projects(reporter_id, user, role, []) if organization.in_trial_mode: delete_datasender_for_trial_mode(manager, [reporter_id], REPORTER) delete_entity_instance(manager, [reporter_id], REPORTER, transport_info) delete_datasender_users_if_any([reporter_id], organization) user.delete()
def _delete_user_entry(profiles): user_profile = profiles[0] profile_reporter_id = user_profile.reporter_id if profile_reporter_id.lower() == profile_reporter_id: print "Not deleting user since the reporter id is already lowercase." else: entity_to_be_deleted = get_by_short_code_include_voided( dbm, profile_reporter_id.lower(), ['reporter']) print "User void status:%s" % entity_to_be_deleted.is_void() if entity_to_be_deleted.is_void(): print "Deleting user." user_profile.user.delete() if organization.in_trial_mode: delete_datasender_for_trial_mode(dbm, [profile_reporter_id.lower()], 'reporter') else: print "Not deleting user since it is not soft deleted."