@@ -36,27 +36,31 @@ def event_register(self, event, **post):
3636 # Business method
3737 # ------------------------------------------------------
3838 def _check_privacy (self , event , ** post ):
39+ # for private events, check authorization
3940 if event .event_privacy != "public" and not request .env .user .has_group (
4041 "website.group_website_restricted_editor"
4142 ):
43+ # get cookie from http request
4244 cookie = request .httprequest .cookies .get ("odoo-event-%d" % event .id )
43- if (
44- post
45- and post .get ("access_token" )
46- and post .get ("access_token" ) == event .access_token
47- ):
48- access_token = post .get ("access_token" )
49- request .future_response .set_cookie (
50- key = "odoo-event-%d" % event .id ,
51- value = access_token ,
52- max_age = 10 * 86400 ,
53- secure = True ,
54- httponly = True ,
55- samesite = "Strict" ,
56- )
57- return True
58- elif cookie and cookie == event .access_token :
45+ # check if cookie match access token
46+ if cookie and cookie == event .access_token :
5947 return True
60- else :
61- return False
48+ # if cookie does not match, get the cookie from url
49+ if post and post .get ("access_token" ):
50+ access_token = post .get ("access_token" )
51+ # if the cookie is correct, set the cookie accordingly and succeed
52+ if access_token == event .access_token :
53+ request .future_response .set_cookie (
54+ key = "odoo-event-%d" % event .id ,
55+ value = access_token ,
56+ max_age = 10 * 86400 ,
57+ secure = True ,
58+ httponly = True ,
59+ samesite = "Strict" ,
60+ )
61+ return True
62+ # if cookie is incorrect, do not set the cookie and fail
63+ else :
64+ return False
65+ # for public event or if user is authorized, allow access
6266 return True
0 commit comments