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

[14.0][IMP] cetmix_tower_server: use checkbox for sudo mode #224

Open
wants to merge 4 commits into
base: 14.0-dev
Choose a base branch
from

Conversation

halbtonjazz
Copy link

@halbtonjazz halbtonjazz commented Mar 13, 2025

Replace the sudo selector with a checkbox in the command wizard to ensure the sudo mode is determined by the server settings. This change avoids mismatches between the user selection and server configuration by validating the sudo mode before command execution.

Task: 4403

Summary by CodeRabbit

  • New Features
    • Enhanced the handling of elevated privileges during command execution, ensuring they now follow the server’s configured settings.
    • Updated the command execution interface with a streamlined on/off option for elevated privileges and conditional display of status labels based on the selected command action.

Replace the sudo selector with a checkbox in the command wizard to
ensure the sudo mode is determined by the server settings. This change
avoids mismatches between the user selection and server configuration by
validating the sudo mode before command execution.

Task: 4403
Use sudo() on server_ids for users in group_user
to ensure read access to server.use_sudo (restricted to group_manager), preventing AccessError

Task: 4403
Move the sudo mode check from the wizard model to execute_command.
This change ensures that a mismatched sudo parameter versus the server
configuration triggers a ValidationError. Add a new test and update the test
test_execute_command_with_variables to reflect this behavior.

Task: 4403
Copy link

coderabbitai bot commented Mar 13, 2025

Walkthrough

This pull request updates the handling of sudo privileges across the server command execution, tests, and wizard interfaces. The changes adjust how the sudo parameter is derived from server settings and modify the wizard’s use_sudo field from a selection type to a boolean type. The modifications span adjustments in the core server command execution method, dynamic test settings, and UI changes to conditionally display sudo elements.

Changes

Files Change Summary
cetmix_tower_server/models/cx_tower_server.py
cetmix_tower_server/tests/test_command.py
In the server command execution, a conditional now checks for the sudo parameter to align it with the server's configuration. The test file was updated to set the use_sudo attribute dynamically for different sudo options.
cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py
cetmix_tower_server/wizards/…/cx_tower_command_execute_wizard_view.xml
In the wizard, the use_sudo field type changed from a selection (with password options) to a boolean. The accompanying view was modified to remove the placeholder and conditionally display the "sudo" label based on the command action.

Possibly related PRs

Suggested labels

needs review, merged 🎉, approved

Suggested reviewers

  • ivs-cetmix
  • Aldeigja

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between ec1ae5c and 8d4b634.

📒 Files selected for processing (3)
  • cetmix_tower_server/models/cx_tower_server.py (1 hunks)
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py (3 hunks)
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard_view.xml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard_view.xml
  • cetmix_tower_server/models/cx_tower_server.py
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test with OCB

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@halbtonjazz halbtonjazz marked this pull request as ready for review March 13, 2025 18:23
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py (1)

47-51: Field type change improves user experience

The field use_sudo has been changed from a Selection to a Boolean field, which aligns with the PR objective of replacing the sudo selector with a checkbox. This simplifies the user interface and makes it clearer that sudo usage depends on server settings.

However, there's a minor issue with the help text formatting - missing punctuation between sentences.

- "If no sudo is configured will run without sudo",
+ "If no sudo is configured, will run without sudo",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 119ac05 and ec1ae5c.

📒 Files selected for processing (5)
  • cetmix_tower_server/models/cx_tower_server.py (1 hunks)
  • cetmix_tower_server/tests/test_command.py (1 hunks)
  • cetmix_tower_server/tests/test_server.py (1 hunks)
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py (3 hunks)
  • cetmix_tower_server/wizards/cx_tower_command_execute_wizard_view.xml (1 hunks)
🔇 Additional comments (6)
cetmix_tower_server/tests/test_command.py (1)

691-691: Good syncing of server sudo mode with test parameter.

This update ensures that the server's use_sudo setting matches the sudo parameter being tested in each loop iteration, which properly accommodates the new validation in the execute_command method.

cetmix_tower_server/wizards/cx_tower_command_execute_wizard_view.xml (1)

55-57: Improved UI clarity with conditional sudo label.

The new span element adds a clear "sudo" label that is conditionally displayed only when SSH commands are selected, making the purpose of the checkbox more intuitive for users.

cetmix_tower_server/models/cx_tower_server.py (1)

733-739: Good validation to prevent sudo mode mismatches.

This validation ensures consistency between the command execution's sudo parameter and the server's configured sudo mode, preventing potential issues that could arise from mismatched sudo configurations.

cetmix_tower_server/tests/test_server.py (1)

765-783: Well-structured test for sudo mode validation.

This test correctly verifies the new validation check by setting up a server with use_sudo: "p" and attempting to execute a command with a mismatched sudo parameter "n". The assertion properly checks for the expected validation error message.

cetmix_tower_server/wizards/cx_tower_command_execute_wizard.py (2)

193-193: Improved sudo handling logic

This change correctly implements the PR objective of ensuring that sudo mode is determined by server settings rather than user selection. When the checkbox is checked, it will use the server's configured sudo setting; otherwise, it passes None.


274-274: Consistent sudo handling across methods

The same sudo handling logic is correctly applied here for command execution via SSH, maintaining consistency with the implementation in the execute_command_on_server method.

Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

LGTM, pls check comment

Replace 'sudo' argument with boolean in execute_command()
to simplify the code and reduce error risk. Remove the
"sudo mode mismatch" constraint and its test. Unify wizard visibility conditions.

Task: 4403
@@ -730,6 +730,9 @@ def execute_command(
) # pylint: disable=no-member
)

if sudo:
sudo = self.sudo().use_sudo

# Populate `sudo` value from the server settings if not provided explicitly
if sudo is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check still needed? As well as the one in the line 738? Cannot be they simply combined?

@@ -191,7 +190,7 @@ def execute_command_on_server(self):
for server in self.server_ids:
server.execute_command(
self.command_id,
sudo=self.use_sudo,
sudo=server.use_sudo and self.use_sudo,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to check this is wizard if you check this in the execute_command anyway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants