Skip to content

Commit

Permalink
IMPL calls super in group_backend res_users compute_share
Browse files Browse the repository at this point in the history
FIX applies pre-commit
IMPL adds test for share of backend user
FIX pre-commit pass
IMPL removes mail.activity.mixin from dummy model because it is not needed for the test
IMPL renames and divide the base_group_backend into 2 groups one that provide the basic rights and another that allow login in the app
IMPL changes backend ui users to a user type
FIX pre-commit pass
FIX removes useless imports
FIX adds share to group_backend_ui_users
IMPL adds mail_channel to access rights
FIX tests now working
FIX pre-commit pass
  • Loading branch information
FranzPoize authored and bealdav committed Feb 1, 2024
1 parent 48a8d4e commit 93eafb5
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 71 deletions.
2 changes: 1 addition & 1 deletion base_group_backend/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Group backend
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6aed3105c0a4c58cc34c910e88d34a68e14d38a8d549160bbc5b8f276320cda4
!! source digest: sha256:c7397d2b2e542e6918527090ab259d68f9d3b6a25386feccdc38002e51be4e31
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
11 changes: 9 additions & 2 deletions base_group_backend/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
"license": "LGPL-3",
"maintainers": ["oca"],
"website": "https://github.com/OCA/server-backend",
"depends": ["base", "mail"],
"depends": [
"base",
"base_install_request", # weird module, we need to survive with it
"mail",
],
"demo": [
"demo/test-model.xml",
"demo/ir.model.access.csv",
"demo/backend_dummy_model.xml",
"demo/res_partners.xml",
"demo/res_users.xml",
],
"data": [
"data/res-groups.xml",
"data/res_groups.xml",
"data/ir_ui_menu.xml",
"security/ir.model.access.csv",
],
"installable": True,
Expand Down
8 changes: 8 additions & 0 deletions base_group_backend/data/ir_ui_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<odoo>

<record model="ir.ui.menu" id="base.menu_management">
<!-- Allow to avoid to display App menu for backend users -->
<field name="groups_id" eval="[(4, ref('base.group_user'), 0)]" />
</record>

</odoo>
18 changes: 0 additions & 18 deletions base_group_backend/data/res-groups.xml

This file was deleted.

43 changes: 43 additions & 0 deletions base_group_backend/data/res_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<odoo>

<record model="res.groups" id="base_group_backend">
<field name="name">Backend user</field>
<field name="category_id" ref="base.module_category_user_type" />
<field name="comment">
This group is used to gives user backend access.

While users in `base.group_user` gets a lot of default access
which makes hard to define properly records/rules/menu access.

So for maintainability you shouldn't linked any access right, rules,
menu, and so on to this group directly.

The only intent of this groups is to be able to get a session
to Odoo backend (`/web`).
</field>
</record>

<record model="res.groups" id="group_backend_ui_users">
<field name="name">Backend UI user</field>
<field name="category_id" ref="base.module_category_user_type" />
<field name="comment">
This group is used to gives user basic ui access.
</field>
<field
name="rule_groups"
eval="[
(6, 0,[
ref('base.ir_default_user_rule'),
ref('base.ir_filters_delete_own_rule'),
ref('base.ir_filters_employee_rule'),
ref('base.res_company_rule_employee'),
ref('mail.ir_rule_mail_notifications_group_user'),
ref('mail.ir_rule_mail_channel_member_group_user'),
ref('mail.mail_activity_rule_user'),
ref('mail.mail_channel_rule'),
]),
]"
/>
</record>

</odoo>
1 change: 0 additions & 1 deletion base_group_backend/demo/backend_dummy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

class BackendDummyModel(models.Model):
_name = "backend.dummy.model"
_inherit = ["mail.activity.mixin"]
_description = "Backend Dummy Model demo"

