Skip to content

Commit

Permalink
[IMP] cetmix_tower_server Command Log access
Browse files Browse the repository at this point in the history
- Fix access rules
- Fix tests
  • Loading branch information
ivs-cetmix authored and Aldeigja committed Oct 23, 2024
1 parent 4a4a09f commit 265ffdb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 48 deletions.
10 changes: 5 additions & 5 deletions cetmix_tower_server/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ command or ``Path`` field in flight plan line.
cat my_doge_memes.txt
.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/user_profile.png
.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_tab.png
.. |User profile| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/user_profile.png
.. |Server logs tab| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_tab.png

Usage
=====
Expand Down Expand Up @@ -961,9 +961,9 @@ are located in a special abstract model "cetmix.tower". You can check
those functions in the source code in the following file:
``models/cetmix_tower.py``

.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_from_template_auto_action.png
.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_1.png
.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_2.png
.. |Automatic action| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_from_template_auto_action.png
.. |Open server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_1.png
.. |Update server log| image:: https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_2.png

Bug Tracker
===========
Expand Down
23 changes: 14 additions & 9 deletions cetmix_tower_server/security/cx_tower_command_log_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
<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), ('access_level', '=', '1')]</field>


<field name="domain_force">[
"|",
('create_uid', '=', user.id),
"&amp;",
('server_id.message_partner_ids', 'in', [user.partner_id.id]),
('access_level', '=', '1')]
</field>
</record>

<record id="cx_tower_command_log_rule_group_manager_access" model="ir.rule">
<field name="name">Tower command log: manager access rule</field>
<field name="model_id" ref="model_cx_tower_command_log" />
<field name="domain_force">[
('server_id.message_partner_ids', 'in', [user.partner_id.id])]</field>
<field name="groups" eval="[(4, ref('cetmix_tower_server.group_manager'))]" />


<field name="domain_force">[
"|",
('create_uid', '=', user.id),
"&amp;",
('server_id.message_partner_ids', 'in', [user.partner_id.id]),
('access_level', '&lt;=', '2')]
</field>
</record>


Expand Down
23 changes: 9 additions & 14 deletions cetmix_tower_server/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -369,7 +368,7 @@ <h1 class="title">Cetmix Tower Server Management</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:965f9c95041ea94d3274be7d9f1063ee80c2c6cfa68aa1b0c53b015a6d728468
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/cetmix/cetmix-tower/tree/14.0-dev/cetmix_tower_server"><img alt="cetmix/cetmix-tower" src="https://img.shields.io/badge/github-cetmix%2Fcetmix--tower-lightgray.png?logo=github" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/cetmix/cetmix-tower/tree/14.0/cetmix_tower_server"><img alt="cetmix/cetmix-tower" src="https://img.shields.io/badge/github-cetmix%2Fcetmix--tower-lightgray.png?logo=github" /></a></p>
<p><a class="reference external" href="http://cetmix.com/tower">Cetmix Tower</a> offers a streamlined solution
for managing remote servers via SSH or API calls directly from
<a class="reference external" href="https:/odoo.com">Odoo</a>. It is designed for versatility across
Expand Down Expand Up @@ -474,7 +473,7 @@ <h2>User access configuration</h2>
to in the the user settings. To configure it go to
<tt class="docutils literal">Setting/Users &amp; Companies/Users</tt> and open a user whom you would like
to provide access to the Cetmix Tower.</p>
<p><img alt="User profile" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/user_profile.png" /></p>
<p><img alt="User profile" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/user_profile.png" /></p>
<p>In <tt class="docutils literal">Other</tt> section find the <tt class="docutils literal">Cetmix Tower</tt> field and select one of
the following options:</p>
<ul class="simple">
Expand Down Expand Up @@ -995,7 +994,7 @@ <h2>Configure a Server Log</h2>
<p>Server Logs allow to fetch and view logs of a server fast and convenient
way. To configure a Server Log open the server form, navigate to the
<tt class="docutils literal">Server Logs</tt> tab and add a new record in the list.</p>
<p><img alt="Server logs tab" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_tab.png" /></p>
<p><img alt="Server logs tab" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_tab.png" /></p>
<p>Following fields are available:</p>
<ul class="simple">
<li><strong>Name</strong>: Readable name of the log</li>
Expand Down Expand Up @@ -1130,7 +1129,7 @@ <h2>Create a new Server from a Server Template</h2>
</pre>
<p>Here is a short example of an Odoo automated action that creates a new
server when a Sales Order is confirmed:</p>
<p><img alt="Automatic action" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_from_template_auto_action.png" /></p>
<p><img alt="Automatic action" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_from_template_auto_action.png" /></p>
<pre class="code python literal-block">
<span class="k">for</span> <span class="n">record</span> <span class="ow">in</span> <span class="n">records</span><span class="p">:</span><span class="w">

