From af92f5b00fd9cbd8b9124f09384e718fac33a261 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 27 Oct 2017 15:07:21 +0100 Subject: [PATCH 1/3] Revert "Add jitter to validity period of attestations" --- synapse/groups/attestations.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/synapse/groups/attestations.py b/synapse/groups/attestations.py index fc5f92121e75..b751cf5e4317 100644 --- a/synapse/groups/attestations.py +++ b/synapse/groups/attestations.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import random - from twisted.internet import defer from synapse.api.errors import SynapseError @@ -27,11 +25,6 @@ # Default validity duration for new attestations we create DEFAULT_ATTESTATION_LENGTH_MS = 3 * 24 * 60 * 60 * 1000 -# We add some jitter to the validity duration of attestations so that if we -# add lots of users at once we don't need to renew them all at once. -# The jitter is a multiplier picked randomly between the first and second number -DEFAULT_ATTESTATION_JITTER = (0.9, 1.3) - # Start trying to update our attestations when they come this close to expiring UPDATE_ATTESTATION_TIME_MS = 1 * 24 * 60 * 60 * 1000 @@ -80,14 +73,10 @@ def create_attestation(self, group_id, user_id): """Create an attestation for the group_id and user_id with default validity length. """ - validity_period = DEFAULT_ATTESTATION_LENGTH_MS - validity_period *= random.uniform(*DEFAULT_ATTESTATION_JITTER) - valid_until_ms = int(self.clock.time_msec() + validity_period) - return sign_json({ "group_id": group_id, "user_id": user_id, - "valid_until_ms": valid_until_ms, + "valid_until_ms": self.clock.time_msec() + DEFAULT_ATTESTATION_LENGTH_MS, }, self.server_name, self.signing_key) From fa4f337b49b9a417cbb3a555cd959b1be36cc666 Mon Sep 17 00:00:00 2001 From: Francois Granade Date: Fri, 3 Nov 2017 18:25:04 +0100 Subject: [PATCH 2/3] Fix for issue 2635: correctly update rooms avatar/display name when modified by admin --- synapse/handlers/profile.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index 62b9bd503ec3..d6646825d89b 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -140,7 +140,7 @@ def set_displayname(self, target_user, requester, new_displayname, by_admin=Fals target_user.localpart, new_displayname ) - yield self._update_join_states(requester) + yield self._update_join_states(requester, target_user) @defer.inlineCallbacks def get_avatar_url(self, target_user): @@ -184,7 +184,7 @@ def set_avatar_url(self, target_user, requester, new_avatar_url, by_admin=False) target_user.localpart, new_avatar_url ) - yield self._update_join_states(requester) + yield self._update_join_states(requester, target_user) @defer.inlineCallbacks def on_profile_query(self, args): @@ -209,28 +209,24 @@ def on_profile_query(self, args): defer.returnValue(response) @defer.inlineCallbacks - def _update_join_states(self, requester): - user = requester.user - if not self.hs.is_mine(user): + def _update_join_states(self, requester, target_user): + if not self.hs.is_mine(target_user): return yield self.ratelimit(requester) room_ids = yield self.store.get_rooms_for_user( - user.to_string(), + target_user.to_string(), ) for room_id in room_ids: handler = self.hs.get_handlers().room_member_handler try: - # Assume the user isn't a guest because we don't let guests set - # profile or avatar data. - # XXX why are we recreating `requester` here for each room? - # what was wrong with the `requester` we were passed? - requester = synapse.types.create_requester(user) + # Assume the target_user isn't a guest, + # because we don't let guests set profile or avatar data. yield handler.update_membership( requester, - user, + target_user, room_id, "join", # We treat a profile update like a join. ratelimit=False, # Try to hide that these events aren't atomic. From f103b91ffa536d3d36697c159d6c13a7b952ba3a Mon Sep 17 00:00:00 2001 From: Francois Granade Date: Fri, 3 Nov 2017 18:45:49 +0100 Subject: [PATCH 3/3] removed unused import flagged by flake8a --- synapse/handlers/profile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index d6646825d89b..5e5b1952dd03 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -17,7 +17,6 @@ from twisted.internet import defer -import synapse.types from synapse.api.errors import SynapseError, AuthError, CodeMessageException from synapse.types import UserID, get_domain_from_id from ._base import BaseHandler