my_value = fields.Char(name="Value", required=True)
Expand Down
11 changes: 5 additions & 6 deletions base_group_backend/demo/backend_dummy_model.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<odoo noupdate="1">
<record id="backend_dummy_model_tree_view" model="ir.ui.view">
<field name="name">Backend dummy tree view</field>
<field name="model">backend.dummy.model</field>
<field name="arch" type="xml">
<tree create="false" delete="false">
<field name="my_value" />
<field name="my_other_value" />
<field name="my_other_value" groups="base.group_user" />
</tree>
</field>
</record>
Expand All @@ -24,20 +23,20 @@
id="menu_dummy_root"
name="Dummy"
sequence="100"
groups="group_backend,base.group_user"
groups="group_backend_ui_users,base.group_user"
/>
<menuitem
id="menu_dummy_menu"
name="Dummy"
sequence="10"
groups="group_backend,base.group_user"
groups="group_backend_ui_users,base.group_user"
parent="menu_dummy_root"
/>
<menuitem
id="menu_dummy_list"
name="Dummy list"
sequence="100"
groups="group_backend,base.group_user"
groups="group_backend_ui_users,base.group_user"
parent="menu_dummy_root"
action="action_dummy_list"
/>
Expand Down
2 changes: 1 addition & 1 deletion base_group_backend/demo/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"backend_dummy_models","backend dummy.model","model_backend_dummy_model",group_backend,1,0,0,0
"backend_dummy_models","backend dummy.model","model_backend_dummy_model",group_backend_ui_users,1,0,0,0
"backend_dummy_models_user_grp","backend dummy.model user grp","model_backend_dummy_model",base.group_user,1,0,0,0
12 changes: 12 additions & 0 deletions base_group_backend/demo/res_partners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="demo_partner" model="res.partner">
<field name="name">Demo partner backend</field>
</record>
<record id="demo_partner1" model="res.partner">
<field name="name">Demo partner backend 1</field>
</record>
<record id="demo_partner2" model="res.partner">
<field name="name">Demo partner backend 2</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions base_group_backend/demo/res_users.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="user_demo" model="res.users">
<field name="login">demo backend user</field>
<field name="groups_id" eval="[Command.set([ref('base.group_user')])]" />
<field name="partner_id" ref="base_group_backend.demo_partner" />
</record>
<record id="user_demo_external" model="res.users">
<field name="login">demo backend user 1</field>
<field name="groups_id" eval="[Command.set([ref('base.group_portal')])]" />
<field name="partner_id" ref="base_group_backend.demo_partner1" />
</record>
<record id="user_demo_external_with_ui" model="res.users">
<field name="login">demo backend user 2</field>
<field
name="groups_id"
eval="[Command.set([ref('base_group_backend.group_backend_ui_users')])]"
/>
<field name="partner_id" ref="base_group_backend.demo_partner2" />
</record>
</odoo>
5 changes: 2 additions & 3 deletions base_group_backend/demo/test-model.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<odoo>

<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="backend.dummy.model" id="dummy_model_1">
<field name="my_value">hello</field>
<field name="my_other_value">hello</field>
</record>

</odoo>
1 change: 0 additions & 1 deletion base_group_backend/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from odoo.tools import config
from . import res_users
21 changes: 13 additions & 8 deletions base_group_backend/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class Users(models.Model):
_inherit = "res.users"

