Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1273 Widoki

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?

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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)


Awatar
Odrzuć
Najlepsza odpowiedź

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"

Awatar
Odrzuć
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.

Powiązane posty Odpowiedzi Widoki Czynność
0
mar 24
875
2
wrz 15
6276
1
kwi 23
2814
2
lip 25
1414
0
lip 25
328