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