diff options
author | Neil Johnson <neil@matrix.org> | 2018-11-14 14:32:07 +0000 |
---|---|---|
committer | Neil Johnson <neil@matrix.org> | 2018-11-14 14:32:07 +0000 |
commit | ce27b1c9c1b984110da1af258ea22a409eea2aed (patch) | |
tree | b511e11d3ea60675ad49a73e112338b54e68e276 | |
parent | test support user behaviour (diff) | |
download | synapse-ce27b1c9c1b984110da1af258ea22a409eea2aed.tar.xz |
clean up
-rw-r--r-- | synapse/config/server.py | 1 | ||||
-rw-r--r-- | synapse/storage/user_directory.py | 12 | ||||
-rw-r--r-- | tests/storage/test_user_directory.py | 51 |
3 files changed, 7 insertions, 57 deletions
diff --git a/synapse/config/server.py b/synapse/config/server.py index c4d660bb61..c1c7c0105e 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging from synapse.http.endpoint import parse_and_validate_server_name diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py index 4fbfe8d90c..a8781b0e5d 100644 --- a/synapse/storage/user_directory.py +++ b/synapse/storage/user_directory.py @@ -31,7 +31,6 @@ logger = logging.getLogger(__name__) class UserDirectoryStore(SQLBaseStore): - @cachedInlineCallbacks(cache_context=True) def is_room_world_readable_or_publicly_joinable(self, room_id, cache_context): """Check if the room is either world_readable or publically joinable @@ -157,7 +156,6 @@ class UserDirectoryStore(SQLBaseStore): def update_profile_in_user_dir(self, user_id, display_name, avatar_url, room_id): def _update_profile_in_user_dir_txn(txn): - new_entry = self._simple_upsert_txn( txn, table="user_directory", @@ -215,6 +213,7 @@ class UserDirectoryStore(SQLBaseStore): raise Exception("Unrecognized database engine") txn.call_after(self.get_user_in_directory.invalidate, (user_id,)) + return self.runInteraction( "update_profile_in_user_dir", _update_profile_in_user_dir_txn ) @@ -339,9 +338,7 @@ class UserDirectoryStore(SQLBaseStore): share_private (bool): Is the room private user_id_tuples([(str, str)]): iterable of 2-tuple of user IDs. """ - - def _add_users_who_share_room_txn(txn, user_id_tuples): - + def _add_users_who_share_room_txn(txn): self._simple_insert_many_txn( txn, table="users_who_share_rooms", @@ -365,9 +362,7 @@ class UserDirectoryStore(SQLBaseStore): (user_id, other_user_id), ) return self.runInteraction( - "add_users_who_share_room", - _add_users_who_share_room_txn, - user_id_tuples, + "add_users_who_share_room", _add_users_who_share_room_txn ) def update_users_who_share_room(self, room_id, share_private, user_id_sets): @@ -380,7 +375,6 @@ class UserDirectoryStore(SQLBaseStore): user_id_tuples([(str, str)]): iterable of 2-tuple of user IDs. """ def _update_users_who_share_room_txn(txn): - sql = """ UPDATE users_who_share_rooms SET room_id = ?, share_private = ? diff --git a/tests/storage/test_user_directory.py b/tests/storage/test_user_directory.py index eff62e42e4..0dde1ab2fe 100644 --- a/tests/storage/test_user_directory.py +++ b/tests/storage/test_user_directory.py @@ -15,6 +15,7 @@ from twisted.internet import defer +from synapse.storage import UserDirectoryStore from synapse.storage.roommember import ProfileInfo from tests import unittest @@ -23,14 +24,13 @@ from tests.utils import setup_test_homeserver ALICE = "@alice:a" BOB = "@bob:b" BOBBY = "@bobby:a" -ROOM = "!room:id" class UserDirectoryStoreTestCase(unittest.TestCase): @defer.inlineCallbacks def setUp(self): self.hs = yield setup_test_homeserver(self.addCleanup) - self.store = self.hs.get_datastore() + self.store = UserDirectoryStore(self.hs.get_db_conn(), self.hs) # alice and bob are both in !room_id. bobby is not but shares # a homeserver with alice. @@ -42,7 +42,7 @@ class UserDirectoryStoreTestCase(unittest.TestCase): BOBBY: ProfileInfo(None, "bobby"), }, ) - yield self.store.add_users_to_public_room(ROOM, [ALICE, BOB]) + yield self.store.add_users_to_public_room("!room:id", [ALICE, BOB]) yield self.store.add_users_who_share_room( "!room:id", False, ((ALICE, BOB), (BOB, ALICE)) ) @@ -75,48 +75,3 @@ class UserDirectoryStoreTestCase(unittest.TestCase): ) finally: self.hs.config.user_directory_search_all_users = False - - # @defer.inlineCallbacks - # def test_cannot_add_support_user_to_directory(self): - # self.hs.config.user_directory_search_all_users = True - # SUPPORT_USER = "@support:test" - # SUPPOER_USER_SCREEN_NAME = "Support" - # - # yield self.store.register(user_id=SUPPORT_USER, token="123", - # password_hash=None, - # user_type=UserTypes.SUPPORT) - # yield self.store.register(user_id=ALICE, token="456", password_hash=None) - # - # yield self.store.add_profiles_to_user_dir( - # ROOM, - # {SUPPORT_USER: ProfileInfo(None, SUPPOER_USER_SCREEN_NAME)}, - # ) - # yield self.store.add_users_to_public_room(ROOM, [SUPPORT_USER]) - # yield self.store.add_users_who_share_room( - # ROOM, False, ((ALICE, SUPPORT_USER),) - # ) - # - # r = yield self.store.search_user_dir(ALICE, SUPPOER_USER_SCREEN_NAME, 10) - # self.assertFalse(r["limited"]) - # self.assertEqual(0, len(r["results"])) - # - # # Check that enabled support user does not prevent all users being added - # r = yield self.store.search_user_dir(ALICE, ALICE, 10) - # self.assertFalse(r["limited"]) - # self.assertEqual(1, len(r["results"])) - # - # yield self.store.update_user_in_user_dir(SUPPORT_USER, ROOM) - # yield self.store.update_profile_in_user_dir( - # SUPPORT_USER, SUPPOER_USER_SCREEN_NAME, None, ROOM - # ) - # yield self.store.update_user_in_public_user_list(SUPPORT_USER, ROOM) - # - # r = yield self.store.search_user_dir(ALICE, SUPPOER_USER_SCREEN_NAME, 10) - # self.assertFalse(r["limited"]) - # self.assertEqual(0, len(r["results"])) - # - # r = yield self.store.get_user_in_directory(SUPPORT_USER) - # self.assertEqual(r, None) - # - # r = yield self.store.get_user_in_public_room(SUPPORT_USER) - # self.assertEqual(r, None) |