# TODO: (franz) make it clear why we test with "." group and why the share = True
@api.model
def has_group(self, group_ext_id):
"""While ensuring a user is part of `base.group_user` this code will
Expand All @@ -25,21 +24,27 @@ def has_group(self, group_ext_id):
res = super().has_group(group_ext_id)
if not res and (group_ext_id == "base.group_user"):
has_base_group_backend = super().has_group(
"base_group_backend.group_backend"
)
"base_group_backend.base_group_backend"
) or super().has_group("base_group_backend.group_backend_ui_users")
if has_base_group_backend:
_logger.warning("Forcing has_group to return True for group_backend")
_logger.warning(
"Forcing has_group to return True"
+ " for group_backend and base_group_backend_ui_users"
)
return has_base_group_backend
return res

@api.depends("groups_id")
def _compute_share(self):
user_group_id = self.env["ir.model.data"]._xmlid_to_res_id("base.group_user")
res = super()._compute_share()
backend_user_group_id = self.env["ir.model.data"]._xmlid_to_res_id(
"base_group_backend.group_backend"
"base_group_backend.base_group_backend"
)
backend_ui_user_group_id = self.env["ir.model.data"]._xmlid_to_res_id(
"base_group_backend.group_backend_ui_users"
)
internal_users = self.filtered_domain(
[("groups_id", "in", [user_group_id, backend_user_group_id])]
[("groups_id", "in", [backend_user_group_id, backend_ui_user_group_id])]
)
internal_users.share = False
(self - internal_users).share = True
return res
5 changes: 5 additions & 0 deletions base_group_backend/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Current module depends on `base_install_request` instead of `base`.

We don't need `base_install_request` auto install module but we must override it to set a security group on `App` menu.

This dependency should be remove if possible in future versions.
44 changes: 32 additions & 12 deletions base_group_backend/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
res_users_backend,backend user res.users,base.model_res_users,group_backend,1,0,0,0
res_partner_backend,backend user res.partner,base.model_res_partner,group_backend,1,0,0,0
ir_ui_menu_backend,backend user ir.ui.menu,base.model_ir_ui_menu,group_backend,1,0,0,0
ir_filter_backend,backend user ir.filters,base.model_ir_filters,group_backend,1,1,1,1
bus_presence_backend,backend user bus.presence,bus.model_bus_presence,group_backend,1,1,1,1
mail_channel_member_backend,backend user mail.channel.member,mail.model_mail_channel_member,group_backend,1,1,1,0
mail_channel_backend,backend user mail.group,mail.model_mail_channel,group_backend,1,1,1,0
mail_notification_backend,backend user mail.notification,mail.model_mail_notification,group_backend,1,1,1,0
mail_activity_backend,backend user mail.activity,mail.model_mail_activity,group_backend,1,1,1,1
mail_activity_type_backend,backend user mail.activity.type,mail.model_mail_activity_type,group_backend,1,0,0,0
ir_attachment_group_backend,backend user ir.attachment,base.model_ir_attachment,group_backend,1,0,0,0
mail_followers_backend,backend user mail.followers,mail.model_mail_followers,group_backend,1,0,0,0
backend_ui_users_ir_default,backend_ui_users_ir_default,base.model_ir_default,group_backend_ui_users,1,1,1,1
backend_ui_users_ir_filters,backend_ui_users_ir_filters,base.model_ir_filters,group_backend_ui_users,1,1,1,1
backend_ui_users_ir_model,backend_ui_users_ir_model,base.model_ir_model,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_model_fields,backend_ui_users_ir_model_fields,base.model_ir_model_fields,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_model_data,backend_ui_users_ir_model_data,base.model_ir_model_data,group_backend_ui_users,1,0,1,0
backend_ui_users_ir_model_fields_selection,backend_ui_users_ir_model_fields_selection,base.model_ir_model_fields_selection,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_sequence,backend_ui_users_ir_sequence,base.model_ir_sequence,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_sequence_date_range,backend_ui_users_ir_sequence_date_range,base.model_ir_sequence_date_range,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_ui_menu,backend_ui_users_ir_ui_menu,base.model_ir_ui_menu,group_backend_ui_users,1,0,0,0
backend_ui_users_ir_attachment,backend_ui_users_ir_attachment,base.model_ir_attachment,group_backend_ui_users,1,0,1,0
backend_ui_users_res_partner,backend_ui_users_res_partner,base.model_res_partner,group_backend_ui_users,1,0,0,0
backend_ui_users_bus_presence,backend_ui_users_bus_presence,bus.model_bus_presence,group_backend_ui_users,1,1,1,1
backend_ui_users_mail_channel_member_public,backend_ui_users_mail_channel_member,mail.model_mail_channel_member,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_channel_public,backend_ui_users_mail_channel_member,mail.model_mail_channel,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_activity,backend_ui_users_mail_activity,mail.model_mail_activity,group_backend_ui_users,1,1,1,1
backend_ui_users_mail_activity_type,backend_ui_users_mail_activity_type,mail.model_mail_activity_type,group_backend_ui_users,1,0,0,0
backend_ui_users_mail_followers,backend_ui_users_mail_followers,mail.model_mail_followers,group_backend_ui_users,1,0,0,0
backend_ui_users_mail_mail,backend_ui_users_mail_mail,mail.model_mail_mail,group_backend_ui_users,0,0,0,0
backend_ui_users_mail_compose_message,backend_ui_users_mail_compose_message,mail.model_mail_compose_message,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_wizard_invite,backend_ui_users_mail_wizard_invite,mail.model_mail_wizard_invite,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_template,backend_ui_users_mail_template,mail.model_mail_template,group_backend_ui_users,1,0,0,0
backend_ui_users_mail_template_preview,backend_ui_users_mail_template_preview,mail.model_mail_template_preview,group_backend_ui_users,1,0,0,0
backend_ui_users_mail_message,backend_ui_users_mail_message,mail.model_mail_message,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_resend_message,backend_ui_users_mail_resend_message,mail.model_mail_resend_message,group_backend_ui_users,1,1,1,0
backend_ui_users_mail_notification,backend_ui_users_mail_notification,mail.model_mail_notification,group_backend_ui_users,1,1,1,1
backend_ui_users_mail_alias,backend_ui_users_mail_alias,mail.model_mail_alias,group_backend_ui_users,1,0,0,0
backend_ui_users_res_groups,backend_ui_users_res_groups,base.model_res_groups,group_backend_ui_users,1,0,0,0
backend_ui_users_res_partner_category,backend_ui_users_res_partner_category,base.model_res_partner_category,group_backend_ui_users,1,0,0,0
backend_ui_users_res_partner_industry,backend_ui_users_res_partner_industry,base.model_res_partner_industry,group_backend_ui_users,1,0,0,0
backend_ui_users_res_users_identitycheck,backend_ui_users_res_users_identitycheck,base.model_res_users_identitycheck,group_backend_ui_users,1,1,1,0
backend_ui_users_res_bank,backend_ui_users_res_bank,base.model_res_bank,group_backend_ui_users,1,0,0,0
backend_ui_users_res_partner_bank,backend_ui_users_res_partner_bank,base.model_res_partner_bank,group_backend_ui_users,1,0,0,0
Loading

0 comments on commit 93eafb5

Please sign in to comment.