Skip to content

Commit

Permalink
ext: notifications: Add link logging for management of new comments i…
Browse files Browse the repository at this point in the history
…n Stdout

Fixes #138
  • Loading branch information
pkvach committed Apr 23, 2024
1 parent 29236ff commit 1111fa8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion isso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, conf):
smtp_backend = False
for backend in conf.getlist("general", "notify"):
if backend == "stdout":
subscribers.append(Stdout(None))
subscribers.append(Stdout(self))
elif backend in ("smtp", "SMTP"):
smtp_backend = True
else:
Expand Down
22 changes: 18 additions & 4 deletions isso/ext/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from isso import local


def create_comment_action_url(uri, action, key):
return uri + "/" + action + "/" + key


class SMTPConnection(object):

def __init__(self, conf):
Expand Down Expand Up @@ -118,10 +122,10 @@ def format(self, thread, comment, parent_comment, recipient=None, admin=False):
uri = self.public_endpoint + "/id/%i" % comment["id"]
key = self.isso.sign(comment["id"])

rv.write("Delete comment: %s\n" % (uri + "/delete/" + key))
rv.write("Delete comment: %s\n" % create_comment_action_url(uri, "delete", key))

if comment["mode"] == 2:
rv.write("Activate comment: %s\n" % (uri + "/activate/" + key))
rv.write("Activate comment: %s\n" % create_comment_action_url(uri, "activate", key))

else:
uri = self.public_endpoint + "/id/%i" % parent_comment["id"]
Expand Down Expand Up @@ -208,8 +212,9 @@ def _retry(self, subject, body, to, headers):

class Stdout(object):

def __init__(self, conf):
pass
def __init__(self, isso):
self.isso = isso
self.public_endpoint = isso.conf.get("server", "public-endpoint") or local("host")

def __iter__(self):

Expand All @@ -224,6 +229,15 @@ def _new_thread(self, thread):

def _new_comment(self, thread, comment):
logger.info("comment created: %s", json.dumps(comment))
logger.info("Link to comment: %s" % (local("origin") + thread["uri"] + "#isso-%i" % comment["id"]))

uri = self.public_endpoint + "/id/%i" % comment["id"]
key = self.isso.sign(comment["id"])

logger.info("Delete comment: %s" % create_comment_action_url(uri, "delete", key))

if comment["mode"] == 2:
logger.info("Activate comment: %s" % create_comment_action_url(uri, "activate", key))

def _edit_comment(self, comment):
logger.info('comment %i edited: %s',
Expand Down

0 comments on commit 1111fa8

Please sign in to comment.