mirror of
https://github.com/element-hq/synapse
synced 2024-08-20 12:00:21 +00:00
De-localpart ProfileWorkerStore.get_profileinfo()
Signed-off-by: Sean Quah <seanq@matrix.org>
This commit is contained in:
parent
0a734d0cf2
commit
b375e2abd9
8 changed files with 25 additions and 18 deletions
|
@ -89,7 +89,7 @@ class AdminHandler:
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add additional user metadata
|
# Add additional user metadata
|
||||||
profile = await self._store.get_profileinfo(user.localpart)
|
profile = await self._store.get_profileinfo(user.to_string())
|
||||||
threepids = await self._store.user_get_threepids(user.to_string())
|
threepids = await self._store.user_get_threepids(user.to_string())
|
||||||
external_ids = [
|
external_ids = [
|
||||||
({"auth_provider": auth_provider, "external_id": external_id})
|
({"auth_provider": auth_provider, "external_id": external_id})
|
||||||
|
|
|
@ -1756,9 +1756,7 @@ class AuthHandler:
|
||||||
respond_with_html(request, 403, self._sso_account_deactivated_template)
|
respond_with_html(request, 403, self._sso_account_deactivated_template)
|
||||||
return
|
return
|
||||||
|
|
||||||
user_profile_data = await self.store.get_profileinfo(
|
user_profile_data = await self.store.get_profileinfo(registered_user_id)
|
||||||
UserID.from_string(registered_user_id).localpart
|
|
||||||
)
|
|
||||||
|
|
||||||
# Store any extra attributes which will be passed in the login response.
|
# Store any extra attributes which will be passed in the login response.
|
||||||
# Note that this is per-user so it may overwrite a previous value, this
|
# Note that this is per-user so it may overwrite a previous value, this
|
||||||
|
|
|
@ -282,8 +282,6 @@ class DeactivateAccountHandler:
|
||||||
Args:
|
Args:
|
||||||
user_id: ID of user to be re-activated
|
user_id: ID of user to be re-activated
|
||||||
"""
|
"""
|
||||||
user = UserID.from_string(user_id)
|
|
||||||
|
|
||||||
# Ensure the user is not marked as erased.
|
# Ensure the user is not marked as erased.
|
||||||
await self.store.mark_user_not_erased(user_id)
|
await self.store.mark_user_not_erased(user_id)
|
||||||
|
|
||||||
|
@ -297,5 +295,5 @@ class DeactivateAccountHandler:
|
||||||
# Add the user to the directory, if necessary. Note that
|
# Add the user to the directory, if necessary. Note that
|
||||||
# this must be done after the user is re-activated, because
|
# this must be done after the user is re-activated, because
|
||||||
# deactivated users are excluded from the user directory.
|
# deactivated users are excluded from the user directory.
|
||||||
profile = await self.store.get_profileinfo(user.localpart)
|
profile = await self.store.get_profileinfo(user_id)
|
||||||
await self.user_directory_handler.handle_local_profile_change(user_id, profile)
|
await self.user_directory_handler.handle_local_profile_change(user_id, profile)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class ProfileHandler:
|
||||||
target_user = UserID.from_string(user_id)
|
target_user = UserID.from_string(user_id)
|
||||||
|
|
||||||
if self.hs.is_mine(target_user):
|
if self.hs.is_mine(target_user):
|
||||||
profileinfo = await self.store.get_profileinfo(target_user.localpart)
|
profileinfo = await self.store.get_profileinfo(user_id)
|
||||||
if profileinfo.display_name is None:
|
if profileinfo.display_name is None:
|
||||||
raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)
|
raise SynapseError(404, "Profile was not found", Codes.NOT_FOUND)
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ class ProfileHandler:
|
||||||
raise AuthError(400, "Cannot set another user's displayname")
|
raise AuthError(400, "Cannot set another user's displayname")
|
||||||
|
|
||||||
if not by_admin and not self.hs.config.registration.enable_set_displayname:
|
if not by_admin and not self.hs.config.registration.enable_set_displayname:
|
||||||
profile = await self.store.get_profileinfo(target_user.localpart)
|
profile = await self.store.get_profileinfo(target_user.to_string())
|
||||||
if profile.display_name:
|
if profile.display_name:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400,
|
400,
|
||||||
|
@ -182,7 +182,7 @@ class ProfileHandler:
|
||||||
target_user.localpart, displayname_to_set
|
target_user.localpart, displayname_to_set
|
||||||
)
|
)
|
||||||
|
|
||||||
profile = await self.store.get_profileinfo(target_user.localpart)
|
profile = await self.store.get_profileinfo(target_user.to_string())
|
||||||
await self.user_directory_handler.handle_local_profile_change(
|
await self.user_directory_handler.handle_local_profile_change(
|
||||||
target_user.to_string(), profile
|
target_user.to_string(), profile
|
||||||
)
|
)
|
||||||
|
@ -243,7 +243,7 @@ class ProfileHandler:
|
||||||
raise AuthError(400, "Cannot set another user's avatar_url")
|
raise AuthError(400, "Cannot set another user's avatar_url")
|
||||||
|
|
||||||
if not by_admin and not self.hs.config.registration.enable_set_avatar_url:
|
if not by_admin and not self.hs.config.registration.enable_set_avatar_url:
|
||||||
profile = await self.store.get_profileinfo(target_user.localpart)
|
profile = await self.store.get_profileinfo(target_user.to_string())
|
||||||
if profile.avatar_url:
|
if profile.avatar_url:
|
||||||
raise SynapseError(
|
raise SynapseError(
|
||||||
400, "Changing avatar is disabled on this server", Codes.FORBIDDEN
|
400, "Changing avatar is disabled on this server", Codes.FORBIDDEN
|
||||||
|
@ -276,7 +276,7 @@ class ProfileHandler:
|
||||||
target_user.localpart, avatar_url_to_set
|
target_user.localpart, avatar_url_to_set
|
||||||
)
|
)
|
||||||
|
|
||||||
profile = await self.store.get_profileinfo(target_user.localpart)
|
profile = await self.store.get_profileinfo(target_user.to_string())
|
||||||
await self.user_directory_handler.handle_local_profile_change(
|
await self.user_directory_handler.handle_local_profile_change(
|
||||||
target_user.to_string(), profile
|
target_user.to_string(), profile
|
||||||
)
|
)
|
||||||
|
|
|
@ -314,7 +314,7 @@ class RegistrationHandler:
|
||||||
approved=approved,
|
approved=approved,
|
||||||
)
|
)
|
||||||
|
|
||||||
profile = await self.store.get_profileinfo(localpart)
|
profile = await self.store.get_profileinfo(user_id)
|
||||||
await self.user_directory_handler.handle_local_profile_change(
|
await self.user_directory_handler.handle_local_profile_change(
|
||||||
user_id, profile
|
user_id, profile
|
||||||
)
|
)
|
||||||
|
|
|
@ -648,7 +648,8 @@ class ModuleApi:
|
||||||
Returns:
|
Returns:
|
||||||
The profile information (i.e. display name and avatar URL).
|
The profile information (i.e. display name and avatar URL).
|
||||||
"""
|
"""
|
||||||
return await self._store.get_profileinfo(localpart)
|
user = UserID(localpart, self._hs.hostname)
|
||||||
|
return await self._store.get_profileinfo(user.to_string())
|
||||||
|
|
||||||
async def get_threepids_for_user(self, user_id: str) -> List[Dict[str, str]]:
|
async def get_threepids_for_user(self, user_id: str) -> List[Dict[str, str]]:
|
||||||
"""Look up the threepids (email addresses and phone numbers) associated with the
|
"""Look up the threepids (email addresses and phone numbers) associated with the
|
||||||
|
|
|
@ -21,21 +21,31 @@ from synapse.storage.database import (
|
||||||
LoggingTransaction,
|
LoggingTransaction,
|
||||||
)
|
)
|
||||||
from synapse.storage.databases.main.roommember import ProfileInfo
|
from synapse.storage.databases.main.roommember import ProfileInfo
|
||||||
from synapse.types import JsonDict
|
from synapse.types import JsonDict, UserID
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from synapse.server import HomeServer
|
from synapse.server import HomeServer
|
||||||
|
|
||||||
|
|
||||||
class ProfileWorkerStore(SQLBaseStore):
|
class ProfileWorkerStore(SQLBaseStore):
|
||||||
async def get_profileinfo(self, user_localpart: str) -> ProfileInfo:
|
async def get_profileinfo(self, user_id: str) -> ProfileInfo:
|
||||||
try:
|
try:
|
||||||
profile = await self.db_pool.simple_select_one(
|
profile = await self.db_pool.simple_select_one(
|
||||||
table="profiles",
|
table="profiles",
|
||||||
keyvalues={"user_id": user_localpart},
|
keyvalues={"full_user_id": user_id},
|
||||||
retcols=("displayname", "avatar_url"),
|
retcols=("displayname", "avatar_url"),
|
||||||
|
allow_none=True,
|
||||||
desc="get_profileinfo",
|
desc="get_profileinfo",
|
||||||
)
|
)
|
||||||
|
if profile is None:
|
||||||
|
# Fall back to the `user_id` column.
|
||||||
|
user_localpart = UserID.from_string(user_id).localpart
|
||||||
|
profile = await self.db_pool.simple_select_one(
|
||||||
|
table="profiles",
|
||||||
|
keyvalues={"user_id": user_localpart},
|
||||||
|
retcols=("displayname", "avatar_url"),
|
||||||
|
desc="get_profileinfo",
|
||||||
|
)
|
||||||
except StoreError as e:
|
except StoreError as e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
# no match
|
# no match
|
||||||
|
|
|
@ -383,7 +383,7 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore):
|
||||||
|
|
||||||
for user_id in users_to_work_on:
|
for user_id in users_to_work_on:
|
||||||
if await self.should_include_local_user_in_dir(user_id):
|
if await self.should_include_local_user_in_dir(user_id):
|
||||||
profile = await self.get_profileinfo(get_localpart_from_id(user_id)) # type: ignore[attr-defined]
|
profile = await self.get_profileinfo(user_id) # type: ignore[attr-defined]
|
||||||
await self.update_profile_in_user_dir(
|
await self.update_profile_in_user_dir(
|
||||||
user_id, profile.display_name, profile.avatar_url
|
user_id, profile.display_name, profile.avatar_url
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue