def user_cache_items(items_for_remote_cache: Dict[str, Tuple[UserProfile]], user_profile: UserProfile) -> None: for api_key in get_all_api_keys(user_profile): items_for_remote_cache[user_profile_by_api_key_cache_key(api_key)] = ( user_profile, ) items_for_remote_cache[user_profile_cache_key( user_profile.email, user_profile.realm)] = (user_profile, )
def user_cache_items(items_for_remote_cache: Dict[str, Tuple[UserProfile]], user_profile: UserProfile) -> None: items_for_remote_cache[user_profile_by_email_cache_key( user_profile.email)] = (user_profile, ) items_for_remote_cache[user_profile_by_id_cache_key( user_profile.id)] = (user_profile, ) items_for_remote_cache[user_profile_by_api_key_cache_key( user_profile.api_key)] = (user_profile, ) items_for_remote_cache[user_profile_cache_key( user_profile.email, user_profile.realm)] = (user_profile, )
def user_cache_items(items_for_remote_cache, user_profile): # type: (Dict[Text, Tuple[UserProfile]], UserProfile) -> None items_for_remote_cache[user_profile_by_email_cache_key( user_profile.email)] = (user_profile, ) items_for_remote_cache[user_profile_by_id_cache_key( user_profile.id)] = (user_profile, ) items_for_remote_cache[user_profile_by_api_key_cache_key( user_profile.api_key)] = (user_profile, ) items_for_remote_cache[user_profile_cache_key( user_profile.email, user_profile.realm)] = (user_profile, )
def reset_user_api_key(user_profile: Any) -> None: old_api_key = user_profile.api_key user_profile.api_key = generate_api_key() cache_delete(user_profile_by_api_key_cache_key(old_api_key)) # Like with any API key change, we need to clear any server-side # state for sending push notifications to mobile app clients that # could have been registered with the old API key. Fortunately, # we can just write to the queue processor that handles sending # those notices to the push notifications bouncer service. event = {'type': 'clear_push_device_tokens', 'user_profile_id': user_profile.id} queue_json_publish("deferred_work", event)
def do_regenerate_api_key(user_profile: UserProfile, acting_user: UserProfile) -> str: old_api_key = user_profile.api_key new_api_key = generate_api_key() user_profile.api_key = new_api_key user_profile.save(update_fields=["api_key"]) # We need to explicitly delete the old API key from our caches, # because the on-save handler for flushing the UserProfile object # in zerver/lib/cache.py only has access to the new API key. cache_delete(user_profile_by_api_key_cache_key(old_api_key)) event_time = timezone_now() RealmAuditLog.objects.create( realm=user_profile.realm, acting_user=acting_user, modified_user=user_profile, event_type=RealmAuditLog.USER_API_KEY_CHANGED, event_time=event_time, ) if user_profile.is_bot: send_event( user_profile.realm, dict( type="realm_bot", op="update", bot=dict( user_id=user_profile.id, api_key=new_api_key, ), ), bot_owner_user_ids(user_profile), ) event = { "type": "clear_push_device_tokens", "user_profile_id": user_profile.id } queue_json_publish("deferred_work", event) return new_api_key
def user_cache_items(items_for_remote_cache: Dict[Text, Tuple[UserProfile]], user_profile: UserProfile) -> None: items_for_remote_cache[user_profile_by_email_cache_key(user_profile.email)] = (user_profile,) items_for_remote_cache[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,) items_for_remote_cache[user_profile_by_api_key_cache_key(user_profile.api_key)] = (user_profile,) items_for_remote_cache[user_profile_cache_key(user_profile.email, user_profile.realm)] = (user_profile,)
def user_cache_items(items_for_remote_cache: Dict[str, Tuple[UserProfile]], user_profile: UserProfile) -> None: for api_key in get_all_api_keys(user_profile): items_for_remote_cache[user_profile_by_api_key_cache_key(api_key)] = (user_profile,) items_for_remote_cache[user_profile_cache_key(user_profile.email, user_profile.realm)] = (user_profile,)