6 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
fbed7e93e8
operation: Use safe formatter for translating messages
- When an app install fails, there is a small chance that the failure message is
show in the area where operation spinner is shown. If that happens,
operation.translated_message is accessed from the HTML template. This throws an
exception if the error message that made contains excepted formatting keys.
Example:
"{include_once("/var/www/html/config/config.php");print($CONFIG["dbpassword"] ??
""); }".

- Also change the formatting key {exception_message} to {exception} as this
would help in translation when Notification is shown which has {exception} as
data dictionary value.

Tests:

- In the operation update message such as 'Installing app', insert unexpected
formatting strings. 'Installing app {foo}'. Notice the error without the patch
and how the patch fixes it.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-10-21 12:47:08 -04:00
James Valleroy
c8dac10308
tests: operation: Fix mock has_calls assertion
In Python 3.12, has_calls is not a valid assertion.

Closes: #1058421

Tests:

- Run "python3.12 -m pytest plinth/tests/test_operation.py" in unstable
  container. All tests are passed.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-12-26 07:47:25 -08:00
Sunil Mohan Adapa
5e6c676748
operation: Fix issue with re-running setup when it fails first time
When setup is run from the application thread after startup, it continuously
tries until it succeeds. However, after making the first attempt, it does not
collect the status of the operation keeping the operation object in operation
manager. When trying for the second time, trying to create operation with same
ID fails since the operation is already present.

Fix this by allowing the operation to be recreated if the existing operation has
failed.

Tests:

- Unit tests pass.

- Functional tests for bepasty app pass.

- Install an app. Create an error in the setup mechanism for an app. Increment
is app version number. Start the service and notice that setup of app is
attempted and fails. Few seconds later the setup is attempted again and the
process continues. Each time the failure is due to fault in the app's setup
method rather than operation not being accepted.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-11-04 17:48:35 -04:00
Sunil Mohan Adapa
a233bbfd9b
operation: Add unique ID for each operation
- Helps in retrieving an operation that is currently running.

- Prevent starting an operation that is already running.

Tests:

- Unit tests work.

- Installing, uninstalling an app works.

- For upgrading an app works.

- Running background diagnostics works.

- Updating tor configuration works.

- Updating torproxy configuration works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-10-07 04:52:17 +09:00
Sunil Mohan Adapa
bc09cd42bb
operation: tests: Fix warning when test helpers start with 'Test'
Don't start the helper class name with 'Test' as it will be treated as a class
with test cases to run.

Fixes #2288.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-01-02 20:07:11 -05:00
Sunil Mohan Adapa
cbef3e0163
operation: Add module to manage threaded operations
- Show a Django message if desired. Keep the operation after completion so that
the message can be collected later.

- Show notifications for running operations

  - Only if show_notification flag is set.

  - Use a custom template so that spinner can be shown.

- Log generously for operation creation, scheduling, running and completion.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:13 -04:00