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

[IMP] cetmix_tower_server: Access rules #194

Open
wants to merge 2 commits into
base: 14.0-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
833 changes: 413 additions & 420 deletions cetmix_tower_server/README.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cetmix_tower_server/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"security/cx_tower_variable_value_security.xml",
"security/cx_tower_plan_security.xml",
"security/cx_tower_plan_line_security.xml",
"security/cx_tower_key_security.xml",
"security/cx_tower_plan_line_action_security.xml",
"security/cx_tower_plan_log_security.xml",
"security/cx_tower_server_log_security.xml",
Expand Down
1 change: 1 addition & 0 deletions cetmix_tower_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
from . import cx_tower_server_template
from . import cetmix_tower
from . import cx_tower_variable_option
from . import res_partner
16 changes: 16 additions & 0 deletions cetmix_tower_server/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2025 Cetmix OÜ
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import fields, models


class ResPartner(models.Model):
_inherit = "res.partner"

server_ids = fields.One2many(
string="Servers",
comodel_name="cx.tower.server",
inverse_name="partner_id",
GabbasovDinar marked this conversation as resolved.
Show resolved Hide resolved
help="Cetmix Tower servers that belong to this partner",
)
30 changes: 30 additions & 0 deletions cetmix_tower_server/security/cx_tower_key_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="cx_tower_key_rule_group_manager_access" model="ir.rule">
<field name="name">Tower Key: manager access rule</field>
<field name="model_id" ref="model_cx_tower_key" />
<field name="domain_force">
[
"|",
"&amp;",
("server_id", "=", False),
("server_ssh_ids", "=", False),
"|",
"|",
("server_id.message_partner_ids", "in", [user.partner_id.id]),
("server_ssh_ids.message_partner_ids", "in", [user.partner_id.id]),
("partner_id.server_ids.message_partner_ids", "in", [user.partner_id.id]),
GabbasovDinar marked this conversation as resolved.
Show resolved Hide resolved
]
</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_manager'))]" />
</record>

<record id="cx_tower_key_rule_group_root_access" model="ir.rule">
<field name="name">Tower Key: root access rule</field>
<field name="model_id" ref="model_cx_tower_key" />
<field name="domain_force">[(1, "=", 1)]</field>
<field name="groups" eval="[(4,ref('cetmix_tower_server.group_root'))]" />
</record>

</odoo>
1 change: 0 additions & 1 deletion cetmix_tower_server/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ access_command_manager,Command->Manager,model_cx_tower_command,group_manager,1,1
access_command_root,Command->Root,model_cx_tower_command,group_root,1,1,1,1
access_execute_command_user,Execute Command->User,model_cx_tower_command_execute_wizard,group_user,1,1,1,1
access_execute_plan_user,Execute Plan->User,model_cx_tower_plan_execute_wizard,group_user,1,1,1,1
access_key_user,Key->User,model_cx_tower_key,group_user,1,0,0,0
access_key_manager,Key->Manager,model_cx_tower_key,group_manager,1,1,1,0
access_key_root,Key->Root,model_cx_tower_key,group_root,1,1,1,1
access_command_log_user,Command Log->User,model_cx_tower_command_log,group_user,1,0,0,0
Expand Down
169 changes: 81 additions & 88 deletions cetmix_tower_server/static/description/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cetmix_tower_server/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def test_execute_command_with_keys(self):

def test_user_access_rule(self):
"""Test user access rule"""

# Create the test command
test_command = self.Command.create({"name": "Test command"})

Expand Down
15 changes: 3 additions & 12 deletions cetmix_tower_server/tests/test_key.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have added new access rules. This means you must add access rules to check those new rules to ensure they are working properly.

Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def test_key_creation(self):
def test_key_access_rights(self):
"""Test private key security features"""

# Default message returned instead of key value
SECRET_VALUE_PLACEHOLDER = self.Key.SECRET_VALUE_PLACEHOLDER

# Store key value
self.write_and_invalidate(self.key_1, **{"secret_value": "pepe"})

Expand All @@ -45,15 +42,9 @@ def test_key_access_rights(self):
# Add user to group
self.add_to_group(self.user_bob, "cetmix_tower_server.group_user")

# Get value
key_value = key_bob.secret_value

# Ensure placeholder is used instead of the key value
self.assertEqual(
key_value,
SECRET_VALUE_PLACEHOLDER,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to ensure that SECRET_VALUE_PLACEHOLDER is returned properly., so this test cannot be removed.
If you can modify it or add another one if this one is not working in the new flow.

msg="Must return placeholder '{}'".format(SECRET_VALUE_PLACEHOLDER),
)
with self.assertRaises(AccessError):
# Get value
key_value = key_bob.secret_value

# Test write
with self.assertRaises(AccessError):
Expand Down
Loading