Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
1270 Vizualizări

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?

Imagine profil
Abandonează
Autor Cel mai bun răspuns

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)


Imagine profil
Abandonează
Cel mai bun răspuns

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"

Imagine profil
Abandonează
Autor

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.

Related Posts Răspunsuri Vizualizări Activitate
0
mar. 24
874
2
sept. 15
6276
1
apr. 23
2814
2
iul. 25
1413
0
iul. 25
328