Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF][IMP] Access Rules for Variables and Values with Tests #166

Closed
wants to merge 10 commits into from
831 changes: 412 additions & 419 deletions cetmix_tower_server/README.rst

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions cetmix_tower_server/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright Cetmix OU
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Cetmix Tower Server Management",
"summary": "Flexible Server Management directly from Odoo",
Expand All @@ -23,6 +24,7 @@
"security/cx_tower_server_security.xml",
"security/cx_tower_command_security.xml",
"security/cx_tower_variable_value_security.xml",
"security/cx_tower_variable_security.xml",
"security/cx_tower_plan_security.xml",
"security/cx_tower_plan_line_security.xml",
"security/cx_tower_plan_line_action_security.xml",
Expand Down
16 changes: 8 additions & 8 deletions cetmix_tower_server/models/cx_tower_access_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class CxTowerAccessMixin(models.AbstractModel):
_name = "cx.tower.access.mixin"
_description = "Cetmix Tower access mixin"

access_level = fields.Selection(
tendil marked this conversation as resolved.
Show resolved Hide resolved
lambda self: self._selection_access_level(),
string="Access Level",
default=lambda self: self._default_access_level(),
groups="cetmix_tower_server.group_root,cetmix_tower_server.group_manager",
required=True,
)

def _selection_access_level(self):
"""Available access levels

Expand All @@ -31,11 +39,3 @@ def _default_access_level(self):
Char: `access_level` field selection value
"""
return "2"

access_level = fields.Selection(
lambda self: self._selection_access_level(),
string="Access Level",
default=lambda self: self._default_access_level(),
groups="cetmix_tower_server.group_root,cetmix_tower_server.group_manager",
required=True,
)
2 changes: 1 addition & 1 deletion cetmix_tower_server/models/cx_tower_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TowerVariable(models.Model):
_name = "cx.tower.variable"
_description = "Cetmix Tower Variable"
_inherit = ["cx.tower.reference.mixin"]
_inherit = ["cx.tower.reference.mixin", "cx.tower.access.mixin"]

_order = "name"

Expand Down
1 change: 1 addition & 0 deletions cetmix_tower_server/models/cx_tower_variable_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TowerVariableValue(models.Model):
_description = "Cetmix Tower Variable Values"
_inherit = [
"cx.tower.reference.mixin",
"cx.tower.access.mixin",
]
_rec_name = "variable_reference"
_order = "variable_reference"
Expand Down
26 changes: 26 additions & 0 deletions cetmix_tower_server/security/cx_tower_variable_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- user -->
<record id="cx_tower_variable_rule_group_user_access" model="ir.rule">
<field name="name">Tower Variable: User Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable" />
<field name="domain_force">[('access_level', '=', '1')]</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_user'))]" />
</record>

<!-- manager -->
<record id="cx_tower_variable_rule_group_manager_access" model="ir.rule">
<field name="name">Tower Variable: Manager Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable" />
<field name="domain_force">[('access_level', 'in', ['2'])]</field>
tendil marked this conversation as resolved.
Show resolved Hide resolved
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_manager'))]" />
</record>

<!-- root -->
<record id="cx_tower_variable_rule_group_root_access" model="ir.rule">
<field name="name">Tower Variable: Root Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_root'))]" />
</record>
</odoo>
45 changes: 33 additions & 12 deletions cetmix_tower_server/security/cx_tower_variable_value_security.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="cx_tower_variable_value_rule_group_manager_access" model="ir.rule">
<field name="name">Tower variable value: manager access rule</field>
<field name="model_id" ref="model_cx_tower_variable_value" />
<field name="domain_force">['|', ('is_global', '=', True),
('server_id.message_partner_ids', 'in', [user.partner_id.id])]</field>
<field
<!-- user -->
<record id="cx_tower_variable_value_rule_group_user_access" model="ir.rule">
<field name="name">Tower Variable Value: User Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable_value" />
<field name="domain_force">
['|',
('is_global', '=', True),
tendil marked this conversation as resolved.
Show resolved Hide resolved
'&amp;',
('variable_id.access_level', '=', '1'),
tendil marked this conversation as resolved.
Show resolved Hide resolved
('server_id.message_partner_ids', 'in', [user.partner_id.id])
]
</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_user'))]" />
</record>

<!-- manager -->
<record id="cx_tower_variable_value_rule_group_manager_access" model="ir.rule">
<field name="name">Tower Variable Value: Manager Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable_value" />
<field name="domain_force">
['|',
('is_global', '=', True),
'&amp;',
('variable_id.access_level', 'in', ['2']),
tendil marked this conversation as resolved.
Show resolved Hide resolved
('server_id.message_partner_ids', 'in', [user.partner_id.id])
]
</field>
<field
name="groups"
eval="[(4, ref('cetmix_tower_server.group_user')), (4, ref('cetmix_tower_server.group_manager'))]"
eval="[(4, ref('cetmix_tower_server.group_manager'))]"
/>
</record>

</record>


<!-- root -->
<record id="cx_tower_variable_value_rule_group_root_access" model="ir.rule">
<field name="name">Tower variable value: root access rule</field>
<field name="name">Tower Variable Value: Root Access Rule</field>
<field name="model_id" ref="model_cx_tower_variable_value" />
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4,ref('cetmix_tower_server.group_root'))]" />
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_root'))]" />
</record>

</odoo>
Loading
Loading