kopia lustrzana https://github.com/snarfed/bridgy-fed
email me when someone enables or disables a protocol
rodzic
139bd0aedb
commit
ece168fac1
|
@ -10,6 +10,8 @@ flask_secret_key
|
|||
make_password
|
||||
private_notes
|
||||
service_account_creds.json
|
||||
smtp_password
|
||||
smtp_user
|
||||
superfeedr_token
|
||||
superfeedr_username
|
||||
TAGS
|
||||
|
|
10
common.py
10
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)
|
||||
|
|
10
models.py
10
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.
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue