Skip to content

FE: Notifications sorting fix #1713#1714

Open
jokob-sk wants to merge 6 commits into
mainfrom
next_release
Open

FE: Notifications sorting fix #1713#1714
jokob-sk wants to merge 6 commits into
mainfrom
next_release

Conversation

@jokob-sk

@jokob-sk jokob-sk commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Fixed DataTables timestamp sorting by using the raw, timezone-trimmed value for sort operations.
    • Preserved localized timestamp display for on-screen rendering.
  • Improvements

    • Enhanced Telegram notification sending reliability with safer request payload formatting, improved bounded truncation behavior, and better execution-time handling.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The notification timestamp renderer now preserves raw values for sorting, while the Telegram publisher sends JSON requests through an argument-based curl subprocess with updated truncation, timeout, output, and error handling.

Changes

Notification timestamp rendering

Layer / File(s) Summary
Timestamp render logic
front/userNotifications.php
The DataTables timestamp renderer returns the timezone-trimmed value for sorting and non-display types, then localizes it only for display rendering.

Telegram message publishing

Layer / File(s) Summary
Telegram request execution
front/plugins/_publisher_telegram/tg.py
The sender truncates oversized messages including the truncation marker, serializes the request body with json.dumps, invokes curl through subprocess.run without a shell and with timeouts, and returns subprocess output or stringified OSError details.

Sequence Diagram(s)

sequenceDiagram
  participant Publisher as Telegram publisher
  participant Curl as curl subprocess
  participant Telegram as Telegram API
  Publisher->>Publisher: Serialize truncated message as JSON
  Publisher->>Curl: Execute curl with argv request
  Curl->>Telegram: Send JSON request
  Telegram-->>Curl: Return response
  Curl-->>Publisher: Return stdout
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the notifications sorting fix, which is a real part of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch next_release

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@front/userNotifications.php`:
- Around line 91-93: Update the conditional in the DataTables rendering callback
around the sort/type handling to return the raw value whenever type is not
"display". Replace the limited sort/type check with a type !== "display" check
so filter uses the unlocalized value as well.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 319f419c-5a35-4fb3-b8a9-6da928d0ff44

📥 Commits

Reviewing files that changed from the base of the PR and between 2924b4c and 05e0f69.

📒 Files selected for processing (1)
  • front/userNotifications.php

Comment thread front/userNotifications.php Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@front/plugins/_publisher_telegram/tg.py`:
- Line 109: Update the debug logging around the Telegram command in the
publisher flow to avoid including the bot token embedded in the API URL. Log
only the operation name or a URL with the token redacted, while preserving the
existing command execution behavior.
- Around line 88-91: Update the truncation logic in the payload construction
block to ensure the final payload, including " (text was truncated)", never
exceeds TELEGRAM_SIZE. Reduce the text slice by the marker length before
appending it, while preserving the existing unmodified text path when no
truncation is needed.
- Around line 99-118: Add curl connection and total request timeouts to the
command assembled in the Telegram publisher flow before subprocess.run, using
values both below RUN_TIMEOUT. Update the cmd construction associated with the
sendMessage request while preserving the existing subprocess behavior and
logging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5cb31b82-0f48-4585-80fd-a7ad5baeb671

📥 Commits

Reviewing files that changed from the base of the PR and between 84bc713 and 30df63b.

📒 Files selected for processing (1)
  • front/plugins/_publisher_telegram/tg.py

Comment on lines 88 to +91
if len(text) > limit:
payloadData = text[:limit] + " (text was truncated)"
payload_data = text[:limit] + " (text was truncated)"
else:
payloadData = text
payload_data = text

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep the truncated payload within TELEGRAM_SIZE.

Slicing to limit and then appending the marker produces a message longer than the configured limit, potentially causing Telegram to reject it.

