mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	sessions: Fix type: ignore issues.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		@@ -1,7 +1,6 @@
 | 
			
		||||
# See https://zulip.readthedocs.io/en/latest/subsystems/caching.html for docs
 | 
			
		||||
import datetime
 | 
			
		||||
import logging
 | 
			
		||||
from importlib import import_module
 | 
			
		||||
from typing import Any, Callable, Dict, List, Tuple
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
@@ -22,6 +21,7 @@ from zerver.lib.cache import (
 | 
			
		||||
    user_profile_cache_key,
 | 
			
		||||
)
 | 
			
		||||
from zerver.lib.message import MessageDict
 | 
			
		||||
from zerver.lib.sessions import session_engine
 | 
			
		||||
from zerver.lib.users import get_all_api_keys
 | 
			
		||||
from zerver.models import (
 | 
			
		||||
    Client,
 | 
			
		||||
@@ -75,7 +75,6 @@ def huddle_cache_items(items_for_remote_cache: Dict[str, Tuple[Huddle]],
 | 
			
		||||
                       huddle: Huddle) -> None:
 | 
			
		||||
    items_for_remote_cache[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,)
 | 
			
		||||
 | 
			
		||||
session_engine = import_module(settings.SESSION_ENGINE)
 | 
			
		||||
def session_cache_items(items_for_remote_cache: Dict[str, str],
 | 
			
		||||
                        session: Session) -> None:
 | 
			
		||||
    if settings.SESSION_ENGINE != "django.contrib.sessions.backends.cached_db":
 | 
			
		||||
@@ -83,7 +82,7 @@ def session_cache_items(items_for_remote_cache: Dict[str, str],
 | 
			
		||||
        # will be no store.cache_key attribute, and in any case we
 | 
			
		||||
        # don't need to fill the cache, since it won't exist.
 | 
			
		||||
        return
 | 
			
		||||
    store = session_engine.SessionStore(session_key=session.session_key)  # type: ignore[attr-defined] # import_module
 | 
			
		||||
    store = session_engine.SessionStore(session_key=session.session_key)
 | 
			
		||||
    items_for_remote_cache[store.cache_key] = store.decode(session.session_data)
 | 
			
		||||
 | 
			
		||||
def get_active_realm_ids() -> List[int]:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,11 @@
 | 
			
		||||
# See https://zulip.readthedocs.io/en/latest/subsystems/events-system.html for
 | 
			
		||||
# high-level documentation on how this system works.
 | 
			
		||||
import copy
 | 
			
		||||
from importlib import import_module
 | 
			
		||||
from typing import Any, Callable, Dict, Iterable, Optional, Sequence, Set
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.utils.translation import ugettext as _
 | 
			
		||||
 | 
			
		||||
session_engine = import_module(settings.SESSION_ENGINE)
 | 
			
		||||
 | 
			
		||||
from version import API_FEATURE_LEVEL, ZULIP_VERSION
 | 
			
		||||
from zerver.lib.actions import (
 | 
			
		||||
    default_stream_groups_to_dicts_sorted,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,23 @@
 | 
			
		||||
import logging
 | 
			
		||||
from datetime import timedelta
 | 
			
		||||
from importlib import import_module
 | 
			
		||||
from typing import Any, List, Mapping, Optional
 | 
			
		||||
from typing import Any, List, Mapping, Optional, Type, cast
 | 
			
		||||
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.contrib.auth import SESSION_KEY, get_user_model
 | 
			
		||||
from django.contrib.sessions.backends.base import SessionBase
 | 
			
		||||
from django.contrib.sessions.models import Session
 | 
			
		||||
from django.utils.timezone import now as timezone_now
 | 
			
		||||
from typing_extensions import Protocol
 | 
			
		||||
 | 
			
		||||
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
 | 
			
		||||
from zerver.models import Realm, UserProfile, get_user_profile_by_id
 | 
			
		||||
 | 
			
		||||
session_engine = import_module(settings.SESSION_ENGINE)
 | 
			
		||||
 | 
			
		||||
class SessionEngine(Protocol):
 | 
			
		||||
    SessionStore: Type[SessionBase]
 | 
			
		||||
 | 
			
		||||
session_engine = cast(SessionEngine, import_module(settings.SESSION_ENGINE))
 | 
			
		||||
 | 
			
		||||
def get_session_dict_user(session_dict: Mapping[str, int]) -> Optional[int]:
 | 
			
		||||
    # Compare django.contrib.auth._get_user_session_key
 | 
			
		||||
@@ -28,7 +34,7 @@ def user_sessions(user_profile: UserProfile) -> List[Session]:
 | 
			
		||||
            if get_session_user(s) == user_profile.id]
 | 
			
		||||
 | 
			
		||||
def delete_session(session: Session) -> None:
 | 
			
		||||
    session_engine.SessionStore(session.session_key).delete()  # type: ignore[attr-defined] # import_module
 | 
			
		||||
    session_engine.SessionStore(session.session_key).delete()
 | 
			
		||||
 | 
			
		||||
def delete_user_sessions(user_profile: UserProfile) -> None:
 | 
			
		||||
    for session in Session.objects.all():
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user