email me when someone enables or disables a protocol

pull/977/head
Ryan Barrett 2024-04-24 11:12:45 -07:00
rodzic 139bd0aedb
commit ece168fac1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 20 dodań i 2 usunięć

2
.gitignore vendored
Wyświetl plik

@ -10,6 +10,8 @@ flask_secret_key
make_password
private_notes
service_account_creds.json
smtp_password
smtp_user
superfeedr_token
superfeedr_username
TAGS

Wyświetl plik

@ -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)

Wyświetl plik

@ -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.