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

Set username as triggerValue when possible #2382

Merged
merged 6 commits into from
Aug 15, 2024

Conversation

BadWolf42
Copy link
Contributor

@BadWolf42 BadWolf42 commented Jan 21, 2024

Proposed change

As per feature request here: https://community.jeedom.com/t/utilisateur-ayant-execute-la-commande/4488

Last user who executed the scenario is available using triggerValue() when trigger() is 'user'.

(Also fixed a typo in core/ajax/user.ajax.php)

Type of change

  • Core new feature
  • Code quality improvements

Test check

image

Documentation

N/A

@rocket13011
Copy link
Contributor

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

CodiumAI-Agent commented Jan 23, 2024

PR Analysis

(review updated until commit 4384ef3)

  • 🎯 Main theme: Setting the username as triggerValue when possible
  • 📝 PR summary: This PR introduces a new feature where the last user who executed the scenario is available using triggerValue() when trigger() is 'user'. It also includes a minor typo fix in core/ajax/user.ajax.php.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 2, because the PR is relatively small and the changes are straightforward.
  • 🔒 Security concerns: No

PR Feedback

💡 General suggestions: The PR is well-structured and the changes are clear. However, it would be beneficial to include unit tests to verify the new functionality. Also, it would be helpful to provide a bit more context in the PR description about why this change is needed and how it improves the system.


✨ Usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...

With a configuration file, use the following template:

[pr_reviewer]
some_config1=...
some_config2=...
Utilizing extra instructions

The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

Examples for extra instructions:

[pr_reviewer] # /review #
extra_instructions="""
In the code feedback section, emphasize the following:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

How to enable\disable automation
  • When you first install PR-Agent app, the default mode for the review tool is:
pr_commands = ["/review", ...]

meaning the review tool will run automatically on every PR, with the default configuration.
Edit this field to enable/disable the tool, or to change the used configurations

About the 'Code feedback' section

The review tool provides several type of feedbacks, one of them is code suggestions.
If you are interested only in the code suggestions, it is recommended to use the improve feature instead, since it dedicated only to code suggestions, and usually gives better results.
Use the review tool if you want to get a more comprehensive feedback, which includes code suggestions as well.

Auto-labels

The review tool can auto-generate two specific types of labels for a PR:

  • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
  • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
Extra sub-tools

The review tool provides a collection of possible feedbacks about a PR.
It is recommended to review the possible options, and choose the ones relevant for your use case.
Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
require_score_review, require_soc2_review, enable_review_labels_effort, and more.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the review usage page for a comprehensive guide on using this tool.

@CodiumAI-Agent
Copy link

Persistent review updated to latest commit 4384ef3

1 similar comment
@CodiumAI-Agent
Copy link

Persistent review updated to latest commit 4384ef3

@@ -840,6 +840,7 @@ public function launch($_trigger = '', $_message = '', $_forceSyncMode = false,
$this->setTags($tags);
}
$this->setCache(array('startingTime' => strtotime('now'), 'state' => 'starting'));
$this->setCache('lastExecutionUser', (isset($_SESSION) && isset($_SESSION['user']) && $_SESSION['user'] != null) ? $_SESSION['user']->getLogin() : 'none');

Choose a reason for hiding this comment

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

Consider handling the case where $_SESSION['user'] is not set more gracefully. Instead of setting the lastExecutionUser to 'none', it might be better to leave it unset or set it to a more meaningful value. [medium]

@BadWolf42
Copy link
Contributor Author

Hello @Hotfirenet & @Sekiro-kost,
Any news regarding this PR, what should I change to have it merged?
Regards,
Bad

@zoic21
Copy link
Contributor

zoic21 commented Jun 10, 2024

Hello,

No problem with this PR just we wait core 4.5 (maybe this week or next week).

@zoic21 zoic21 added this to the 4.5 milestone Jun 10, 2024
@zoic21 zoic21 deleted the branch jeedom:alpha July 11, 2024 09:09
@zoic21 zoic21 closed this Jul 11, 2024
@zoic21 zoic21 reopened this Jul 11, 2024
@zoic21
Copy link
Contributor

zoic21 commented Aug 5, 2024

Hello,
It's time to merge !!!!! Can you review your PR to adapt of new code of scenario, specially using tag to pass username

@zoic21
Copy link
Contributor

zoic21 commented Aug 14, 2024

Hello,

I think we can do better for this PR, currently it's use cache but now it's better to you use tag like this :
https://github.com/jeedom/core/blob/alpha/core/class/scenario.class.php#L378

Now tag is instanciated for current launch and do not impact other scenario launch

@BadWolf42
Copy link
Contributor Author

Using the tag system in the instance, it is way easier to get the user who triggered the scenario.
This could also be done to identify which API key triggered the scenario in jeeApi and proApi.

@zoic21 zoic21 merged commit d619bee into jeedom:alpha Aug 15, 2024
3 of 4 checks passed
@BadWolf42 BadWolf42 deleted the sc-triggering-user branch August 15, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants