diff --git a/controllers/main.py b/controllers/main.py index 0239780f17cf092493545250525b5ea6bc5892f0..39fc7f1581588e5804a3d7af7cfd9ddbc232e3ef 100644 --- a/controllers/main.py +++ b/controllers/main.py @@ -1,9 +1,9 @@ # Copyright 2021- Le Filament (https://le-filament.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +import werkzeug -from werkzeug.exceptions import Unauthorized - -from odoo import http +from odoo import _, http +from odoo.exceptions import AccessError from odoo.http import request from odoo.addons.oacc_portal.controllers.main import CustomerPortal as CustomerPortal @@ -172,13 +172,18 @@ class CustomerPortal(CustomerPortal): - When click on date range """ operation = request.env["acc.operation"].browse(operation_id) - roles = self._get_role(operation) - # Si l'opération n'a pas de courbes on renvoie un dictionnaire vide + try: + roles = self._get_role(operation) + except AccessError as e: + raise werkzeug.exceptions.abort( + werkzeug.wrappers.Response(status=401) + ) from e + # Si l'opération n'a pas de courbes on renvoie une erreur 401 # Si l'utilisateur n'est pas soit superAdmin, soit Admin, soit Pmo, # 1. si prm_id est passé il doit aussi y avoir un partner_id # 2. il faut vérifier qu'il est bien autorisé à accéder au partner_id # si passé en paramètre - # sinon on renvoie un dictionnaire vide + # sinon on renvoie une erreur 401 # (on ne vérifie pas qu'il ait bien accès au prm, aucune donnée ne sera renvoyée # si les courbes du prm demandées n'appartiennent pas à ce partner) if not roles.get("isDataCdc") or ( @@ -194,7 +199,7 @@ class CustomerPortal(CustomerPortal): ) ) ): - return {} + raise werkzeug.exceptions.abort(werkzeug.wrappers.Response(status=401)) vals = operation.get_graph( start_date, end_date, partner_id, prm_id, data_type, graph_type ) @@ -224,19 +229,25 @@ class CustomerPortal(CustomerPortal): - When click on button export """ operation = request.env["acc.operation"].sudo().browse(int(operation_id)) - if ( - request.env.user.commercial_partner_id.id - not in operation.partner_role_ids.partner_id.ids - ): - raise Unauthorized() - roles = self._get_role(operation) - # Si l'opération n'a pas de courbes on renvoie un Unauthorized + try: + if ( + request.env.user.commercial_partner_id.id + not in operation.partner_role_ids.partner_id.ids + ): + raise AccessError(_("You are not allowed to access this operation")) + roles = self._get_role(operation) + except AccessError as e: + raise werkzeug.exceptions.abort( + werkzeug.wrappers.Response(status=401) + ) from e + + # Si l'opération n'a pas de courbes on renvoie une erreur 401 # Si l'utilisateur n'est pas soit superAdmin, soit Admin, soit Pmo, # 1. le partner_id est obligatoire # 2. il faut vérifier qu'il est bien autorisé à accéder au partner_id # 3. il faut vérifier que le PRM correspond bien à une période de ce partner_id # sur l'opération - # sinon on renvoie un Unauthorized + # sinon on renvoie une erreur 401 # (on ne vérifie pas qu'il ait bien accès au prm, aucune donnée ne sera renvoyée # si les courbes du prm demandées n'appartiennent pas à ce partner) if not roles.get("isDataCdc") or ( @@ -264,7 +275,8 @@ class CustomerPortal(CustomerPortal): ) ) ): - raise Unauthorized() + raise werkzeug.exceptions.abort(werkzeug.wrappers.Response(status=401)) + file_values = operation._export_cdc( start_date, end_date, partner_id, prm_id, data_type )