Skip to content

Commit

Permalink
restrict edit to positive id
Browse files Browse the repository at this point in the history
edit 0 is accepted in the org.gnome.Hamster.WindowServer
for backward compatibility reasons only.
Accept only strictly positive id for the cli edit.
  • Loading branch information
ederag committed Feb 17, 2020
1 parent b10c9bb commit 4e593e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/hamster-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,9 @@ def version(self):
assert len(args.action_args) == 1, (
"edit requires exactly one argument, got {}"
.format(args.action_args))
action_data = glib.Variant.new_int32(int(args.action_args[0]))
id_ = int(args.action_args[0])
assert id_ > 0, "received non-positive id : {}".format(id_)
action_data = glib.Variant.new_int32(id_)
else:
action_data = None
app.activate_action(action, action_data)
Expand Down
7 changes: 5 additions & 2 deletions src/hamster-windows-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ def _open_window(self, name):
subprocess.run(cmd, shell=True)

@dbus.service.method("org.gnome.Hamster.WindowServer", in_signature='i')
def edit(self, id=0):
def edit(self, id):
"""Edit fact, given its id (int) in the database.
For backward compatibility, if id is 0, create a brand new fact.
"""
self._open_window("edit {}".format(id))
if id:
self._open_window("edit {}".format(id))
else:
self._open_window("add")

@dbus.service.method("org.gnome.Hamster.WindowServer")
def overview(self):
Expand Down

0 comments on commit 4e593e6

Please sign in to comment.