kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
64a196a8c8
commit
3c55d7c145
28
models.py
28
models.py
|
@ -28,7 +28,7 @@ from oauth_dropins.webutil.models import (
|
|||
from oauth_dropins.webutil.util import json_dumps, json_loads
|
||||
|
||||
import common
|
||||
from common import add, base64_to_long, DOMAIN_RE, long_to_base64, unwrap
|
||||
from common import add, base64_to_long, DOMAIN_RE, long_to_base64, remove, unwrap
|
||||
import ids
|
||||
|
||||
# maps string label to Protocol subclass. populated by ProtocolUserMeta.
|
||||
|
@ -348,6 +348,32 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
|
||||
return None
|
||||
|
||||
@ndb.transactional()
|
||||
def enable_protocol(self, to_proto):
|
||||
"""Adds ``to_proto` to :attr:`enabled_protocols`.
|
||||
|
||||
Args:
|
||||
to_proto (:class:`protocol.Protocol` subclass)
|
||||
"""
|
||||
user = self.key.get()
|
||||
add(user.enabled_protocols, to_proto.LABEL)
|
||||
user.put()
|
||||
|
||||
add(self.enabled_protocols, to_proto.LABEL)
|
||||
|
||||
@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)
|
||||
user.put()
|
||||
|
||||
remove(self.enabled_protocols, to_proto.LABEL)
|
||||
|
||||
def handle_as(self, to_proto):
|
||||
"""Returns this user's handle in a different protocol.
|
||||
|
||||
|
|
18
protocol.py
18
protocol.py
|
@ -27,7 +27,6 @@ from common import (
|
|||
DOMAINS,
|
||||
error,
|
||||
PROTOCOL_DOMAINS,
|
||||
remove,
|
||||
subdomain_wrap,
|
||||
)
|
||||
from flask_app import app
|
||||
|
@ -802,13 +801,7 @@ class Protocol:
|
|||
logger.info("Ignoring block, target isn't one of our protocol domains")
|
||||
return 'OK', 200
|
||||
|
||||
@ndb.transactional()
|
||||
def disable_protocol():
|
||||
user = from_user.key.get()
|
||||
remove(user.enabled_protocols, proto.LABEL)
|
||||
user.put()
|
||||
|
||||
disable_protocol()
|
||||
from_user.disable_protocol(proto)
|
||||
return 'OK', 200
|
||||
|
||||
# fetch actor if necessary
|
||||
|
@ -837,13 +830,8 @@ class Protocol:
|
|||
proto = Protocol.for_bridgy_subdomain(inner_obj_id)
|
||||
if proto:
|
||||
# follow of one of our protocol users; enable that protocol
|
||||
@ndb.transactional()
|
||||
def enable_protocol():
|
||||
user = from_user.key.get()
|
||||
add(user.enabled_protocols, proto.LABEL)
|
||||
user.put()
|
||||
|
||||
enable_protocol()
|
||||
from_user.enable_protocol(proto)
|
||||
# TODO: accept
|
||||
return 'OK', 200
|
||||
|
||||
from_cls.handle_follow(obj)
|
||||
|
|
Ładowanie…
Reference in New Issue