There's more...

When you are performing a CRUD operation through RPC, it might generate an error if you don't have permission to do that operation. With the check_access_rights method, you can check whether the user has the proper access rights to do a certain operation. The check_access_rights method returns True or False values based on the access rights of the user. Here is an example showing whether a user has the rights to create a books record:

from xmlrpc import client

server_url = 'http://localhost:8069'
db_name = 'test-12'
username = 'admin'
password = 'admin'

common = client.ServerProxy('%s/xmlrpc/2/common' % server_url)
user_id = common.authenticate(db_name, username, password, {})

models = client.ServerProxy('%s/xmlrpc/2/object' % server_url)

if user_id:
has_access = models.execute_kw(db_name, user_id, password,
'library.book', 'check_access_rights',
['create'], {'raise_exception': False})
print('Has create access on book:', has_access )
else:
print('Wrong credentials')

# Output: Has create access on book: True

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset