Skip to content

Commit

Permalink
[IMP]pms_civitfun: adapt auth services
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed May 19, 2023
1 parent ef27377 commit 5fd6a47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 41 deletions.
1 change: 1 addition & 0 deletions pms_civitfun/datamodels/pms_checkin_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CivitfunCheckinPartnerInfo(Datamodel):
position = fields.Integer(required=False, allow_none=True)
email = fields.String(required=False, allow_none=True)
lang = fields.String(required=False, allow_none=True)
language = fields.String(required=False, allow_none=True)
name = fields.String(required=False, allow_none=True)
surname = fields.String(required=False, allow_none=True)
secondSurname = fields.String(required=False, allow_none=True)
Expand Down
50 changes: 16 additions & 34 deletions pms_civitfun/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Unauthorized,
)

import odoo
from odoo.exceptions import (
AccessDenied,
AccessError,
Expand All @@ -18,11 +17,7 @@
from odoo.http import HttpRequest, Root, SessionExpiredException
from odoo.loglevels import ustr

from odoo.addons.base_rest.http import (
HttpRestRequest,
_rest_services_routes,
wrapJsonException,
)
from odoo.addons.base_rest.http import HttpRestRequest, wrapJsonException


class HttpRestRequestCivitfun(HttpRestRequest):
Expand Down Expand Up @@ -72,34 +67,21 @@ def _handle_exception(self, exception):


def get_request(self, httprequest):
db = httprequest.session.db
if db and odoo.service.db.exp_db_exist(db):
# on the very first request processed by a worker,
# registry is not loaded yet
# so we enforce its loading here to make sure that
# _rest_services_databases is not empty
odoo.registry(db)
rest_routes = _rest_services_routes.get(db, [])
for root_path in rest_routes:
if httprequest.path.startswith(root_path):
if "civitfun" in httprequest.path:
if (
"Civitfun-Standard3-Request" in httprequest.environ
and httprequest.environ.get("Civitfun-Standard3-Request")
== "authorization"
):
httprequest.environ["HTTP_AUTHORIZATION"] = httprequest.environ[
"Civitfun-Standard3-Request"
]
if (
"CONTENT_TYPE" in httprequest.environ
and httprequest.environ.get("CONTENT_TYPE")
== "application/json"
):
httprequest.environ[
"CONTENT_TYPE"
] = "application/json-civitfun"
return HttpRestRequestCivitfun(httprequest)
if "civitfun" in httprequest.path:
if (
"HTTP_CIVITFUN_STANDARD3_REQUEST" in httprequest.environ
and httprequest.environ.get("Civitfun-Standard3-Request") == "authorization"
):
httprequest.environ["HTTP_AUTHORIZATION"] = httprequest.environ[
"Civitfun-Standard3-Request"
]
if (
"CONTENT_TYPE" in httprequest.environ
and httprequest.environ.get("CONTENT_TYPE") == "application/json"
and not len(httprequest.get_data().decode(httprequest.charset)) > 0
):
httprequest.environ["CONTENT_TYPE"] = "application/json-civitfun"
return HttpRestRequestCivitfun(httprequest)
return ori_get_request(self, httprequest)


Expand Down
16 changes: 9 additions & 7 deletions pms_civitfun/services/pms_checkin_partner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def _mapped_hosts_info(self, guest):
if guest.customFields.get("phone"):
checkin_vals["phone"] = guest.customFields.get("phone")
if guest.customFields.get("address"):
checkin_vals["residence_street"] = guest.customFields.get("address")
checkin_vals["residence_street"] = guest.customFields.get(
"address"
).splitlines()[0]
res_zip = False
if guest.customFields.get("postalCode"):
zip_code = guest.customFields.get("postalCode")
Expand Down Expand Up @@ -174,10 +176,10 @@ def _mapped_hosts_info(self, guest):
.id
)

partner_vals = {
"lang": self._get_mapped_lang(guest.lang),
}

# partner_vals = {
# "lang": self._get_mapped_lang(guest.lang),
# }
partner_vals = {}
return checkin_vals, partner_vals

def check_reservation(self, reservation):
Expand All @@ -197,8 +199,8 @@ def _get_mapped_lang(self, lang):
("iso_code", "=", lang),
]
)
).code
return pms_lang or False
)
return pms_lang.code or False

def _get_mapped_gender(self, gender):
if gender == "M":
Expand Down

0 comments on commit 5fd6a47

Please sign in to comment.