Proposed fix
+        marker = " (text was truncated)"
-        payload_data = text[:limit] + " (text was truncated)"
+        payload_data = (text[:max(0, limit - len(marker))] + marker)[:limit]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if len(text) > limit:
payloadData = text[:limit] + " (text was truncated)"
payload_data = text[:limit] + " (text was truncated)"
else:
payloadData = text
payload_data = text
if len(text) > limit:
marker = " (text was truncated)"
payload_data = (text[:max(0, limit - len(marker))] + marker)[:limit]
else:
payload_data = text
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@front/plugins/_publisher_telegram/tg.py` around lines 88 - 91, Update the
truncation logic in the payload construction block to ensure the final payload,
including " (text was truncated)", never exceeds TELEGRAM_SIZE. Reduce the text
slice by the marker length before appending it, while preserving the existing
unmodified text path when no truncation is needed.

Comment on lines +99 to +118
cmd = [
"curl",
"--location",
f"https://api.telegram.org/bot{get_setting_value('TELEGRAM_URL')}/sendMessage",
"--header",
"Content-Type: application/json",
"--data",
payload,
]

mylog("debug", ["Executing:", " ".join(cmd[:-1]), "--data <json>"])

try:
# try runnning a subprocess

req = """curl --location 'https://api.telegram.org/bot%s/sendMessage' \\
--header 'Content-Type: application/json' \\
--data '{
"chat_id": "%s",
"text": "%s",
"disable_notification": false
}'""" % (get_setting_value('TELEGRAM_URL'), get_setting_value('TELEGRAM_HOST'), payloadData)

mylog('debug', [req])

p = subprocess.Popen(req, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
stdout, stderr = p.communicate()

# write stdout and stderr into .log files for debugging if needed
# Log the stdout and stderr
mylog('debug', [stdout, stderr])

# log result
result = stdout
proc = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target file around the cited lines.
sed -n '1,180p' front/plugins/_publisher_telegram/tg.py

# Find timeout-related settings and usages in this plugin.
rg -n "RUN_TIMEOUT|connect-timeout|max-time|timeout|curl" front/plugins/_publisher_telegram/tg.py front/plugins/_publisher_telegram -S

# Look for similar curl invocations elsewhere for comparison.
rg -n "subprocess\.run\(.*curl|--connect-timeout|--max-time" front -S

Repository: netalertx/NetAlertX

Length of output: 4453


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect RUN_TIMEOUT definition and how it is used in this plugin/config.
rg -n "RUN_TIMEOUT" front/plugins/_publisher_telegram front/plugins -S

# Read the relevant config section for the Telegram plugin.
sed -n '330,390p' front/plugins/_publisher_telegram/config.json

# Search for run-time enforcement helpers in the repo.
rg -n "run timeout|RUN_TIMEOUT|timeout" front server -S | head -n 200

Repository: netalertx/NetAlertX

Length of output: 50376


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the Telegram plugin's RUN_TIMEOUT config block.
sed -n '340,375p' front/plugins/_publisher_telegram/config.json

# Show only the send() function and surrounding lines from tg.py.
sed -n '78,130p' front/plugins/_publisher_telegram/tg.py

# Check whether subprocess.run in this file uses timeout= anywhere.
rg -n "subprocess\.run\(|timeout=" front/plugins/_publisher_telegram/tg.py -n -S

Repository: netalertx/NetAlertX

Length of output: 2204


Add curl connection and request timeouts at front/plugins/_publisher_telegram/tg.py:99-118.

A stalled Telegram request can block this publisher loop and delay later notifications. Set --connect-timeout and --max-time to values below RUN_TIMEOUT.

🧰 Tools
🪛 ast-grep (0.44.1)

[error] 111-117: Use of unsanitized data to create processes
Context: subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(os-system-unsanitized-data)


[error] 111-117: Command coming from incoming request
Context: subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(subprocess-from-request)

🪛 Ruff (0.15.21)

[error] 112-112: subprocess call: check for execution of untrusted input

(S603)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@front/plugins/_publisher_telegram/tg.py` around lines 99 - 118, Add curl
connection and total request timeouts to the command assembled in the Telegram
publisher flow before subprocess.run, using values both below RUN_TIMEOUT.
Update the cmd construction associated with the sendMessage request while
preserving the existing subprocess behavior and logging.

Source: Learnings

Comment thread front/plugins/_publisher_telegram/tg.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@front/plugins/_publisher_telegram/tg.py`:
- Around line 116-118: Remove the standalone stray period immediately before the
mylog("debug", ["Executing: Telegram sendMessage", "--data <json>"]) call,
leaving the surrounding list or statement structure valid so tg.py parses and
runs successfully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 552e935e-1710-42ec-b6ea-cda26f2375f8

📥 Commits

Reviewing files that changed from the base of the PR and between 30df63b and 776a415.

📒 Files selected for processing (1)
  • front/plugins/_publisher_telegram/tg.py

Comment thread front/plugins/_publisher_telegram/tg.py
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.

1 participant