Expand Down Expand Up @@ -1226,14 +1225,14 @@ <h2>Check a Server Log</h2>
up window. Or click on the <tt class="docutils literal">Open</tt> button <strong>(2)</strong> to open it in the
full form view</li>
</ul>
<p><img alt="Open server log" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_1.png" /></p>
<p><img alt="Open server log" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_1.png" /></p>
<ul class="simple">
<li>Click the <tt class="docutils literal">Refresh</tt> button to update the log. You can also click
the <tt class="docutils literal">Refresh All</tt> button <strong>(3)</strong> located above the log list in
order to refresh all logs at once. Log output will be displayed in
the HTML field below.</li>
</ul>
<p><img alt="Update server log" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0-dev/cetmix_tower_server/static/description/images/server_log_usage_2.png" /></p>
<p><img alt="Update server log" src="https://raw.githubusercontent.com/cetmix/cetmix-tower/14.0/cetmix_tower_server/static/description/images/server_log_usage_2.png" /></p>
</div>
<div class="section" id="using-cetmix-tower-in-odoo-automation">
<h2>Using Cetmix Tower in Odoo automation</h2>
Expand Down Expand Up @@ -1263,11 +1262,7 @@ <h2>Authors</h2>
</div>
<div class="section" id="maintainers">
<h2>Maintainers</h2>
<p>This module is part of the <a class="reference external" href="https://github.com/cetmix/cetmix-tower/tree/14.0-dev/cetmix_tower_server">cetmix/cetmix-tower</a> project on GitHub.</p>
=======
<h2><a class="toc-backref" href="#toc-entry-22">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/cetmix/cetmix-tower/tree/14.0/cetmix_tower_server">cetmix/cetmix-tower</a> project on GitHub.</p>
>>>>>>> 44924e0 ([FIX] cetmix_tower_server Command log access test)
<p>You are welcome to contribute.</p>
</div>
</div>
Expand Down
43 changes: 23 additions & 20 deletions cetmix_tower_server/tests/test_command_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ def test_user_access_rule(self):
# Ensure that regular user cannot access the command log
test_command_log_as_bob = test_command_log.with_user(self.user_bob)
with self.assertRaises(AccessError):
command_log_name = test_command_log_as_bob.read(["name"])
command_log_read_result = test_command_log_as_bob.read([])

# Add user_bob to group user
self.add_to_group(self.user_bob, "cetmix_tower_server.group_user")
# Ensure that user still doesn't have access to command log he did't create
with self.assertRaises(AccessError):
command_log_name = test_command_log_as_bob.read(["name"])
command_log_read_result = test_command_log_as_bob.read([])
# Add user_bob to group manager
self.add_to_group(self.user_bob, "cetmix_tower_server.group_manager")
# Ensure that manager doesn't have access to command belongs to server
# he did't subscribed to
with self.assertRaises(AccessError):
command_log_name = test_command_log_as_bob.read(["name"])
command_log_read_result = test_command_log_as_bob.read([])
# Subscribe manager to server and test again
self.server_test_1.message_subscribe([self.user_bob.partner_id.id])
command_log_name = test_command_log_as_bob.read(["name"])
command_log_read_result = test_command_log_as_bob.read([])
self.assertEqual(
command_log_name[0]["name"],
command_log_read_result[0]["name"],
test_command_log_as_bob.name,
"Command name should be same",
)
Expand Down Expand Up @@ -74,11 +74,11 @@ def test_user_access_rule(self):
)

# Test if Manager can read command log of a command with "Root" access level
test_command_log_1_name = test_command_log_1.with_user(self.user_bob).read(
["name"]
)
test_command_log_1_read_result = test_command_log_1.with_user(
self.user_bob
).read([])
self.assertEqual(
test_command_log_1_name[0]["name"],
test_command_log_1_read_result[0]["name"],
test_command_log_1.name,
"Command name should be same",
)
Expand All @@ -99,27 +99,30 @@ def test_user_access_rule(self):
)

# Update test_command access_level to "1"
test_command_1.write({"access_level": "1"})
self.write_and_invalidate(test_command_1, **{"access_level": "1"})

# Ensure that user_bob has access to test_command_log_1
test_command_log_1_as_bob = test_command_log_1.with_user(self.user_bob)
test_command_log_1_as_bob.invalidate_cache()
self.assertEqual(
test_command_log_1_as_bob.access_level,
test_command_1.access_level,
"Access should be same",
)
test_command_1.invalidate_cache()
test_command_log_1_name = test_command_log_1_as_bob.read(["name"])
test_command_log_1_read_result = test_command_log_1_as_bob.read([])
self.assertEqual(
test_command_log_1_name[0]["name"],
test_command_log_1_read_result[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):
test_command_log_1_name = test_command_log_1.with_user(self.user_bob).read(
["name"]
)
self.write_and_invalidate(test_command_1, **{"access_level": "2"})
# Remove Bob from server followers
self.server_test_1.message_unsubscribe([self.user_bob.partner_id.id])

# Bob must have access because he is a log creator
test_command_log_1_read_result = test_command_log_1_as_bob.read([])
self.assertEqual(
test_command_log_1_read_result[0]["name"],
test_command_log_1.name,
"Command name should be same",
)

0 comments on commit 265ffdb

Please sign in to comment.