Skip to content

Set Admin User as Default run_as_user_id When Importing Scripts #6208

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

Merged
merged 2 commits into from
Feb 11, 2024

Conversation

sanjacornelius
Copy link
Contributor

@sanjacornelius sanjacornelius commented Feb 9, 2024

Issue & Reproduction Steps

This PR addresses an issue discovered during the import of scripts from Guided Templates where scripts lacking a run_as_user_id caused a A user is required to run scripts. error when running the Re-run Wizard process. To resolve this, the PR implements setting the admin user as the default run_as_user_id when importing such scripts.

How to Test

  1. Ensure your environment has the latest Guided Templates synced php artisan processmaker:sync-guided-templates.
  2. Create a process from the Guided Template.
  3. Navigate to that process's Launchpad.
  4. Select "Re-run Wizard."
  5. Complete the wizard.
  6. Navigate to "Requests -> All Requests."
  7. Select the recently completed request (the status may initially show as "cancelled").
  8. View the summary data.
  9. Ensure no errors such as _configuration_error_node_212 are present.

Example Error that was previously returned:

unnamed

Related Tickets & Packages

ci:next

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.

Copy link
Contributor

@eiresendez eiresendez left a comment

Choose a reason for hiding this comment

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

@sanjacornelius I think there's a potential issue in !is_null($scriptUser->id). For instance, if $scriptUser is null, trying to access id would result in WARNING Attempt to read property "id" on null.
Maybe using the nullsafe operator is a safe way to handle that:
$this->model->run_as_user_id = $scriptUser?->id ?? User::where('is_administrator', true)->first()->id;

@sanjacornelius
Copy link
Contributor Author

@sanjacornelius I think there's a potential issue in !is_null($scriptUser->id). For instance, if $scriptUser is null, trying to access id would result in WARNING Attempt to read property "id" on null. Maybe using the nullsafe operator is a safe way to handle that: $this->model->run_as_user_id = $scriptUser?->id ?? User::where('is_administrator', true)->first()->id;

Great idea!! I will implement thank you!!

@eiresendez eiresendez self-requested a review February 9, 2024 21:36
Copy link

Copy link
Contributor

@eiresendez eiresendez left a comment

Choose a reason for hiding this comment

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

The admin user is correctly assigned in the absence of a Script User.

image

@ryancooley ryancooley merged commit 83e1fc1 into next Feb 11, 2024
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.

3 participants