From a896b5c869f15648c3cc341ea91bb403a14d9bb3 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Wed, 28 Aug 2024 21:45:09 -0700 Subject: [PATCH] Protocol.check_supported: allow DMs to/from protocol bot user copy ids for #966 --- common.py | 14 ++++++++++++++ protocol.py | 5 +++-- tests/test_protocol.py | 20 +++++++++++++++++--- tests/testutil.py | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/common.py b/common.py index dd73f71..cb24249 100644 --- a/common.py +++ b/common.py @@ -13,6 +13,7 @@ import cachetools from Crypto.Util import number from flask import abort, g, has_request_context, make_response, request from google.cloud.error_reporting.util import build_flask_context +from google.cloud import ndb from google.cloud.ndb.global_cache import _InProcessGlobalCache, MemcacheCache from google.cloud.ndb.key import Key from google.protobuf.timestamp_pb2 import Timestamp @@ -108,6 +109,19 @@ else: global_cache = MemcacheCache(memcache) +@functools.cache +def protocol_user_copy_ids(): + """Returns all copy ids for protocol bot users.""" + ids = [] + + from web import Web + for user in ndb.get_multi(Web(id=domain).key for domain in PROTOCOL_DOMAINS): + if user: + ids.extend(copy.uri for copy in user.copies) + + return tuple(ids) + + def base64_to_long(x): """Converts from URL safe base64 encoding to long integer. diff --git a/protocol.py b/protocol.py index 7a6140a..324ca76 100644 --- a/protocol.py +++ b/protocol.py @@ -1614,9 +1614,10 @@ Hi! You recently replied