[FIX] fix login controller, fix public & private endpoints, add cors

This commit is contained in:
miguelpadin
2021-12-27 16:31:09 +01:00
committed by Darío Lodeiros
parent 6f672029f5
commit af960fcec3
8 changed files with 10 additions and 85 deletions

View File

@@ -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 = "*"

View File

@@ -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

View File

@@ -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 = (

View File

@@ -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)

View File

@@ -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):

View File

@@ -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):

View File

@@ -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 = []

View File

@@ -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 = []