Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PC-31860)[BO] feat: transfert all PRO links in BO to connect as exte… #14230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions api/src/pcapi/routes/backoffice/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,13 +1385,7 @@ def install_template_filters(app: Flask) -> None:
app.jinja_env.filters["unescape"] = html.unescape
app.jinja_env.filters["action_to_name"] = action_to_name
app.jinja_env.filters["field_list_get_number_from_name"] = field_list_get_number_from_name
app.jinja_env.filters["pc_pro_bank_account_link"] = urls.build_pc_pro_bank_account_link
app.jinja_env.filters["pc_pro_offer_link"] = urls.build_pc_pro_offer_link
app.jinja_env.filters["pc_pro_offerer_link"] = urls.build_pc_pro_offerer_link
app.jinja_env.filters["pc_pro_venue_bookings_link"] = urls.build_pc_pro_venue_bookings_link
app.jinja_env.filters["pc_pro_venue_offers_link"] = urls.build_pc_pro_venue_offers_link
app.jinja_env.filters["pc_pro_venue_link"] = urls.build_pc_pro_venue_link
app.jinja_env.filters["pc_pro_venue_parameters_link"] = urls.build_pc_pro_venue_parameters_link
app.jinja_env.filters["pc_pro_offer_link"] = urls.build_pc_pro_offer_path
app.jinja_env.filters["pc_backoffice_public_account_link"] = urls.build_backoffice_public_account_link
app.jinja_env.filters["pc_backoffice_public_account_link_in_comment"] = (
urls.build_backoffice_public_account_link_in_comment
Expand Down
22 changes: 22 additions & 0 deletions api/src/pcapi/routes/backoffice/pro/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pcapi import settings
from pcapi.connectors import api_adresse
from pcapi.core.finance import models as finance_models
from pcapi.core.mails import transactional as transactional_mails
from pcapi.core.offerers import api as offerers_api
from pcapi.core.offerers import models as offerers_models
Expand Down Expand Up @@ -358,6 +359,25 @@ def _get_user_id_from_offer_id(offer_id: int) -> int:
return user_id


def _get_user_id_from_bank_account_id(bank_account_id: int) -> int:
if not FeatureToggle.WIP_CONNECT_AS_EXTENDED.is_active():
raise ValueError(
"L'utilisation de la version étendue de « connect as » requiert l'activation de la feature : WIP_CONNECT_AS_EXTENDED"
)
query = get_user_id_for_connect_as_base_query()
user_id = (
query.join(offerers_models.UserOfferer.offerer)
.join(offerers_models.Offerer.bankAccounts)
.filter(finance_models.BankAccount.id == bank_account_id)
.order_by(offerers_models.UserOfferer.id)
.limit(1)
.scalar()
)
if not user_id:
raise ValueError("Aucun utilisateur approprié n'a été trouvé pour se connecter à ce compte bancaire")
return user_id


@pro_blueprint.route("/connect-as", methods=["POST"])
@utils.permission_required(perm_models.Permissions.MANAGE_PRO_ENTITY)
@atomic()
Expand All @@ -371,6 +391,8 @@ def connect_as() -> utils.BackofficeResponse:

try:
match form.object_type.data:
case "bank_account":
user_id = _get_user_id_from_bank_account_id(form.object_id.data)
case "offer":
user_id = _get_user_id_from_offer_id(form.object_id.data)
case "offerer":
Expand Down
1 change: 1 addition & 0 deletions api/src/pcapi/routes/backoffice/pro/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class ConnectAsForm(FlaskForm):
object_id = fields.PCStringField()
object_type = fields.PCSelectField(
choices=(
("bank_account", "bank_account"),
("offer", "offer"),
("offerer", "offerer"),
("user", "user"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<tr>
<th scope="row">{{ build_booking_toggle_extra_row_button(booking) }}</th>
<td>{{ booking.offerer.name | escape }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(booking.stock.offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(booking.stock.offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>
{{ booking.amount | format_amount }}
{% if booking.stock.offer.isDuo and booking.quantity == 2 %}(Duo){% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<tr>
<th scope="row"></th>
<td class="fw-bolder">{{ links.build_venue_name_to_details_link(link_venue.venue, text_attr="id") }}</td>
<td class="text-break">{{ links.build_venue_name_to_pc_pro_link(link_venue.venue) }}</td>
<td class="text-break">
{{ links.build_venue_name_to_pc_pro_link(link_venue.venue, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ link_venue.timespan.lower | format_date_time }}</td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ <h5 class="modal-title">Annuler la réservation {{ collective_booking.id }}</h5>
({{ collective_booking.educationalInstitution.id }})
</td>
<td>{{ collective_booking.educationalRedactor.firstName }} {{ collective_booking.educationalRedactor.lastName }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(collective_offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(collective_offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ links.build_collective_offer_name_to_details_link(collective_offer, text_attr="id") }}</td>
<td>{{ collective_booking.total_amount | format_amount }}</td>
<td>{{ collective_booking | format_booking_status(with_badge=True) | safe }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ <h2 class="fw-light">Offres collectives</h2>
{% endif %}
</td>
<td>{{ links.build_collective_offer_details_link(collective_offer) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(collective_offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(collective_offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ collective_offer.formats | format_collective_offer_formats }}</td>
{% if has_permission("PRO_FRAUD_ACTIONS") %}
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ <h2 class="fw-light">Offres collectives vitrine</h2>
{% endif %}
</td>
<td>{{ links.build_collective_offer_template_details_link(collective_offer_template, text_attr="id") }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(collective_offer_template) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(collective_offer_template, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ collective_offer_template.formats | format_collective_offer_formats }}</td>
{% if has_permission("PRO_FRAUD_ACTIONS") %}
<td>{{ collective_offer_template.flaggingValidationRules | format_offer_validation_rule_list }}</td>
Expand Down
39 changes: 18 additions & 21 deletions api/src/pcapi/routes/backoffice/templates/components/links.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<a href="{{ redirect | build_pro_link }}"
class="{{ class }}"
onclick="document.getElementById('connect-as-form-{{ object_type }}-{{ object_id }}-{{ randomness }}').submit(); return false;">
{{ text_link }}<i class="bi bi-box-arrow-up-right"></i>
{{ text_link }} <i class="bi bi-box-arrow-up-right"></i>
</a>
{% else %}
{{ text_link }}
Expand Down Expand Up @@ -128,30 +128,27 @@
{% macro build_pro_offerer_offers_link(offerer, is_feature_active, has_permission) %}
{{ build_connect_as_pseudo_link(offerer.id, "offerer", "/offres?structure="~offerer.id~"&from-bo=true", "Offres associées", "fw-bold link-primary", is_feature_active, has_permission) }}
{% endmacro %}
{% macro build_offerer_name_to_pc_pro_link(offerer) %}
<a href="{{ offerer | pc_pro_offerer_link }}"
class="link-primary"
target="_blank">{{ offerer.name }} <i class="bi bi-box-arrow-up-right"></i></a>
{% macro build_offerer_name_to_pc_pro_link(offerer, is_feature_active, has_permission) %}
{{ build_connect_as_pseudo_link(offerer.id, "offerer", "/accueil?structure="~offerer.id~"&from-bo=true", offerer.name, "link-primary", is_feature_active, has_permission) }}
{% endmacro %}
{% macro build_venue_name_to_pc_pro_link(venue, public_name=true, siret=false) %}
<a href="{{ venue | pc_pro_venue_link }}"
class="link-primary"
target="_blank">{{ ((public_name and venue.publicName) or venue.name) + ((" - " + venue.siret) if siret else "") }} <i class="bi bi-box-arrow-up-right"></i></a>
{% macro build_venue_name_to_pc_pro_link(venue, is_feature_active, has_permission, public_name=true, siret=false) %}
{% if venue.isVirtual %}
{{ build_connect_as_pseudo_link(venue.id, "venue", "/accueil?structure="~venue.managingOffererId~"&from-bo=true", (((public_name and venue.publicName) or venue.name) + ((" - " + venue.siret) if siret else "")), "link-primary", is_feature_active, has_permission) }}
{% else %}
{{ build_connect_as_pseudo_link(venue.id, "venue", "/structures/"~venue.managingOffererId~"/lieux/"~venue.id~"", (((public_name and venue.publicName) or venue.name) + ((" - " + venue.siret) if siret else "")), "link-primary", is_feature_active, has_permission) }}
{% endif %}
{% endmacro %}
{% macro build_venue_parameters_name_to_pc_pro_link(venue, public_name=true, siret=false) %}
<a href="{{ venue | pc_pro_venue_parameters_link }}"
class="link-primary"
target="_blank">{{ ((public_name and venue.publicName) or venue.name) + ((" - " + venue.siret) if siret else "") }} <i class="bi bi-box-arrow-up-right"></i></a>
{% macro build_venue_parameters_name_to_pc_pro_link(venue, is_feature_active, has_permission) %}
{{ build_connect_as_pseudo_link(venue.id, "venue", "/structures/"~venue.managingOffererId~"/lieux/"~venue.id~"/parametres", (public_name or venue.name) , "link-primary", is_feature_active, has_permission) }}
{% endmacro %}
{% macro build_offer_name_to_pc_pro_link(offer) %}
<a href="{{ offer | pc_pro_offer_link }}"
class="link-primary"
target="_blank">{{ offer.name }} <i class="bi bi-box-arrow-up-right"></i></a>
{% macro build_offer_name_to_pc_pro_link(offer, is_feature_active, has_permission) %}
{# this macro must be on one line or it breaks the connect as feature #}
{# djlint:off #}{% macro build_offer_name_to_pc_pro_url(offer) %}{{ offer | pc_pro_offer_link }}{% endmacro %}{# djlint:on #}
{% set offer_name_to_pc_pro_url = build_offer_name_to_pc_pro_url(offer) %}
{{ build_connect_as_pseudo_link(offer.id, "offer", offer_name_to_pc_pro_url, offer.name , "link-primary", is_feature_active, has_permission) }}
{% endmacro %}
{% macro build_bank_account_name_to_pc_pro_link(bank_account) %}
<a href="{{ bank_account | pc_pro_bank_account_link }}"
class="link-primary"
target="_blank">{{ bank_account.label }} <i class="bi bi-box-arrow-up-right"></i></a>
{% macro build_bank_account_name_to_pc_pro_link(bank_account, is_feature_active, has_permission) %}
{{ build_connect_as_pseudo_link(bank_account.id, "bank_account", "/remboursements/informations-bancaires?structure="~bank_account.offererId~"&from-bo=true", bank_account.label , "link-primary", is_feature_active, has_permission) }}
{% endmacro %}
{# ----- external links ----- #}
{% macro build_siren_to_external_link(offerer) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,32 @@ <h2 class="fw-light">Tarifs dérogatoires</h2>
</td>
<td>{{ reimbursement_rule.id }}</td>
{% if reimbursement_rule.offerer %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offerer) }}</td>
<td>
{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offerer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ reimbursement_rule.offerer.siren }}</td>
<td></td>
<td></td>
{% elif reimbursement_rule.venue %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.venue.managingOfferer) }}</td>
<td>
{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.venue.managingOfferer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ reimbursement_rule.venue.managingOfferer.siren }}</td>
<td>{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.venue, siret=true) }}</td>
<td>
{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.venue, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY"), siret=true) }}
</td>
<td></td>
{% else %}
<td>{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offer.venue.managingOfferer) }}</td>
<td>
{{ links.build_offerer_name_to_pc_pro_link(reimbursement_rule.offer.venue.managingOfferer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ reimbursement_rule.offer.venue.managingOfferer.siren }}</td>
<td>{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.offer.venue) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(reimbursement_rule.offer) }}</td>
<td>
{{ links.build_venue_name_to_pc_pro_link(reimbursement_rule.offer.venue, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(reimbursement_rule.offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
{% endif %}
<td>{{ reimbursement_rule.rate | format_rate_multiply_by_100 }}</td>
<td>{{ reimbursement_rule.amount | format_cents if reimbursement_rule.amount else "" }}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
</td>
<td>{{ links.build_public_user_name_to_details_link(booking_finance_incident.beneficiary) }}</td>
<td>{{ booking_finance_incident.booking | format_booking_status(with_badge=True) | safe }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(booking_finance_incident.booking.stock.offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(booking_finance_incident.booking.stock.offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ booking_finance_incident.booking.dateCreated | format_date("Le %d/%m/%Y à %Hh%M") }}</td>
</tr>
<tr class="collapse accordion-collapse pc-booking-{{ booking_finance_incident.booking.id }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
<td>{{ booking_finance_incident.collectiveBooking.educationalInstitution.name }}</td>
<td>{{ booking_finance_incident.collectiveBooking.userName }}</td>
<td>{{ booking_finance_incident.collectiveBooking | format_booking_status(with_badge=True) | safe }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(booking_finance_incident.collectiveBooking.collectiveStock.collectiveOffer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(booking_finance_incident.collectiveBooking.collectiveStock.collectiveOffer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ booking_finance_incident.collectiveBooking.dateCreated | format_date("Le %d/%m/%Y à %Hh%M") }}</td>
</tr>
<tr class="collapse accordion-collapse pc-booking-{{ booking_finance_incident.collectiveBooking.id }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ <h5 class="modal-title">Annuler la réservation {{ booking.token }}</h5>
<td>{{ booking.id }}</td>
<td>{{ booking.token }}</td>
<td>{{ links.build_public_user_name_to_details_link(booking.user) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ links.build_offer_name_to_details_link(offer, text_attr="id") }}</td>
<td>{{ (offer.isDuo and booking.quantity == 2) | format_bool }}</td>
<td>{{ booking.stock.quantity }}</td>
Expand Down
4 changes: 3 additions & 1 deletion api/src/pcapi/routes/backoffice/templates/offer/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<div class="card-body">
<div class="row justify-content-start align-items-center">
<div class="col d-flex align-items-center justify-content-start">
<h2 class="card-title mb-3 text-primary">{{ links.build_offer_name_to_pc_pro_link(offer) }}</h2>
<h2 class="card-title mb-3 text-primary">
{{ links.build_offer_name_to_pc_pro_link(offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</h2>
<span class="fs-5 ps-4">
{% if offer.lastProviderId %}
<span class="me-2 badge rounded-pill text-bg-secondary align-middle">
Expand Down
4 changes: 3 additions & 1 deletion api/src/pcapi/routes/backoffice/templates/offer/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ <h2 class="fw-light">Offres individuelles</h2>
</div>
</td>
<td>{{ links.build_offer_details_link(offer) }}</td>
<td>{{ links.build_offer_name_to_pc_pro_link(offer) }}</td>
<td>
{{ links.build_offer_name_to_pc_pro_link(offer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ offer.subcategoryId | format_offer_category }}</td>
<td>{{ offer.subcategoryId | format_offer_subcategory }}</td>
{% if not has_permission("PRO_FRAUD_ACTIONS") %}
Expand Down
4 changes: 3 additions & 1 deletion api/src/pcapi/routes/backoffice/templates/offerer/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<div class="card shadow">
<div class="card-body">
<div class="d-flex flex-fill align-items-center">
<h2 class="card-title text-primary">{{ links.build_offerer_name_to_pc_pro_link(offerer) }}</h2>
<h2 class="card-title text-primary">
{{ links.build_offerer_name_to_pc_pro_link(offerer, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</h2>
<span class="fs-5 ps-4">{{ build_offerer_badges(offerer) }}</span>
<div class="d-flex row-reverse justify-content-end flex-grow-1">
{% if has_permission("MANAGE_PRO_ENTITY") %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<tr>
<th scope="row"></th>
<td class="fw-bolder">{{ links.build_bank_account_name_to_details_link(bank_account, text_attr="id") }}</td>
<td class="text-break">{{ links.build_bank_account_name_to_pc_pro_link(bank_account) }}</td>
<td class="text-break">
{{ links.build_bank_account_name_to_pc_pro_link(bank_account, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ bank_account.status | format_dms_application_status }}</td>
</tr>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<tr>
<th scope="row"></th>
<td class="fw-bolder">{{ links.build_venue_name_to_details_link(venue, text_attr="id") }}</td>
<td class="text-break">{{ links.build_venue_name_to_pc_pro_link(venue) }}</td>
<td class="text-break">
{{ links.build_venue_name_to_pc_pro_link(venue, is_feature_active("WIP_CONNECT_AS_EXTENDED") , has_permission("MANAGE_PRO_ENTITY")) }}
</td>
<td>{{ links.build_siret_to_external_link(venue) }}</td>
<td>
{% if venue.isPermanent %}<span class="visually-hidden">Lieu permanent</span><i class="bi bi-check-circle-fill"></i>{% endif %}
Expand Down
Loading
Loading