Restrict Url
Restrict Url
access control mechanisms along with custom code in controllers. Here’s how you can achieve
this:
This example restricts access to the restricted.model model to users who belong to
the base.group_user group, allowing read access only.
This example allows users in the base.group_user group to read all records in the
restricted.model model.
1
9 if not user.has_group('your_module.your_group'):
10 return request.redirect('/web/login') # Redirect to login if the
↪ user does not belong to the group
11
12 return "Welcome to the restricted URL!"
This example defines a controller that restricts access to the URL /restricted/url
based on whether the user belongs to a specific group.
2. Define the group in your module: Create a file named security/security.xml
in your module directory.
1 <odoo>
2 <data noupdate="1">
3 <record id="group_restricted_user" model="res.groups">
4 <field name="name">Restricted User</field>
5 </record>
6 </data>
7 </odoo>
3. Update the manifest file: Ensure that your manifest file __manifest__.py includes
references to the security files.
1 {
2 'name': 'Your Module',
3 'version': '1.0',
4 'category': 'Hidden',
5 'description': 'Module to restrict URL access based on user roles or
↪ groups',
6 'depends': ['base'],
7 'data': [
8 'security/security.xml',
9 'security/ir.model.access.csv',
10 'security/ir.rule.csv',
11 'views/views.xml',
12 ],
13 'installable': True,
14 'application': False,
15 }