From 8728df10b9ffe0a007becfd628a164d19b8380b9 Mon Sep 17 00:00:00 2001 From: Xavier Fernandez Date: Thu, 19 Dec 2024 08:35:42 +0100 Subject: [PATCH] job_applications: fix is_active_company_member to check that the membership is still active --- itou/job_applications/models.py | 9 +- tests/job_applications/tests.py | 16 + .../www/apply/__snapshots__/test_process.ambr | 1256 +++++++++-------- 3 files changed, 659 insertions(+), 622 deletions(-) diff --git a/itou/job_applications/models.py b/itou/job_applications/models.py index a4a068ceef..f2de72e25a 100644 --- a/itou/job_applications/models.py +++ b/itou/job_applications/models.py @@ -14,6 +14,7 @@ from itou.approvals.models import Approval, Suspension from itou.approvals.notifications import PassAcceptedEmployerNotification from itou.companies.enums import SIAE_WITH_CONVENTION_KINDS, CompanyKind, ContractType +from itou.companies.models import CompanyMembership from itou.eligibility.enums import AuthorKind from itou.eligibility.models import EligibilityDiagnosis, SelectedAdministrativeCriteria from itou.job_applications.enums import ( @@ -134,7 +135,13 @@ class JobApplicationWorkflow(xwf_models.Workflow): class JobApplicationQuerySet(models.QuerySet): def is_active_company_member(self, user): - return self.filter(to_company__members=user, to_company__members__is_active=True) + return self.filter( + Exists( + CompanyMembership.objects.filter( + user=user, is_active=True, user__is_active=True, company=OuterRef("to_company") + ) + ) + ) def pending(self): return self.filter(state__in=JobApplicationWorkflow.PENDING_STATES) diff --git a/tests/job_applications/tests.py b/tests/job_applications/tests.py index 4305ff36bf..da8a00f92a 100644 --- a/tests/job_applications/tests.py +++ b/tests/job_applications/tests.py @@ -166,6 +166,22 @@ def test_inverted_vae_contract(self): assert "Un contrat associé à une VAE inversée n'est possible que pour les GEIQ" in str(excinfo.value) +class TestJobApplicationQueryset: + def test_is_active_company_member(self): + job_application = JobApplicationFactory() + user = EmployerFactory() + assert JobApplication.objects.is_active_company_member(user).count() == 0 + + job_application.to_company.add_or_activate_member(user) + assert JobApplication.objects.is_active_company_member(user).get() == job_application + + membership = job_application.to_company.memberships.filter(user=user).get() + membership.is_active = False + membership.save(update_fields=("is_active",)) + + assert JobApplication.objects.is_active_company_member(user).count() == 0 + + def test_can_be_cancelled(): assert JobApplicationFactory().can_be_cancelled is True diff --git a/tests/www/apply/__snapshots__/test_process.ambr b/tests/www/apply/__snapshots__/test_process.ambr index 13740a85ec..dfb2f31ea3 100644 --- a/tests/www/apply/__snapshots__/test_process.ambr +++ b/tests/www/apply/__snapshots__/test_process.ambr @@ -221,38 +221,38 @@ "job_applications_jobapplication"."planned_training_hours", "job_applications_jobapplication"."inverted_vae_contract", "job_applications_jobapplication"."diagoriente_invite_sent_at", - T5."id", - T5."password", - T5."last_login", - T5."is_superuser", - T5."username", - T5."first_name", - T5."last_name", - T5."is_staff", - T5."is_active", - T5."date_joined", - T5."address_line_1", - T5."address_line_2", - T5."post_code", - T5."city", - T5."department", - T5."coords", - T5."geocoding_score", - T5."geocoding_updated_at", - T5."ban_api_resolved_address", - T5."insee_city_id", - T5."title", - T5."email", - T5."phone", - T5."kind", - T5."identity_provider", - T5."has_completed_welcoming_tour", - T5."created_by_id", - T5."external_data_source_history", - T5."last_checked_at", - T5."public_id", - T5."address_filled_at", - T5."first_login", + "users_user"."id", + "users_user"."password", + "users_user"."last_login", + "users_user"."is_superuser", + "users_user"."username", + "users_user"."first_name", + "users_user"."last_name", + "users_user"."is_staff", + "users_user"."is_active", + "users_user"."date_joined", + "users_user"."address_line_1", + "users_user"."address_line_2", + "users_user"."post_code", + "users_user"."city", + "users_user"."department", + "users_user"."coords", + "users_user"."geocoding_score", + "users_user"."geocoding_updated_at", + "users_user"."ban_api_resolved_address", + "users_user"."insee_city_id", + "users_user"."title", + "users_user"."email", + "users_user"."phone", + "users_user"."kind", + "users_user"."identity_provider", + "users_user"."has_completed_welcoming_tour", + "users_user"."created_by_id", + "users_user"."external_data_source_history", + "users_user"."last_checked_at", + "users_user"."public_id", + "users_user"."address_filled_at", + "users_user"."first_login", "users_jobseekerprofile"."user_id", "users_jobseekerprofile"."birthdate", "users_jobseekerprofile"."birth_place_id", @@ -291,13 +291,17 @@ "users_jobseekerprofile"."pe_obfuscated_nir", "users_jobseekerprofile"."pe_last_certification_attempt_at" FROM "job_applications_jobapplication" - INNER JOIN "companies_company" ON ("job_applications_jobapplication"."to_company_id" = "companies_company"."id") - INNER JOIN "companies_companymembership" ON ("companies_company"."id" = "companies_companymembership"."company_id") - INNER JOIN "users_user" ON ("companies_companymembership"."user_id" = "users_user"."id") - INNER JOIN "users_user" T5 ON ("job_applications_jobapplication"."job_seeker_id" = T5."id") - LEFT OUTER JOIN "users_jobseekerprofile" ON (T5."id" = "users_jobseekerprofile"."user_id") - WHERE ("companies_companymembership"."user_id" = %s - AND "users_user"."is_active" + INNER JOIN "users_user" ON ("job_applications_jobapplication"."job_seeker_id" = "users_user"."id") + LEFT OUTER JOIN "users_jobseekerprofile" ON ("users_user"."id" = "users_jobseekerprofile"."user_id") + WHERE (EXISTS + (SELECT %s AS "a" + FROM "companies_companymembership" U0 + INNER JOIN "users_user" U2 ON (U0."user_id" = U2."id") + WHERE (U0."company_id" = ("job_applications_jobapplication"."to_company_id") + AND U0."is_active" + AND U0."user_id" = %s + AND U2."is_active") + LIMIT 1) AND "job_applications_jobapplication"."id" = %s) LIMIT 21 ''', @@ -1204,38 +1208,38 @@ WHERE ("rdv_insertion_appointment"."company_id" = %s AND "rdv_insertion_appointment"."start_at" > %s AND "rdv_insertion_participation"."status" = %s)) AS "upcoming_participations_count", - T5."id", - T5."password", - T5."last_login", - T5."is_superuser", - T5."username", - T5."first_name", - T5."last_name", - T5."is_staff", - T5."is_active", - T5."date_joined", - T5."address_line_1", - T5."address_line_2", - T5."post_code", - T5."city", - T5."department", - T5."coords", - T5."geocoding_score", - T5."geocoding_updated_at", - T5."ban_api_resolved_address", - T5."insee_city_id", - T5."title", - T5."email", - T5."phone", - T5."kind", - T5."identity_provider", - T5."has_completed_welcoming_tour", - T5."created_by_id", - T5."external_data_source_history", - T5."last_checked_at", - T5."public_id", - T5."address_filled_at", - T5."first_login", + "users_user"."id", + "users_user"."password", + "users_user"."last_login", + "users_user"."is_superuser", + "users_user"."username", + "users_user"."first_name", + "users_user"."last_name", + "users_user"."is_staff", + "users_user"."is_active", + "users_user"."date_joined", + "users_user"."address_line_1", + "users_user"."address_line_2", + "users_user"."post_code", + "users_user"."city", + "users_user"."department", + "users_user"."coords", + "users_user"."geocoding_score", + "users_user"."geocoding_updated_at", + "users_user"."ban_api_resolved_address", + "users_user"."insee_city_id", + "users_user"."title", + "users_user"."email", + "users_user"."phone", + "users_user"."kind", + "users_user"."identity_provider", + "users_user"."has_completed_welcoming_tour", + "users_user"."created_by_id", + "users_user"."external_data_source_history", + "users_user"."last_checked_at", + "users_user"."public_id", + "users_user"."address_filled_at", + "users_user"."first_login", "users_jobseekerprofile"."user_id", "users_jobseekerprofile"."birthdate", "users_jobseekerprofile"."birth_place_id", @@ -1282,6 +1286,69 @@ "eligibility_eligibilitydiagnosis"."expires_at", "eligibility_eligibilitydiagnosis"."job_seeker_id", "eligibility_eligibilitydiagnosis"."author_siae_id", + T9."id", + T9."password", + T9."last_login", + T9."is_superuser", + T9."username", + T9."first_name", + T9."last_name", + T9."is_staff", + T9."is_active", + T9."date_joined", + T9."address_line_1", + T9."address_line_2", + T9."post_code", + T9."city", + T9."department", + T9."coords", + T9."geocoding_score", + T9."geocoding_updated_at", + T9."ban_api_resolved_address", + T9."insee_city_id", + T9."title", + T9."email", + T9."phone", + T9."kind", + T9."identity_provider", + T9."has_completed_welcoming_tour", + T9."created_by_id", + T9."external_data_source_history", + T9."last_checked_at", + T9."public_id", + T9."address_filled_at", + T9."first_login", + "prescribers_prescriberorganization"."id", + "prescribers_prescriberorganization"."address_line_1", + "prescribers_prescriberorganization"."address_line_2", + "prescribers_prescriberorganization"."post_code", + "prescribers_prescriberorganization"."city", + "prescribers_prescriberorganization"."department", + "prescribers_prescriberorganization"."coords", + "prescribers_prescriberorganization"."geocoding_score", + "prescribers_prescriberorganization"."geocoding_updated_at", + "prescribers_prescriberorganization"."ban_api_resolved_address", + "prescribers_prescriberorganization"."insee_city_id", + "prescribers_prescriberorganization"."name", + "prescribers_prescriberorganization"."created_at", + "prescribers_prescriberorganization"."updated_at", + "prescribers_prescriberorganization"."uid", + "prescribers_prescriberorganization"."active_members_email_reminder_last_sent_at", + "prescribers_prescriberorganization"."automatic_geocoding_update", + "prescribers_prescriberorganization"."siret", + "prescribers_prescriberorganization"."is_head_office", + "prescribers_prescriberorganization"."kind", + "prescribers_prescriberorganization"."is_brsa", + "prescribers_prescriberorganization"."phone", + "prescribers_prescriberorganization"."email", + "prescribers_prescriberorganization"."website", + "prescribers_prescriberorganization"."description", + "prescribers_prescriberorganization"."is_authorized", + "prescribers_prescriberorganization"."code_safir_pole_emploi", + "prescribers_prescriberorganization"."created_by_id", + "prescribers_prescriberorganization"."authorization_status", + "prescribers_prescriberorganization"."authorization_updated_at", + "prescribers_prescriberorganization"."authorization_updated_by_id", T11."id", T11."password", T11."last_login", @@ -1314,47 +1381,44 @@ T11."public_id", T11."address_filled_at", T11."first_login", - "prescribers_prescriberorganization"."id", - "prescribers_prescriberorganization"."address_line_1", - "prescribers_prescriberorganization"."address_line_2", - "prescribers_prescriberorganization"."post_code", - "prescribers_prescriberorganization"."city", - "prescribers_prescriberorganization"."department", - "prescribers_prescriberorganization"."coords", - "prescribers_prescriberorganization"."geocoding_score", - "prescribers_prescriberorganization"."geocoding_updated_at", - "prescribers_prescriberorganization"."ban_api_resolved_address", - "prescribers_prescriberorganization"."insee_city_id", - "prescribers_prescriberorganization"."name", - "prescribers_prescriberorganization"."created_at", - "prescribers_prescriberorganization"."updated_at", - "prescribers_prescriberorganization"."uid", - "prescribers_prescriberorganization"."active_members_email_reminder_last_sent_at", - "prescribers_prescriberorganization"."automatic_geocoding_update", - "prescribers_prescriberorganization"."siret", - "prescribers_prescriberorganization"."is_head_office", - "prescribers_prescriberorganization"."kind", - "prescribers_prescriberorganization"."is_brsa", - "prescribers_prescriberorganization"."phone", - "prescribers_prescriberorganization"."email", - "prescribers_prescriberorganization"."website", - "prescribers_prescriberorganization"."description", - "prescribers_prescriberorganization"."is_authorized", - "prescribers_prescriberorganization"."code_safir_pole_emploi", - "prescribers_prescriberorganization"."created_by_id", - "prescribers_prescriberorganization"."authorization_status", - "prescribers_prescriberorganization"."authorization_updated_at", - "prescribers_prescriberorganization"."authorization_updated_by_id", + T12."user_id", + T12."birthdate", + T12."birth_place_id", + T12."birth_country_id", + T12."nir", + T12."lack_of_nir_reason", + T12."pole_emploi_id", + T12."lack_of_pole_emploi_id_reason", + T12."asp_uid", + T12."education_level", + T12."resourceless", + T12."rqth_employee", + T12."oeth_employee", + T12."pole_emploi_since", + T12."unemployed_since", + T12."has_rsa_allocation", + T12."rsa_allocation_since", + T12."ass_allocation_since", + T12."aah_allocation_since", + T12."ata_allocation_since", + T12."are_allocation_since", + T12."activity_bonus_since", + T12."cape_freelance", + T12."cesa_freelance", + T12."actor_met_for_business_creation", + T12."mean_monthly_income_before_process", + T12."eiti_contributions", + T12."hexa_lane_number", + T12."hexa_std_extension", + T12."hexa_non_std_extension", + T12."hexa_lane_type", + T12."hexa_lane_name", + T12."hexa_additional_address", + T12."hexa_post_code", + T12."hexa_commune_id", + T12."pe_obfuscated_nir", + T12."pe_last_certification_attempt_at", T13."id", - T13."password", - T13."last_login", - T13."is_superuser", - T13."username", - T13."first_name", - T13."last_name", - T13."is_staff", - T13."is_active", - T13."date_joined", T13."address_line_1", T13."address_line_2", T13."post_code", @@ -1365,56 +1429,50 @@ T13."geocoding_updated_at", T13."ban_api_resolved_address", T13."insee_city_id", - T13."title", - T13."email", - T13."phone", + T13."name", + T13."created_at", + T13."updated_at", + T13."uid", + T13."active_members_email_reminder_last_sent_at", + T13."automatic_geocoding_update", + T13."siret", + T13."naf", T13."kind", - T13."identity_provider", - T13."has_completed_welcoming_tour", + T13."brand", + T13."phone", + T13."email", + T13."auth_email", + T13."website", + T13."description", + T13."provided_support", + T13."source", T13."created_by_id", - T13."external_data_source_history", - T13."last_checked_at", - T13."public_id", - T13."address_filled_at", - T13."first_login", - T14."user_id", - T14."birthdate", - T14."birth_place_id", - T14."birth_country_id", - T14."nir", - T14."lack_of_nir_reason", - T14."pole_emploi_id", - T14."lack_of_pole_emploi_id_reason", - T14."asp_uid", - T14."education_level", - T14."resourceless", - T14."rqth_employee", - T14."oeth_employee", - T14."pole_emploi_since", - T14."unemployed_since", - T14."has_rsa_allocation", - T14."rsa_allocation_since", - T14."ass_allocation_since", - T14."aah_allocation_since", - T14."ata_allocation_since", - T14."are_allocation_since", - T14."activity_bonus_since", - T14."cape_freelance", - T14."cesa_freelance", - T14."actor_met_for_business_creation", - T14."mean_monthly_income_before_process", - T14."eiti_contributions", - T14."hexa_lane_number", - T14."hexa_std_extension", - T14."hexa_non_std_extension", - T14."hexa_lane_type", - T14."hexa_lane_name", - T14."hexa_additional_address", - T14."hexa_post_code", - T14."hexa_commune_id", - T14."pe_obfuscated_nir", - T14."pe_last_certification_attempt_at", + T13."block_job_applications", + T13."job_applications_blocked_at", + T13."convention_id", + T13."job_app_score", + T13."is_searchable", + T13."rdv_solidarites_id", + T13."fields_history", + "eligibility_geiqeligibilitydiagnosis"."id", + "eligibility_geiqeligibilitydiagnosis"."author_id", + "eligibility_geiqeligibilitydiagnosis"."author_kind", + "eligibility_geiqeligibilitydiagnosis"."author_prescriber_organization_id", + "eligibility_geiqeligibilitydiagnosis"."created_at", + "eligibility_geiqeligibilitydiagnosis"."updated_at", + "eligibility_geiqeligibilitydiagnosis"."expires_at", + "eligibility_geiqeligibilitydiagnosis"."job_seeker_id", + "eligibility_geiqeligibilitydiagnosis"."author_geiq_id", T15."id", + T15."password", + T15."last_login", + T15."is_superuser", + T15."username", + T15."first_name", + T15."last_name", + T15."is_staff", + T15."is_active", + T15."date_joined", T15."address_line_1", T15."address_line_2", T15."post_code", @@ -1425,50 +1483,55 @@ T15."geocoding_updated_at", T15."ban_api_resolved_address", T15."insee_city_id", - T15."name", - T15."created_at", - T15."updated_at", - T15."uid", - T15."active_members_email_reminder_last_sent_at", - T15."automatic_geocoding_update", - T15."siret", - T15."naf", - T15."kind", - T15."brand", - T15."phone", + T15."title", T15."email", - T15."auth_email", - T15."website", - T15."description", - T15."provided_support", - T15."source", + T15."phone", + T15."kind", + T15."identity_provider", + T15."has_completed_welcoming_tour", T15."created_by_id", - T15."block_job_applications", - T15."job_applications_blocked_at", - T15."convention_id", - T15."job_app_score", - T15."is_searchable", - T15."rdv_solidarites_id", - T15."fields_history", - "eligibility_geiqeligibilitydiagnosis"."id", - "eligibility_geiqeligibilitydiagnosis"."author_id", - "eligibility_geiqeligibilitydiagnosis"."author_kind", - "eligibility_geiqeligibilitydiagnosis"."author_prescriber_organization_id", - "eligibility_geiqeligibilitydiagnosis"."created_at", - "eligibility_geiqeligibilitydiagnosis"."updated_at", - "eligibility_geiqeligibilitydiagnosis"."expires_at", - "eligibility_geiqeligibilitydiagnosis"."job_seeker_id", - "eligibility_geiqeligibilitydiagnosis"."author_geiq_id", + T15."external_data_source_history", + T15."last_checked_at", + T15."public_id", + T15."address_filled_at", + T15."first_login", + T16."id", + T16."address_line_1", + T16."address_line_2", + T16."post_code", + T16."city", + T16."department", + T16."coords", + T16."geocoding_score", + T16."geocoding_updated_at", + T16."ban_api_resolved_address", + T16."insee_city_id", + T16."name", + T16."created_at", + T16."updated_at", + T16."uid", + T16."active_members_email_reminder_last_sent_at", + T16."automatic_geocoding_update", + T16."siret", + T16."naf", + T16."kind", + T16."brand", + T16."phone", + T16."email", + T16."auth_email", + T16."website", + T16."description", + T16."provided_support", + T16."source", + T16."created_by_id", + T16."block_job_applications", + T16."job_applications_blocked_at", + T16."convention_id", + T16."job_app_score", + T16."is_searchable", + T16."rdv_solidarites_id", + T16."fields_history", T17."id", - T17."password", - T17."last_login", - T17."is_superuser", - T17."username", - T17."first_name", - T17."last_name", - T17."is_staff", - T17."is_active", - T17."date_joined", T17."address_line_1", T17."address_line_2", T17."post_code", @@ -1479,85 +1542,26 @@ T17."geocoding_updated_at", T17."ban_api_resolved_address", T17."insee_city_id", - T17."title", - T17."email", - T17."phone", + T17."name", + T17."created_at", + T17."updated_at", + T17."uid", + T17."active_members_email_reminder_last_sent_at", + T17."automatic_geocoding_update", + T17."siret", + T17."is_head_office", T17."kind", - T17."identity_provider", - T17."has_completed_welcoming_tour", + T17."is_brsa", + T17."phone", + T17."email", + T17."website", + T17."description", + T17."is_authorized", + T17."code_safir_pole_emploi", T17."created_by_id", - T17."external_data_source_history", - T17."last_checked_at", - T17."public_id", - T17."address_filled_at", - T17."first_login", - T18."id", - T18."address_line_1", - T18."address_line_2", - T18."post_code", - T18."city", - T18."department", - T18."coords", - T18."geocoding_score", - T18."geocoding_updated_at", - T18."ban_api_resolved_address", - T18."insee_city_id", - T18."name", - T18."created_at", - T18."updated_at", - T18."uid", - T18."active_members_email_reminder_last_sent_at", - T18."automatic_geocoding_update", - T18."siret", - T18."naf", - T18."kind", - T18."brand", - T18."phone", - T18."email", - T18."auth_email", - T18."website", - T18."description", - T18."provided_support", - T18."source", - T18."created_by_id", - T18."block_job_applications", - T18."job_applications_blocked_at", - T18."convention_id", - T18."job_app_score", - T18."is_searchable", - T18."rdv_solidarites_id", - T18."fields_history", - T19."id", - T19."address_line_1", - T19."address_line_2", - T19."post_code", - T19."city", - T19."department", - T19."coords", - T19."geocoding_score", - T19."geocoding_updated_at", - T19."ban_api_resolved_address", - T19."insee_city_id", - T19."name", - T19."created_at", - T19."updated_at", - T19."uid", - T19."active_members_email_reminder_last_sent_at", - T19."automatic_geocoding_update", - T19."siret", - T19."is_head_office", - T19."kind", - T19."is_brsa", - T19."phone", - T19."email", - T19."website", - T19."description", - T19."is_authorized", - T19."code_safir_pole_emploi", - T19."created_by_id", - T19."authorization_status", - T19."authorization_updated_at", - T19."authorization_updated_by_id", + T17."authorization_status", + T17."authorization_updated_at", + T17."authorization_updated_by_id", "companies_company"."id", "companies_company"."address_line_1", "companies_company"."address_line_2", @@ -1594,38 +1598,38 @@ "companies_company"."is_searchable", "companies_company"."rdv_solidarites_id", "companies_company"."fields_history", - T20."id", - T20."password", - T20."last_login", - T20."is_superuser", - T20."username", - T20."first_name", - T20."last_name", - T20."is_staff", - T20."is_active", - T20."date_joined", - T20."address_line_1", - T20."address_line_2", - T20."post_code", - T20."city", - T20."department", - T20."coords", - T20."geocoding_score", - T20."geocoding_updated_at", - T20."ban_api_resolved_address", - T20."insee_city_id", - T20."title", - T20."email", - T20."phone", - T20."kind", - T20."identity_provider", - T20."has_completed_welcoming_tour", - T20."created_by_id", - T20."external_data_source_history", - T20."last_checked_at", - T20."public_id", - T20."address_filled_at", - T20."first_login", + T18."id", + T18."password", + T18."last_login", + T18."is_superuser", + T18."username", + T18."first_name", + T18."last_name", + T18."is_staff", + T18."is_active", + T18."date_joined", + T18."address_line_1", + T18."address_line_2", + T18."post_code", + T18."city", + T18."department", + T18."coords", + T18."geocoding_score", + T18."geocoding_updated_at", + T18."ban_api_resolved_address", + T18."insee_city_id", + T18."title", + T18."email", + T18."phone", + T18."kind", + T18."identity_provider", + T18."has_completed_welcoming_tour", + T18."created_by_id", + T18."external_data_source_history", + T18."last_checked_at", + T18."public_id", + T18."address_filled_at", + T18."first_login", "approvals_approval"."id", "approvals_approval"."start_at", "approvals_approval"."end_at", @@ -1646,42 +1650,47 @@ "approvals_approval"."origin_prescriber_organization_kind" FROM "job_applications_jobapplication" INNER JOIN "companies_company" ON ("job_applications_jobapplication"."to_company_id" = "companies_company"."id") - INNER JOIN "companies_companymembership" ON ("companies_company"."id" = "companies_companymembership"."company_id") - INNER JOIN "users_user" ON ("companies_companymembership"."user_id" = "users_user"."id") - INNER JOIN "users_user" T5 ON ("job_applications_jobapplication"."job_seeker_id" = T5."id") - LEFT OUTER JOIN "rdv_insertion_participation" ON (T5."id" = "rdv_insertion_participation"."job_seeker_id") + INNER JOIN "users_user" ON ("job_applications_jobapplication"."job_seeker_id" = "users_user"."id") + LEFT OUTER JOIN "rdv_insertion_participation" ON ("users_user"."id" = "rdv_insertion_participation"."job_seeker_id") LEFT OUTER JOIN "rdv_insertion_appointment" ON ("rdv_insertion_participation"."appointment_id" = "rdv_insertion_appointment"."id") - LEFT OUTER JOIN "users_jobseekerprofile" ON (T5."id" = "users_jobseekerprofile"."user_id") + LEFT OUTER JOIN "users_jobseekerprofile" ON ("users_user"."id" = "users_jobseekerprofile"."user_id") LEFT OUTER JOIN "eligibility_eligibilitydiagnosis" ON ("job_applications_jobapplication"."eligibility_diagnosis_id" = "eligibility_eligibilitydiagnosis"."id") - LEFT OUTER JOIN "users_user" T11 ON ("eligibility_eligibilitydiagnosis"."author_id" = T11."id") + LEFT OUTER JOIN "users_user" T9 ON ("eligibility_eligibilitydiagnosis"."author_id" = T9."id") LEFT OUTER JOIN "prescribers_prescriberorganization" ON ("eligibility_eligibilitydiagnosis"."author_prescriber_organization_id" = "prescribers_prescriberorganization"."id") - LEFT OUTER JOIN "users_user" T13 ON ("eligibility_eligibilitydiagnosis"."job_seeker_id" = T13."id") - LEFT OUTER JOIN "users_jobseekerprofile" T14 ON (T13."id" = T14."user_id") - LEFT OUTER JOIN "companies_company" T15 ON ("eligibility_eligibilitydiagnosis"."author_siae_id" = T15."id") + LEFT OUTER JOIN "users_user" T11 ON ("eligibility_eligibilitydiagnosis"."job_seeker_id" = T11."id") + LEFT OUTER JOIN "users_jobseekerprofile" T12 ON (T11."id" = T12."user_id") + LEFT OUTER JOIN "companies_company" T13 ON ("eligibility_eligibilitydiagnosis"."author_siae_id" = T13."id") LEFT OUTER JOIN "eligibility_geiqeligibilitydiagnosis" ON ("job_applications_jobapplication"."geiq_eligibility_diagnosis_id" = "eligibility_geiqeligibilitydiagnosis"."id") - LEFT OUTER JOIN "users_user" T17 ON ("job_applications_jobapplication"."sender_id" = T17."id") - LEFT OUTER JOIN "companies_company" T18 ON ("job_applications_jobapplication"."sender_company_id" = T18."id") - LEFT OUTER JOIN "prescribers_prescriberorganization" T19 ON ("job_applications_jobapplication"."sender_prescriber_organization_id" = T19."id") - LEFT OUTER JOIN "users_user" T20 ON ("job_applications_jobapplication"."archived_by_id" = T20."id") + LEFT OUTER JOIN "users_user" T15 ON ("job_applications_jobapplication"."sender_id" = T15."id") + LEFT OUTER JOIN "companies_company" T16 ON ("job_applications_jobapplication"."sender_company_id" = T16."id") + LEFT OUTER JOIN "prescribers_prescriberorganization" T17 ON ("job_applications_jobapplication"."sender_prescriber_organization_id" = T17."id") + LEFT OUTER JOIN "users_user" T18 ON ("job_applications_jobapplication"."archived_by_id" = T18."id") LEFT OUTER JOIN "approvals_approval" ON ("job_applications_jobapplication"."approval_id" = "approvals_approval"."id") - WHERE ("companies_companymembership"."user_id" = %s - AND "users_user"."is_active" + WHERE (EXISTS + (SELECT %s AS "a" + FROM "companies_companymembership" U0 + INNER JOIN "users_user" U2 ON (U0."user_id" = U2."id") + WHERE (U0."company_id" = ("job_applications_jobapplication"."to_company_id") + AND U0."is_active" + AND U0."user_id" = %s + AND U2."is_active") + LIMIT 1) AND "job_applications_jobapplication"."id" = %s) GROUP BY "job_applications_jobapplication"."id", - T5."id", + "users_user"."id", "users_jobseekerprofile"."user_id", "eligibility_eligibilitydiagnosis"."id", - T11."id", + T9."id", "prescribers_prescriberorganization"."id", + T11."id", + T12."user_id", T13."id", - T14."user_id", - T15."id", "eligibility_geiqeligibilitydiagnosis"."id", + T15."id", + T16."id", T17."id", - T18."id", - T19."id", "companies_company"."id", - T20."id", + T18."id", "approvals_approval"."id" LIMIT 21 ''', @@ -2335,38 +2344,38 @@ WHERE ("rdv_insertion_appointment"."company_id" = %s AND "rdv_insertion_appointment"."start_at" > %s AND "rdv_insertion_participation"."status" = %s)) AS "upcoming_participations_count", - T5."id", - T5."password", - T5."last_login", - T5."is_superuser", - T5."username", - T5."first_name", - T5."last_name", - T5."is_staff", - T5."is_active", - T5."date_joined", - T5."address_line_1", - T5."address_line_2", - T5."post_code", - T5."city", - T5."department", - T5."coords", - T5."geocoding_score", - T5."geocoding_updated_at", - T5."ban_api_resolved_address", - T5."insee_city_id", - T5."title", - T5."email", - T5."phone", - T5."kind", - T5."identity_provider", - T5."has_completed_welcoming_tour", - T5."created_by_id", - T5."external_data_source_history", - T5."last_checked_at", - T5."public_id", - T5."address_filled_at", - T5."first_login", + "users_user"."id", + "users_user"."password", + "users_user"."last_login", + "users_user"."is_superuser", + "users_user"."username", + "users_user"."first_name", + "users_user"."last_name", + "users_user"."is_staff", + "users_user"."is_active", + "users_user"."date_joined", + "users_user"."address_line_1", + "users_user"."address_line_2", + "users_user"."post_code", + "users_user"."city", + "users_user"."department", + "users_user"."coords", + "users_user"."geocoding_score", + "users_user"."geocoding_updated_at", + "users_user"."ban_api_resolved_address", + "users_user"."insee_city_id", + "users_user"."title", + "users_user"."email", + "users_user"."phone", + "users_user"."kind", + "users_user"."identity_provider", + "users_user"."has_completed_welcoming_tour", + "users_user"."created_by_id", + "users_user"."external_data_source_history", + "users_user"."last_checked_at", + "users_user"."public_id", + "users_user"."address_filled_at", + "users_user"."first_login", "users_jobseekerprofile"."user_id", "users_jobseekerprofile"."birthdate", "users_jobseekerprofile"."birth_place_id", @@ -2413,6 +2422,69 @@ "eligibility_eligibilitydiagnosis"."expires_at", "eligibility_eligibilitydiagnosis"."job_seeker_id", "eligibility_eligibilitydiagnosis"."author_siae_id", + T9."id", + T9."password", + T9."last_login", + T9."is_superuser", + T9."username", + T9."first_name", + T9."last_name", + T9."is_staff", + T9."is_active", + T9."date_joined", + T9."address_line_1", + T9."address_line_2", + T9."post_code", + T9."city", + T9."department", + T9."coords", + T9."geocoding_score", + T9."geocoding_updated_at", + T9."ban_api_resolved_address", + T9."insee_city_id", + T9."title", + T9."email", + T9."phone", + T9."kind", + T9."identity_provider", + T9."has_completed_welcoming_tour", + T9."created_by_id", + T9."external_data_source_history", + T9."last_checked_at", + T9."public_id", + T9."address_filled_at", + T9."first_login", + "prescribers_prescriberorganization"."id", + "prescribers_prescriberorganization"."address_line_1", + "prescribers_prescriberorganization"."address_line_2", + "prescribers_prescriberorganization"."post_code", + "prescribers_prescriberorganization"."city", + "prescribers_prescriberorganization"."department", + "prescribers_prescriberorganization"."coords", + "prescribers_prescriberorganization"."geocoding_score", + "prescribers_prescriberorganization"."geocoding_updated_at", + "prescribers_prescriberorganization"."ban_api_resolved_address", + "prescribers_prescriberorganization"."insee_city_id", + "prescribers_prescriberorganization"."name", + "prescribers_prescriberorganization"."created_at", + "prescribers_prescriberorganization"."updated_at", + "prescribers_prescriberorganization"."uid", + "prescribers_prescriberorganization"."active_members_email_reminder_last_sent_at", + "prescribers_prescriberorganization"."automatic_geocoding_update", + "prescribers_prescriberorganization"."siret", + "prescribers_prescriberorganization"."is_head_office", + "prescribers_prescriberorganization"."kind", + "prescribers_prescriberorganization"."is_brsa", + "prescribers_prescriberorganization"."phone", + "prescribers_prescriberorganization"."email", + "prescribers_prescriberorganization"."website", + "prescribers_prescriberorganization"."description", + "prescribers_prescriberorganization"."is_authorized", + "prescribers_prescriberorganization"."code_safir_pole_emploi", + "prescribers_prescriberorganization"."created_by_id", + "prescribers_prescriberorganization"."authorization_status", + "prescribers_prescriberorganization"."authorization_updated_at", + "prescribers_prescriberorganization"."authorization_updated_by_id", T11."id", T11."password", T11."last_login", @@ -2445,47 +2517,44 @@ T11."public_id", T11."address_filled_at", T11."first_login", - "prescribers_prescriberorganization"."id", - "prescribers_prescriberorganization"."address_line_1", - "prescribers_prescriberorganization"."address_line_2", - "prescribers_prescriberorganization"."post_code", - "prescribers_prescriberorganization"."city", - "prescribers_prescriberorganization"."department", - "prescribers_prescriberorganization"."coords", - "prescribers_prescriberorganization"."geocoding_score", - "prescribers_prescriberorganization"."geocoding_updated_at", - "prescribers_prescriberorganization"."ban_api_resolved_address", - "prescribers_prescriberorganization"."insee_city_id", - "prescribers_prescriberorganization"."name", - "prescribers_prescriberorganization"."created_at", - "prescribers_prescriberorganization"."updated_at", - "prescribers_prescriberorganization"."uid", - "prescribers_prescriberorganization"."active_members_email_reminder_last_sent_at", - "prescribers_prescriberorganization"."automatic_geocoding_update", - "prescribers_prescriberorganization"."siret", - "prescribers_prescriberorganization"."is_head_office", - "prescribers_prescriberorganization"."kind", - "prescribers_prescriberorganization"."is_brsa", - "prescribers_prescriberorganization"."phone", - "prescribers_prescriberorganization"."email", - "prescribers_prescriberorganization"."website", - "prescribers_prescriberorganization"."description", - "prescribers_prescriberorganization"."is_authorized", - "prescribers_prescriberorganization"."code_safir_pole_emploi", - "prescribers_prescriberorganization"."created_by_id", - "prescribers_prescriberorganization"."authorization_status", - "prescribers_prescriberorganization"."authorization_updated_at", - "prescribers_prescriberorganization"."authorization_updated_by_id", + T12."user_id", + T12."birthdate", + T12."birth_place_id", + T12."birth_country_id", + T12."nir", + T12."lack_of_nir_reason", + T12."pole_emploi_id", + T12."lack_of_pole_emploi_id_reason", + T12."asp_uid", + T12."education_level", + T12."resourceless", + T12."rqth_employee", + T12."oeth_employee", + T12."pole_emploi_since", + T12."unemployed_since", + T12."has_rsa_allocation", + T12."rsa_allocation_since", + T12."ass_allocation_since", + T12."aah_allocation_since", + T12."ata_allocation_since", + T12."are_allocation_since", + T12."activity_bonus_since", + T12."cape_freelance", + T12."cesa_freelance", + T12."actor_met_for_business_creation", + T12."mean_monthly_income_before_process", + T12."eiti_contributions", + T12."hexa_lane_number", + T12."hexa_std_extension", + T12."hexa_non_std_extension", + T12."hexa_lane_type", + T12."hexa_lane_name", + T12."hexa_additional_address", + T12."hexa_post_code", + T12."hexa_commune_id", + T12."pe_obfuscated_nir", + T12."pe_last_certification_attempt_at", T13."id", - T13."password", - T13."last_login", - T13."is_superuser", - T13."username", - T13."first_name", - T13."last_name", - T13."is_staff", - T13."is_active", - T13."date_joined", T13."address_line_1", T13."address_line_2", T13."post_code", @@ -2496,56 +2565,50 @@ T13."geocoding_updated_at", T13."ban_api_resolved_address", T13."insee_city_id", - T13."title", - T13."email", - T13."phone", + T13."name", + T13."created_at", + T13."updated_at", + T13."uid", + T13."active_members_email_reminder_last_sent_at", + T13."automatic_geocoding_update", + T13."siret", + T13."naf", T13."kind", - T13."identity_provider", - T13."has_completed_welcoming_tour", + T13."brand", + T13."phone", + T13."email", + T13."auth_email", + T13."website", + T13."description", + T13."provided_support", + T13."source", T13."created_by_id", - T13."external_data_source_history", - T13."last_checked_at", - T13."public_id", - T13."address_filled_at", - T13."first_login", - T14."user_id", - T14."birthdate", - T14."birth_place_id", - T14."birth_country_id", - T14."nir", - T14."lack_of_nir_reason", - T14."pole_emploi_id", - T14."lack_of_pole_emploi_id_reason", - T14."asp_uid", - T14."education_level", - T14."resourceless", - T14."rqth_employee", - T14."oeth_employee", - T14."pole_emploi_since", - T14."unemployed_since", - T14."has_rsa_allocation", - T14."rsa_allocation_since", - T14."ass_allocation_since", - T14."aah_allocation_since", - T14."ata_allocation_since", - T14."are_allocation_since", - T14."activity_bonus_since", - T14."cape_freelance", - T14."cesa_freelance", - T14."actor_met_for_business_creation", - T14."mean_monthly_income_before_process", - T14."eiti_contributions", - T14."hexa_lane_number", - T14."hexa_std_extension", - T14."hexa_non_std_extension", - T14."hexa_lane_type", - T14."hexa_lane_name", - T14."hexa_additional_address", - T14."hexa_post_code", - T14."hexa_commune_id", - T14."pe_obfuscated_nir", - T14."pe_last_certification_attempt_at", + T13."block_job_applications", + T13."job_applications_blocked_at", + T13."convention_id", + T13."job_app_score", + T13."is_searchable", + T13."rdv_solidarites_id", + T13."fields_history", + "eligibility_geiqeligibilitydiagnosis"."id", + "eligibility_geiqeligibilitydiagnosis"."author_id", + "eligibility_geiqeligibilitydiagnosis"."author_kind", + "eligibility_geiqeligibilitydiagnosis"."author_prescriber_organization_id", + "eligibility_geiqeligibilitydiagnosis"."created_at", + "eligibility_geiqeligibilitydiagnosis"."updated_at", + "eligibility_geiqeligibilitydiagnosis"."expires_at", + "eligibility_geiqeligibilitydiagnosis"."job_seeker_id", + "eligibility_geiqeligibilitydiagnosis"."author_geiq_id", T15."id", + T15."password", + T15."last_login", + T15."is_superuser", + T15."username", + T15."first_name", + T15."last_name", + T15."is_staff", + T15."is_active", + T15."date_joined", T15."address_line_1", T15."address_line_2", T15."post_code", @@ -2556,50 +2619,55 @@ T15."geocoding_updated_at", T15."ban_api_resolved_address", T15."insee_city_id", - T15."name", - T15."created_at", - T15."updated_at", - T15."uid", - T15."active_members_email_reminder_last_sent_at", - T15."automatic_geocoding_update", - T15."siret", - T15."naf", - T15."kind", - T15."brand", - T15."phone", + T15."title", T15."email", - T15."auth_email", - T15."website", - T15."description", - T15."provided_support", - T15."source", + T15."phone", + T15."kind", + T15."identity_provider", + T15."has_completed_welcoming_tour", T15."created_by_id", - T15."block_job_applications", - T15."job_applications_blocked_at", - T15."convention_id", - T15."job_app_score", - T15."is_searchable", - T15."rdv_solidarites_id", - T15."fields_history", - "eligibility_geiqeligibilitydiagnosis"."id", - "eligibility_geiqeligibilitydiagnosis"."author_id", - "eligibility_geiqeligibilitydiagnosis"."author_kind", - "eligibility_geiqeligibilitydiagnosis"."author_prescriber_organization_id", - "eligibility_geiqeligibilitydiagnosis"."created_at", - "eligibility_geiqeligibilitydiagnosis"."updated_at", - "eligibility_geiqeligibilitydiagnosis"."expires_at", - "eligibility_geiqeligibilitydiagnosis"."job_seeker_id", - "eligibility_geiqeligibilitydiagnosis"."author_geiq_id", + T15."external_data_source_history", + T15."last_checked_at", + T15."public_id", + T15."address_filled_at", + T15."first_login", + T16."id", + T16."address_line_1", + T16."address_line_2", + T16."post_code", + T16."city", + T16."department", + T16."coords", + T16."geocoding_score", + T16."geocoding_updated_at", + T16."ban_api_resolved_address", + T16."insee_city_id", + T16."name", + T16."created_at", + T16."updated_at", + T16."uid", + T16."active_members_email_reminder_last_sent_at", + T16."automatic_geocoding_update", + T16."siret", + T16."naf", + T16."kind", + T16."brand", + T16."phone", + T16."email", + T16."auth_email", + T16."website", + T16."description", + T16."provided_support", + T16."source", + T16."created_by_id", + T16."block_job_applications", + T16."job_applications_blocked_at", + T16."convention_id", + T16."job_app_score", + T16."is_searchable", + T16."rdv_solidarites_id", + T16."fields_history", T17."id", - T17."password", - T17."last_login", - T17."is_superuser", - T17."username", - T17."first_name", - T17."last_name", - T17."is_staff", - T17."is_active", - T17."date_joined", T17."address_line_1", T17."address_line_2", T17."post_code", @@ -2610,85 +2678,26 @@ T17."geocoding_updated_at", T17."ban_api_resolved_address", T17."insee_city_id", - T17."title", - T17."email", - T17."phone", + T17."name", + T17."created_at", + T17."updated_at", + T17."uid", + T17."active_members_email_reminder_last_sent_at", + T17."automatic_geocoding_update", + T17."siret", + T17."is_head_office", T17."kind", - T17."identity_provider", - T17."has_completed_welcoming_tour", + T17."is_brsa", + T17."phone", + T17."email", + T17."website", + T17."description", + T17."is_authorized", + T17."code_safir_pole_emploi", T17."created_by_id", - T17."external_data_source_history", - T17."last_checked_at", - T17."public_id", - T17."address_filled_at", - T17."first_login", - T18."id", - T18."address_line_1", - T18."address_line_2", - T18."post_code", - T18."city", - T18."department", - T18."coords", - T18."geocoding_score", - T18."geocoding_updated_at", - T18."ban_api_resolved_address", - T18."insee_city_id", - T18."name", - T18."created_at", - T18."updated_at", - T18."uid", - T18."active_members_email_reminder_last_sent_at", - T18."automatic_geocoding_update", - T18."siret", - T18."naf", - T18."kind", - T18."brand", - T18."phone", - T18."email", - T18."auth_email", - T18."website", - T18."description", - T18."provided_support", - T18."source", - T18."created_by_id", - T18."block_job_applications", - T18."job_applications_blocked_at", - T18."convention_id", - T18."job_app_score", - T18."is_searchable", - T18."rdv_solidarites_id", - T18."fields_history", - T19."id", - T19."address_line_1", - T19."address_line_2", - T19."post_code", - T19."city", - T19."department", - T19."coords", - T19."geocoding_score", - T19."geocoding_updated_at", - T19."ban_api_resolved_address", - T19."insee_city_id", - T19."name", - T19."created_at", - T19."updated_at", - T19."uid", - T19."active_members_email_reminder_last_sent_at", - T19."automatic_geocoding_update", - T19."siret", - T19."is_head_office", - T19."kind", - T19."is_brsa", - T19."phone", - T19."email", - T19."website", - T19."description", - T19."is_authorized", - T19."code_safir_pole_emploi", - T19."created_by_id", - T19."authorization_status", - T19."authorization_updated_at", - T19."authorization_updated_by_id", + T17."authorization_status", + T17."authorization_updated_at", + T17."authorization_updated_by_id", "companies_company"."id", "companies_company"."address_line_1", "companies_company"."address_line_2", @@ -2725,38 +2734,38 @@ "companies_company"."is_searchable", "companies_company"."rdv_solidarites_id", "companies_company"."fields_history", - T20."id", - T20."password", - T20."last_login", - T20."is_superuser", - T20."username", - T20."first_name", - T20."last_name", - T20."is_staff", - T20."is_active", - T20."date_joined", - T20."address_line_1", - T20."address_line_2", - T20."post_code", - T20."city", - T20."department", - T20."coords", - T20."geocoding_score", - T20."geocoding_updated_at", - T20."ban_api_resolved_address", - T20."insee_city_id", - T20."title", - T20."email", - T20."phone", - T20."kind", - T20."identity_provider", - T20."has_completed_welcoming_tour", - T20."created_by_id", - T20."external_data_source_history", - T20."last_checked_at", - T20."public_id", - T20."address_filled_at", - T20."first_login", + T18."id", + T18."password", + T18."last_login", + T18."is_superuser", + T18."username", + T18."first_name", + T18."last_name", + T18."is_staff", + T18."is_active", + T18."date_joined", + T18."address_line_1", + T18."address_line_2", + T18."post_code", + T18."city", + T18."department", + T18."coords", + T18."geocoding_score", + T18."geocoding_updated_at", + T18."ban_api_resolved_address", + T18."insee_city_id", + T18."title", + T18."email", + T18."phone", + T18."kind", + T18."identity_provider", + T18."has_completed_welcoming_tour", + T18."created_by_id", + T18."external_data_source_history", + T18."last_checked_at", + T18."public_id", + T18."address_filled_at", + T18."first_login", "approvals_approval"."id", "approvals_approval"."start_at", "approvals_approval"."end_at", @@ -2777,42 +2786,47 @@ "approvals_approval"."origin_prescriber_organization_kind" FROM "job_applications_jobapplication" INNER JOIN "companies_company" ON ("job_applications_jobapplication"."to_company_id" = "companies_company"."id") - INNER JOIN "companies_companymembership" ON ("companies_company"."id" = "companies_companymembership"."company_id") - INNER JOIN "users_user" ON ("companies_companymembership"."user_id" = "users_user"."id") - INNER JOIN "users_user" T5 ON ("job_applications_jobapplication"."job_seeker_id" = T5."id") - LEFT OUTER JOIN "rdv_insertion_participation" ON (T5."id" = "rdv_insertion_participation"."job_seeker_id") + INNER JOIN "users_user" ON ("job_applications_jobapplication"."job_seeker_id" = "users_user"."id") + LEFT OUTER JOIN "rdv_insertion_participation" ON ("users_user"."id" = "rdv_insertion_participation"."job_seeker_id") LEFT OUTER JOIN "rdv_insertion_appointment" ON ("rdv_insertion_participation"."appointment_id" = "rdv_insertion_appointment"."id") - LEFT OUTER JOIN "users_jobseekerprofile" ON (T5."id" = "users_jobseekerprofile"."user_id") + LEFT OUTER JOIN "users_jobseekerprofile" ON ("users_user"."id" = "users_jobseekerprofile"."user_id") LEFT OUTER JOIN "eligibility_eligibilitydiagnosis" ON ("job_applications_jobapplication"."eligibility_diagnosis_id" = "eligibility_eligibilitydiagnosis"."id") - LEFT OUTER JOIN "users_user" T11 ON ("eligibility_eligibilitydiagnosis"."author_id" = T11."id") + LEFT OUTER JOIN "users_user" T9 ON ("eligibility_eligibilitydiagnosis"."author_id" = T9."id") LEFT OUTER JOIN "prescribers_prescriberorganization" ON ("eligibility_eligibilitydiagnosis"."author_prescriber_organization_id" = "prescribers_prescriberorganization"."id") - LEFT OUTER JOIN "users_user" T13 ON ("eligibility_eligibilitydiagnosis"."job_seeker_id" = T13."id") - LEFT OUTER JOIN "users_jobseekerprofile" T14 ON (T13."id" = T14."user_id") - LEFT OUTER JOIN "companies_company" T15 ON ("eligibility_eligibilitydiagnosis"."author_siae_id" = T15."id") + LEFT OUTER JOIN "users_user" T11 ON ("eligibility_eligibilitydiagnosis"."job_seeker_id" = T11."id") + LEFT OUTER JOIN "users_jobseekerprofile" T12 ON (T11."id" = T12."user_id") + LEFT OUTER JOIN "companies_company" T13 ON ("eligibility_eligibilitydiagnosis"."author_siae_id" = T13."id") LEFT OUTER JOIN "eligibility_geiqeligibilitydiagnosis" ON ("job_applications_jobapplication"."geiq_eligibility_diagnosis_id" = "eligibility_geiqeligibilitydiagnosis"."id") - LEFT OUTER JOIN "users_user" T17 ON ("job_applications_jobapplication"."sender_id" = T17."id") - LEFT OUTER JOIN "companies_company" T18 ON ("job_applications_jobapplication"."sender_company_id" = T18."id") - LEFT OUTER JOIN "prescribers_prescriberorganization" T19 ON ("job_applications_jobapplication"."sender_prescriber_organization_id" = T19."id") - LEFT OUTER JOIN "users_user" T20 ON ("job_applications_jobapplication"."archived_by_id" = T20."id") + LEFT OUTER JOIN "users_user" T15 ON ("job_applications_jobapplication"."sender_id" = T15."id") + LEFT OUTER JOIN "companies_company" T16 ON ("job_applications_jobapplication"."sender_company_id" = T16."id") + LEFT OUTER JOIN "prescribers_prescriberorganization" T17 ON ("job_applications_jobapplication"."sender_prescriber_organization_id" = T17."id") + LEFT OUTER JOIN "users_user" T18 ON ("job_applications_jobapplication"."archived_by_id" = T18."id") LEFT OUTER JOIN "approvals_approval" ON ("job_applications_jobapplication"."approval_id" = "approvals_approval"."id") - WHERE ("companies_companymembership"."user_id" = %s - AND "users_user"."is_active" + WHERE (EXISTS + (SELECT %s AS "a" + FROM "companies_companymembership" U0 + INNER JOIN "users_user" U2 ON (U0."user_id" = U2."id") + WHERE (U0."company_id" = ("job_applications_jobapplication"."to_company_id") + AND U0."is_active" + AND U0."user_id" = %s + AND U2."is_active") + LIMIT 1) AND "job_applications_jobapplication"."id" = %s) GROUP BY "job_applications_jobapplication"."id", - T5."id", + "users_user"."id", "users_jobseekerprofile"."user_id", "eligibility_eligibilitydiagnosis"."id", - T11."id", + T9."id", "prescribers_prescriberorganization"."id", + T11."id", + T12."user_id", T13."id", - T14."user_id", - T15."id", "eligibility_geiqeligibilitydiagnosis"."id", + T15."id", + T16."id", T17."id", - T18."id", - T19."id", "companies_company"."id", - T20."id", + T18."id", "approvals_approval"."id" LIMIT 21 ''',