User.enable/disable_protocol: move email out of datastore tx

pull/977/head
Ryan Barrett 2024-04-24 14:34:52 -07:00
rodzic b543fdb1d5
commit 55ae9fd2bb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
1 zmienionych plików z 16 dodań i 11 usunięć

Wyświetl plik

@ -364,31 +364,36 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
Args:
to_proto (:class:`protocol.Protocol` subclass)
"""
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):
to_proto.create_for(user)
user.put()
@ndb.transactional()
def enable():
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):
to_proto.create_for(user)
user.put()
enable()
add(self.enabled_protocols, to_proto.LABEL)
msg = f'Enabled {to_proto.LABEL} for {self.key.id()} : {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`.
Args:
to_proto (:class:`protocol.Protocol` subclass)
"""
user = self.key.get()
remove(user.enabled_protocols, to_proto.LABEL)
# TODO: delete copy user
# https://github.com/snarfed/bridgy-fed/issues/783
user.put()
@ndb.transactional()
def disable():
user = self.key.get()
remove(user.enabled_protocols, to_proto.LABEL)
# TODO: delete copy user
# https://github.com/snarfed/bridgy-fed/issues/783
user.put()
disable()
remove(self.enabled_protocols, to_proto.LABEL)
msg = f'Disabled {to_proto.LABEL} for {self.key.id()} : {self.user_page_path()}'