diff --git a/pms_api_rest/controllers/pms_rest.py b/pms_api_rest/controllers/pms_rest.py index 5a738e502..d3389b247 100644 --- a/pms_api_rest/controllers/pms_rest.py +++ b/pms_api_rest/controllers/pms_rest.py @@ -5,9 +5,11 @@ class BaseRestPrivateApiController(main.RestController): _root_path = "/api/" _collection_name = "pms.private.services" _default_auth = "jwt_api_pms" + _default_cors = "*" class BaseRestPublicApiController(main.RestController): _root_path = "/auth/" _collection_name = "pms.public.services" _default_auth = "public" + _default_cors = "*" diff --git a/pms_api_rest/services/calendar_service.py b/pms_api_rest/services/calendar_service.py index d7d3d34ae..a420d767c 100644 --- a/pms_api_rest/services/calendar_service.py +++ b/pms_api_rest/services/calendar_service.py @@ -9,7 +9,7 @@ class PmsCalendarService(Component): _inherit = "base.rest.service" _name = "pms.private.services" _usage = "calendar" - _collection = "pms.reservation.service" + _collection = "pms.private.services" @restapi.method( [ @@ -62,7 +62,6 @@ class PmsCalendarService(Component): ) ], input_param=Datamodel("pms.calendar.swap.info", is_list=False), - auth="public", ) def swap_reservation_slices(self, swap_info): room_id_a = swap_info.roomIdA diff --git a/pms_api_rest/services/folio_services.py b/pms_api_rest/services/folio_services.py index 242542d12..0c80a345b 100644 --- a/pms_api_rest/services/folio_services.py +++ b/pms_api_rest/services/folio_services.py @@ -22,7 +22,6 @@ class PmsFolioService(Component): ], input_param=Datamodel("pms.folio.search.param"), output_param=Datamodel("pms.folio.info", is_list=True), - auth="public", ) def get_folios(self, folio_search_param): domain = [] @@ -117,7 +116,6 @@ class PmsFolioService(Component): ) ], output_param=Datamodel("pms.reservation.info"), - auth="public", ) def get_reservation(self, folio_id, reservation_id): reservation = ( @@ -190,7 +188,6 @@ class PmsFolioService(Component): ) ], output_param=Datamodel("pms.checkin.partner.info", is_list=True), - auth="public", ) def get_checkin_partners(self, folio_id, reservation_id): reservation = ( @@ -236,7 +233,6 @@ class PmsFolioService(Component): ) ], output_param=Datamodel("pms.payment.info", is_list=True), - auth="public", ) def get_folio_payments(self, folio_id): folio = ( diff --git a/pms_api_rest/services/login_service.py b/pms_api_rest/services/login_service.py index 82a431a1f..3176b17ba 100644 --- a/pms_api_rest/services/login_service.py +++ b/pms_api_rest/services/login_service.py @@ -26,9 +26,9 @@ class PmsPartnerService(Component): ) ], input_param=Datamodel("pms.api.rest.user.input", is_list=False), - # output_param=Datamodel("pms.api.rest.user.output", is_list=False), + output_param=Datamodel("pms.api.rest.user.output", is_list=False), ) - def aa(self, user): + def login(self, user): user_record = ( self.env["res.users"].sudo().search([("login", "=", user.username)]) @@ -36,12 +36,7 @@ class PmsPartnerService(Component): if not user_record: ValidationError(_("user or password not valid")) - try: - user_record.with_user(user_record)._check_credentials(user.password, None) - - except Exception as e: - raise UserError("") - + user_record.with_user(user_record)._check_credentials(user.password, None) PmsApiRestUserOutput = self.env.datamodels["pms.api.rest.user.output"] expiration_date = time.time() + 36660 token = jwt.encode( @@ -55,62 +50,4 @@ class PmsPartnerService(Component): key="pms_secret_key_example", algorithm=jwt.ALGORITHMS.HS256, ) - # return PmsApiRestUserOutput(token=token) - return token - - def user_error(self): - """ - Simulate an odoo.exceptions.UserError - Should be translated into BadRequest with a description into the json - body - """ - raise UserError(_("UserError message")) - - # Validator - def _validator_user_error(self): - return {} - - def _validator_return_user_error(self): - return {} - - def _validator_validation_error(self): - return {} - - def _validator_return_validation_error(self): - return {} - - def _validator_session_expired(self): - return {} - - def _validator_return_session_expired(self): - return {} - - def _validator_missing_error(self): - return {} - - def _validator_return_missing_error(self): - return {} - - def _validator_access_error(self): - return {} - - def _validator_return_access_error(self): - return {} - - def _validator_access_denied(self): - return {} - - def _validator_return_access_denied(self): - return {} - - def _validator_http_exception(self): - return {} - - def _validator_return_http_exception(self): - return {} - - def _validator_bare_exception(self): - return {} - - def _validator_return_bare_exception(self): - return {} + return PmsApiRestUserOutput(token=token) diff --git a/pms_api_rest/services/property_services.py b/pms_api_rest/services/property_services.py index 926cdd794..afdc37470 100644 --- a/pms_api_rest/services/property_services.py +++ b/pms_api_rest/services/property_services.py @@ -1,5 +1,3 @@ -from datetime import datetime - from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel from odoo.addons.component.core import Component @@ -9,7 +7,7 @@ class PmsPropertyComponent(Component): _inherit = "base.rest.service" _name = "pms.property.service" _usage = "properties" - _collection = "pms.reservation.service" + _collection = "pms.private.services" @restapi.method( [ @@ -22,9 +20,8 @@ class PmsPropertyComponent(Component): ], input_param=Datamodel("pms.property.search.param"), output_param=Datamodel("pms.property.info", is_list=True), - auth="public", ) - def get_properties(self,property_search_param): + def get_properties(self, property_search_param): domain = [] if property_search_param.name: domain.append(("name", "like", property_search_param.name)) @@ -58,7 +55,6 @@ class PmsPropertyComponent(Component): ) ], output_param=Datamodel("pms.property.info"), - auth="public", ) def get_property(self, property_id): pms_property = ( @@ -86,8 +82,7 @@ class PmsPropertyComponent(Component): "GET", ) ], - output_param=Datamodel("pms.account.journal.info",is_list=True), - auth="public", + output_param=Datamodel("pms.account.journal.info", is_list=True), ) def get_method_payments_property(self, property_id): diff --git a/pms_api_rest/services/reservation_services.py b/pms_api_rest/services/reservation_services.py index e922d85b2..db1b3c112 100644 --- a/pms_api_rest/services/reservation_services.py +++ b/pms_api_rest/services/reservation_services.py @@ -21,7 +21,6 @@ class PmsRoomService(Component): ) ], output_param=Datamodel("pms.reservation.info", is_list=True), - auth="public", ) def get_reservations(self): domain = [] @@ -55,7 +54,6 @@ class PmsRoomService(Component): ) ], input_param=Datamodel("pms.calendar.changes", is_list=False), - auth="public", ) def move_reservation_line(self, reservation_id, reservation_lines_changes): diff --git a/pms_api_rest/services/room_services.py b/pms_api_rest/services/room_services.py index 4e10a51e9..ca981708e 100644 --- a/pms_api_rest/services/room_services.py +++ b/pms_api_rest/services/room_services.py @@ -20,7 +20,6 @@ class PmsRoomService(Component): ], input_param=Datamodel("pms.room.search.param"), output_param=Datamodel("pms.room.info", is_list=True), - auth="public", ) def get_rooms(self, room_search_param): domain = [] diff --git a/pms_api_rest/services/room_type_services.py b/pms_api_rest/services/room_type_services.py index 4ca879a54..e6ef7dc23 100644 --- a/pms_api_rest/services/room_type_services.py +++ b/pms_api_rest/services/room_type_services.py @@ -20,7 +20,6 @@ class PmsRoomTypeService(Component): ], input_param=Datamodel("pms.room.search.param"), output_param=Datamodel("pms.room.info", is_list=True), - auth="public", ) def get_room_types(self, room_type_search_param): domain = []