diff --git a/.gitignore b/.gitignore index 91e4708..5a4d8d0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ flask_secret_key make_password private_notes service_account_creds.json +smtp_password +smtp_user superfeedr_token superfeedr_username TAGS diff --git a/common.py b/common.py index fbed9c3..99cf3a0 100644 --- a/common.py +++ b/common.py @@ -63,6 +63,9 @@ DOMAIN_BLOCKLIST = ( 'twitter.com', ) +SMTP_HOST = 'mail.gandi.net' +SMTP_PORT = 587 + # populated in models.reset_protocol_properties SUBDOMAIN_BASE_URL_RE = None ID_FIELDS = ['id', 'object', 'actor', 'author', 'inReplyTo', 'url'] @@ -305,3 +308,10 @@ def create_task(queue, delay=None, **params): msg = f'Added {queue} task {task.name} : {params}' logger.info(msg) return msg, 202 + + +def email_me(msg): + if not DEBUG: + util.send_email(smtp_host=SMTP_HOST, smtp_port=SMTP_PORT, + from_='bridgy-fed@ryanb.org', to='bridgy-fed@ryanb.org', + subject=util.ellipsize(msg), body=msg) diff --git a/models.py b/models.py index d14bf1e..54f961d 100644 --- a/models.py +++ b/models.py @@ -364,7 +364,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): Args: to_proto (:class:`protocol.Protocol` subclass) """ - logger.info(f'Enabling {to_proto.LABEL} for {self.key}') user = self.key.get() add(user.enabled_protocols, to_proto.LABEL) if to_proto.LABEL in ids.COPIES_PROTOCOLS and not user.get_copy(to_proto): @@ -373,6 +372,10 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): add(self.enabled_protocols, to_proto.LABEL) + msg = f'Enabled {to_proto.LABEL} for {self.key} : {self.user_page_path()}' + logger.info(msg) + common.email_me(msg) + @ndb.transactional() def disable_protocol(self, to_proto): """Removes ``to_proto` from :attr:`enabled_protocols`. @@ -380,7 +383,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): Args: to_proto (:class:`protocol.Protocol` subclass) """ - logger.info(f'Disabling {to_proto.LABEL} for {self.key}') user = self.key.get() remove(user.enabled_protocols, to_proto.LABEL) # TODO: delete copy user @@ -389,6 +391,10 @@ class User(StringIdModel, metaclass=ProtocolUserMeta): remove(self.enabled_protocols, to_proto.LABEL) + msg = f'Disabled {to_proto.LABEL} for {self.key} : {self.user_page_path()}' + logger.info(msg) + common.email_me(msg) + def handle_as(self, to_proto): """Returns this user's handle in a different protocol.