跳至内容
菜单
此问题已终结
2 回复
1269 查看

I want to give the public user access to some data.


But if I use the jsonRPC without credentials I always get a Odoo Session Expired although the permissions would allow my model to be read from a public user.



What can I do to receive data as a public user?

形象
丢弃
编写者 最佳答案

But I want to make my question more precise:

Is it possible to the this jsonrpc working with a session_id of a public user? (not logged in)




import requests

import json


url = "https://73515246-18-0-all.runbot185.odoo.com/web/dataset/call_kw/forum.post/web_search_read"


payload = json.dumps({

"id": 1,

"jsonrpc": "2.0",

"method": "call",

"params": {

"model": "res.partner",

"method": "web_search_read",

"args": [],

"kwargs": {

"specification": {

"name": {}

},

"order": "name",

"domain": [],

"context": {

"uid": None

}

}

}

})

headers = {

'Content-Type': 'application/json',

'Cookie': 'session_id=clfQpy5iv6hb5cq9VacECtum8t2bPZ1OhBwZ5AEr9ya_4xj-I84eUSrEJKSOLhCy9JcXhpOq8QSmusQ3S08M'

}


response = requests.request("GET", url, headers=headers, data=payload)


print(response.text)


形象
丢弃
最佳答案

Just create a publicly accessible controller and use as any REST.
For example, the below GET endpoint can be accessed by just visiting /thank_you.

from odoo import http

class ThankYouController(http.Controller):

​@http.route('/thank_you', auth='public', methods=['GET'], type='http')

​def thank_you(self, **kwargs):

​return "THANK YOU"

形象
丢弃
编写者

Thanks, but the background I need this is because I want to use websearchread an standard OWL method to retrieve data. But If the user is not logged in it does not work. I want to use Owl2 in the frontend which works perfectly with websearchread but as it's also can be used by not logged in users it also has to work with not logged in users.
The core problem can be replicated by creating a json request without authentication. It would be interesting if there is standard way to do this. I had to override some very basic functionality which I want to avoid.

相关帖文 回复 查看 活动
0
3月 24
872
2
9月 15
6276
1
4月 23
2814
2
7月 25
1413
0
7月 25
328