Skip to content

Commit

Permalink
[IMP] cetmix_tower_server: update tower command log security rule
Browse files Browse the repository at this point in the history
in order to provide access only to records which command access level corresponds the user's one.
  • Loading branch information
Aldeigja committed Jun 30, 2024
1 parent ee51393 commit e82b19e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<field name="name">Tower command log: user access rule</field>
<field name="model_id" ref="model_cx_tower_command_log" />
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_user'))]" />
<field name="domain_force">[('create_uid', '=', user.id)]</field>
<field
name="domain_force"
>[('create_uid', '=', user.id), ('command_id.access_level', '=', '1')]</field>


</record>
Expand Down
4 changes: 0 additions & 4 deletions cetmix_tower_server/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
from . import test_plan
from . import test_file
from . import test_plan_log
<<<<<<< HEAD
from . import test_command_wizard
from . import test_log
=======
from . import test_command_log
>>>>>>> 47c5d54 ([IMP] cetmix_tower_server: rest of command log tests updated)
40 changes: 39 additions & 1 deletion cetmix_tower_server/tests/test_command_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_user_access_rule(self):
# he did't subscribed to
with self.assertRaises(AccessError):
command_name = test_command_log_as_bob.read(["name"])
# Subscibe manager to server and test again
# Subscribe manager to server and test again
self.server_test_1.message_subscribe([self.user_bob.partner_id.id])
command_name = test_command_log_as_bob.read(["name"])
self.assertEqual(
Expand All @@ -54,3 +54,41 @@ def test_user_access_rule(self):
not be able to unlink log entries",
):
test_command_log_as_bob.unlink()

# Create a new command
test_command_1 = self.Command.create(
{
"name": "Test",
"code": "ls",
"access_level": "1",
}
)

# Create a new command log as user_bob
test_command_log_1 = self.CommandLog.create(
{
"server_id": self.server_test_1.id,
"command_id": test_command_1.id,
"create_uid": self.user_bob.id,
}
)

# Remove user_bob from group_manager
self.remove_from_group(
self.user_bob,
[
"cetmix_tower_server.group_manager",
],
)
# Ensure that user_bob has access to test_command_log_1
command_name_1 = test_command_log_1.with_user(self.user_bob).read(["name"])
self.assertEqual(
command_name_1[0]["name"],
test_command_log_1.name,
"Command name should be same",
)
# Update test_command access_level to "2"
test_command_1.write({"access_level": "2"})
# Ensure that user_bob doesn't have access to test_command_log_1 anymore
with self.assertRaises(AccessError):
command_name = test_command_log_1.with_user(self.user_bob).read(["name"])

0 comments on commit e82b19e

Please sign in to comment.