From 0d8919846473a2838d236db26dd59067d4092b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Sep 2022 14:30:41 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Limit=20logs=20push=20t?= =?UTF-8?q?o=20MONITOR=5FTERMINAL=20permission?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the terminal wasn't visible for users without the MONITOR_TERMINAL permission, the data was still sent on the websocket. --- src/octoprint/server/util/sockjs.py | 17 +++++++++++++---- .../static/js/app/viewmodels/terminal.js | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index 83134540c..0bc529f56 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -454,12 +454,17 @@ class PrinterStateConnection( { "serverTime": time.time(), "temps": temperatures, - "logs": self._filter_logs(logs), - "messages": messages, "busyFiles": busy_files, "markings": list(self._printer.get_markings()), } ) + if self._user.has_permission(Permissions.MONITOR_TERMINAL): + data.update( + { + "logs": self._filter_logs(logs), + "messages": messages, + } + ) self._emit("current", payload=data) def on_printer_send_initial_data(self, data): @@ -469,9 +474,13 @@ class PrinterStateConnection( return data_to_send = dict(data) - data_to_send["logs"] = self._filter_logs(data_to_send.get("logs", [])) - data_to_send["messages"] = self._filter_messages(data_to_send.get("messages", [])) + data_to_send["serverTime"] = time.time() + if self._user.has_permission(Permissions.MONITOR_TERMINAL): + data_to_send["logs"] = self._filter_logs(data_to_send.get("logs", [])) + data_to_send["messages"] = self._filter_messages( + data_to_send.get("messages", []) + ) self._emit("history", payload=data_to_send) def _filter_state_subscription(self, sub, values): diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index 05d649e19..e9146afd2 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -225,6 +225,8 @@ $(function () { }; self._processCurrentLogData = function (data) { + if (!data) return; + var length = self.log().length; if (length >= self.upperLimit()) { return; @@ -276,6 +278,8 @@ $(function () { }; self._processHistoryLogData = function (data) { + if (!data) return; + self.plainLogLines(data); self.log(_.map(data, self._toInternalFormat)); self.updateOutput();