mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] fix login controller, fix public & private endpoints, add cors
This commit is contained in:
committed by
Darío Lodeiros
parent
6f672029f5
commit
af960fcec3
@@ -5,9 +5,11 @@ class BaseRestPrivateApiController(main.RestController):
|
|||||||
_root_path = "/api/"
|
_root_path = "/api/"
|
||||||
_collection_name = "pms.private.services"
|
_collection_name = "pms.private.services"
|
||||||
_default_auth = "jwt_api_pms"
|
_default_auth = "jwt_api_pms"
|
||||||
|
_default_cors = "*"
|
||||||
|
|
||||||
|
|
||||||
class BaseRestPublicApiController(main.RestController):
|
class BaseRestPublicApiController(main.RestController):
|
||||||
_root_path = "/auth/"
|
_root_path = "/auth/"
|
||||||
_collection_name = "pms.public.services"
|
_collection_name = "pms.public.services"
|
||||||
_default_auth = "public"
|
_default_auth = "public"
|
||||||
|
_default_cors = "*"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class PmsCalendarService(Component):
|
|||||||
_inherit = "base.rest.service"
|
_inherit = "base.rest.service"
|
||||||
_name = "pms.private.services"
|
_name = "pms.private.services"
|
||||||
_usage = "calendar"
|
_usage = "calendar"
|
||||||
_collection = "pms.reservation.service"
|
_collection = "pms.private.services"
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
@@ -62,7 +62,6 @@ class PmsCalendarService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
input_param=Datamodel("pms.calendar.swap.info", is_list=False),
|
input_param=Datamodel("pms.calendar.swap.info", is_list=False),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def swap_reservation_slices(self, swap_info):
|
def swap_reservation_slices(self, swap_info):
|
||||||
room_id_a = swap_info.roomIdA
|
room_id_a = swap_info.roomIdA
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ class PmsFolioService(Component):
|
|||||||
],
|
],
|
||||||
input_param=Datamodel("pms.folio.search.param"),
|
input_param=Datamodel("pms.folio.search.param"),
|
||||||
output_param=Datamodel("pms.folio.info", is_list=True),
|
output_param=Datamodel("pms.folio.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_folios(self, folio_search_param):
|
def get_folios(self, folio_search_param):
|
||||||
domain = []
|
domain = []
|
||||||
@@ -117,7 +116,6 @@ class PmsFolioService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
output_param=Datamodel("pms.reservation.info"),
|
output_param=Datamodel("pms.reservation.info"),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_reservation(self, folio_id, reservation_id):
|
def get_reservation(self, folio_id, reservation_id):
|
||||||
reservation = (
|
reservation = (
|
||||||
@@ -190,7 +188,6 @@ class PmsFolioService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
output_param=Datamodel("pms.checkin.partner.info", is_list=True),
|
output_param=Datamodel("pms.checkin.partner.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_checkin_partners(self, folio_id, reservation_id):
|
def get_checkin_partners(self, folio_id, reservation_id):
|
||||||
reservation = (
|
reservation = (
|
||||||
@@ -236,7 +233,6 @@ class PmsFolioService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
output_param=Datamodel("pms.payment.info", is_list=True),
|
output_param=Datamodel("pms.payment.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_folio_payments(self, folio_id):
|
def get_folio_payments(self, folio_id):
|
||||||
folio = (
|
folio = (
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ class PmsPartnerService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
input_param=Datamodel("pms.api.rest.user.input", is_list=False),
|
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 = (
|
user_record = (
|
||||||
self.env["res.users"].sudo().search([("login", "=", user.username)])
|
self.env["res.users"].sudo().search([("login", "=", user.username)])
|
||||||
@@ -36,12 +36,7 @@ class PmsPartnerService(Component):
|
|||||||
|
|
||||||
if not user_record:
|
if not user_record:
|
||||||
ValidationError(_("user or password not valid"))
|
ValidationError(_("user or password not valid"))
|
||||||
try:
|
user_record.with_user(user_record)._check_credentials(user.password, None)
|
||||||
user_record.with_user(user_record)._check_credentials(user.password, None)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
raise UserError("")
|
|
||||||
|
|
||||||
PmsApiRestUserOutput = self.env.datamodels["pms.api.rest.user.output"]
|
PmsApiRestUserOutput = self.env.datamodels["pms.api.rest.user.output"]
|
||||||
expiration_date = time.time() + 36660
|
expiration_date = time.time() + 36660
|
||||||
token = jwt.encode(
|
token = jwt.encode(
|
||||||
@@ -55,62 +50,4 @@ class PmsPartnerService(Component):
|
|||||||
key="pms_secret_key_example",
|
key="pms_secret_key_example",
|
||||||
algorithm=jwt.ALGORITHMS.HS256,
|
algorithm=jwt.ALGORITHMS.HS256,
|
||||||
)
|
)
|
||||||
# return PmsApiRestUserOutput(token=token)
|
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 {}
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from odoo.addons.base_rest import restapi
|
from odoo.addons.base_rest import restapi
|
||||||
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
from odoo.addons.base_rest_datamodel.restapi import Datamodel
|
||||||
from odoo.addons.component.core import Component
|
from odoo.addons.component.core import Component
|
||||||
@@ -9,7 +7,7 @@ class PmsPropertyComponent(Component):
|
|||||||
_inherit = "base.rest.service"
|
_inherit = "base.rest.service"
|
||||||
_name = "pms.property.service"
|
_name = "pms.property.service"
|
||||||
_usage = "properties"
|
_usage = "properties"
|
||||||
_collection = "pms.reservation.service"
|
_collection = "pms.private.services"
|
||||||
|
|
||||||
@restapi.method(
|
@restapi.method(
|
||||||
[
|
[
|
||||||
@@ -22,9 +20,8 @@ class PmsPropertyComponent(Component):
|
|||||||
],
|
],
|
||||||
input_param=Datamodel("pms.property.search.param"),
|
input_param=Datamodel("pms.property.search.param"),
|
||||||
output_param=Datamodel("pms.property.info", is_list=True),
|
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 = []
|
domain = []
|
||||||
if property_search_param.name:
|
if property_search_param.name:
|
||||||
domain.append(("name", "like", 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"),
|
output_param=Datamodel("pms.property.info"),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_property(self, property_id):
|
def get_property(self, property_id):
|
||||||
pms_property = (
|
pms_property = (
|
||||||
@@ -86,8 +82,7 @@ class PmsPropertyComponent(Component):
|
|||||||
"GET",
|
"GET",
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
output_param=Datamodel("pms.account.journal.info",is_list=True),
|
output_param=Datamodel("pms.account.journal.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_method_payments_property(self, property_id):
|
def get_method_payments_property(self, property_id):
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class PmsRoomService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
output_param=Datamodel("pms.reservation.info", is_list=True),
|
output_param=Datamodel("pms.reservation.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_reservations(self):
|
def get_reservations(self):
|
||||||
domain = []
|
domain = []
|
||||||
@@ -55,7 +54,6 @@ class PmsRoomService(Component):
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
input_param=Datamodel("pms.calendar.changes", is_list=False),
|
input_param=Datamodel("pms.calendar.changes", is_list=False),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def move_reservation_line(self, reservation_id, reservation_lines_changes):
|
def move_reservation_line(self, reservation_id, reservation_lines_changes):
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class PmsRoomService(Component):
|
|||||||
],
|
],
|
||||||
input_param=Datamodel("pms.room.search.param"),
|
input_param=Datamodel("pms.room.search.param"),
|
||||||
output_param=Datamodel("pms.room.info", is_list=True),
|
output_param=Datamodel("pms.room.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_rooms(self, room_search_param):
|
def get_rooms(self, room_search_param):
|
||||||
domain = []
|
domain = []
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ class PmsRoomTypeService(Component):
|
|||||||
],
|
],
|
||||||
input_param=Datamodel("pms.room.search.param"),
|
input_param=Datamodel("pms.room.search.param"),
|
||||||
output_param=Datamodel("pms.room.info", is_list=True),
|
output_param=Datamodel("pms.room.info", is_list=True),
|
||||||
auth="public",
|
|
||||||
)
|
)
|
||||||
def get_room_types(self, room_type_search_param):
|
def get_room_types(self, room_type_search_param):
|
||||||
domain = []
|
domain = []
|
||||||
|
|||||||
Reference in New Issue
Block a user