Skip to content

Commit

Permalink
ui,rules: fixed refrehsing list, fixed typos
Browse files Browse the repository at this point in the history
- Fixed refreshing list when deleting rules.
- Fixed typos that were preventing errors from being displayed correctly.

Closes: #1056
  • Loading branch information
gustavo-iniguez-goya committed Oct 12, 2023
1 parent 72756c8 commit 177d67d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions ui/opensnitch/dialogs/stats.py
Expand Up @@ -806,6 +806,8 @@ def _del_by_field(self, cur_idx, table, value):

def _del_rule(self, rule_name, node_addr):
nid, noti = self._nodes.delete_rule(rule_name, node_addr, self._notification_callback)
if nid == None:
return
self._notifications_sent[nid] = noti
# FIXME: we shouldn't refresh the view here. We should wait for a
# notification reply on self._cb_notification_callback
Expand All @@ -830,7 +832,7 @@ def _configure_events_contextual_menu(self, pos):

selection = table.selectionModel().selectedRows()
if not selection:
return
return False

menu = QtWidgets.QMenu()
_menu_details = menu.addAction(QC.translate("stats", "Details"))
Expand Down Expand Up @@ -867,7 +869,7 @@ def _configure_fwrules_contextual_menu(self, pos):

selection = table.selectionModel().selectedRows()
if not selection:
return
return False
is_rule_enabled = model.index(selection[0].row(), FirewallTableModel.COL_ENABLED).data()
rule_action = model.index(selection[0].row(), FirewallTableModel.COL_ACTION).data()
rule_action = rule_action.lower()
Expand Down Expand Up @@ -937,7 +939,7 @@ def _configure_rules_contextual_menu(self, pos):

selection = table.selectionModel().selectedRows()
if not selection:
return
return False

menu = QtWidgets.QMenu()
durMenu = QtWidgets.QMenu(self.COL_STR_DURATION)
Expand Down Expand Up @@ -997,7 +999,7 @@ def _configure_rules_contextual_menu(self, pos):
if ret == QtWidgets.QMessageBox.Cancel:
return False
self._table_menu_apply_to_node(cur_idx, model, selection, node_addr)
return
return False

if action == _menu_delete:
self._table_menu_delete(cur_idx, model, selection)
Expand Down Expand Up @@ -1254,7 +1256,7 @@ def _table_menu_new_rule_from_row(self, cur_idx, model, selection):
coltime = model.index(selection[0].row(), self.COL_TIME).data()
if self._rules_dialog.new_rule_from_connection(coltime) == False:

Message.ok(QC.transslate("stats", "New rule error"),
Message.ok(QC.translate("stats", "New rule error"),
QC.translate("stats",
"Error creating new rule from event ({0})".format(coltime)
),
Expand All @@ -1267,9 +1269,9 @@ def _table_menu_edit(self, cur_idx, model, selection):
node = model.index(idx.row(), self.COL_R_NODE).data()
records = self._get_rule(name, node)
if records == None or records == -1:
Message.ok(QC.transslate("stats", "New rule error"),
Message.ok(QC.translate("stats", "New rule error"),
QC.translate("stats", "Rule not found by that name and node"),
QtWidgets.QmessageBox.Warning)
QtWidgets.QMessageBox.Warning)
return
self._rules_dialog.edit_rule(records, node)
break
Expand Down Expand Up @@ -1949,11 +1951,13 @@ def _get_order(self, field=None):
return " ORDER BY %s %s" % (order_field, self.SORT_ORDER[self.TABLES[cur_idx]['last_order_to']])

def _refresh_active_table(self):
cur_idx = self.tabWidget.currentIndex()
model = self._get_active_table().model()
lastQuery = model.query().lastQuery()
if "LIMIT" not in lastQuery:
lastQuery += self._get_limit()
self.setQuery(model, lastQuery)
self.TABLES[cur_idx]['view'].refresh()

def _get_active_table(self):
if self.tabWidget.currentIndex() == self.TAB_RULES and self.fwTable.isVisible():
Expand Down
2 changes: 1 addition & 1 deletion ui/opensnitch/nodes.py
Expand Up @@ -92,7 +92,7 @@ def delete_rule(self, rule_name, addr, callback):
deleted_rule = self._rules.delete(rule_name, addr, callback)
if deleted_rule == None:
print(self.LOG_TAG, "error deleting rule", rule_name)
return
return None, None

noti = ui_pb2.Notification(type=ui_pb2.DELETE_RULE, rules=[deleted_rule])
if addr != None:
Expand Down

0 comments on commit 177d67d

Please sign in to comment.