2019-02-27 19:19:49 +01:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/subsystems/hotspots.html
|
|
|
|
# for documentation on this subsystem.
|
2023-04-09 16:48:08 +02:00
|
|
|
from dataclasses import dataclass
|
2024-05-10 15:37:43 +02:00
|
|
|
from typing import Any, Dict, List
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-08-30 02:42:52 +02:00
|
|
|
from django.conf import settings
|
2018-04-18 18:16:30 +02:00
|
|
|
|
2023-12-01 08:20:48 +01:00
|
|
|
from zerver.models import OnboardingStep, UserProfile
|
2017-04-15 05:50:59 +02:00
|
|
|
|
2023-04-09 16:48:08 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
@dataclass
|
|
|
|
class OneTimeNotice:
|
|
|
|
name: str
|
|
|
|
|
|
|
|
def to_dict(self) -> Dict[str, str]:
|
|
|
|
return {
|
|
|
|
"type": "one_time_notice",
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-02 13:34:05 +01:00
|
|
|
ONE_TIME_NOTICES: List[OneTimeNotice] = [
|
|
|
|
OneTimeNotice(
|
|
|
|
name="visibility_policy_banner",
|
|
|
|
),
|
2024-03-05 12:03:05 +01:00
|
|
|
OneTimeNotice(
|
|
|
|
name="intro_inbox_view_modal",
|
|
|
|
),
|
2024-03-05 13:18:56 +01:00
|
|
|
OneTimeNotice(
|
|
|
|
name="intro_recent_view_modal",
|
|
|
|
),
|
2024-04-04 13:58:27 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="first_stream_created_banner",
|
|
|
|
),
|
2024-04-03 12:01:57 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="jump_to_conversation_banner",
|
|
|
|
),
|
2023-12-02 13:34:05 +01:00
|
|
|
]
|
2023-12-01 14:36:24 +01:00
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
# We may introduce onboarding step of types other than 'one time notice'
|
|
|
|
# in future. Earlier, we had 'hotspot' and 'one time notice' as the two
|
|
|
|
# types. We can simply do:
|
|
|
|
# ALL_ONBOARDING_STEPS: List[Union[OneTimeNotice, OtherType]]
|
|
|
|
# to avoid API changes when new type is introduced in the future.
|
|
|
|
ALL_ONBOARDING_STEPS: List[OneTimeNotice] = ONE_TIME_NOTICES
|
2023-04-09 16:48:08 +02:00
|
|
|
|
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
def get_next_onboarding_steps(user: UserProfile) -> List[Dict[str, Any]]:
|
2024-05-10 15:37:43 +02:00
|
|
|
# If a Zulip server has disabled the tutorial, never send any
|
|
|
|
# onboarding steps.
|
2021-03-11 17:19:49 +01:00
|
|
|
if not settings.TUTORIAL_ENABLED:
|
|
|
|
return []
|
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
seen_onboarding_steps = frozenset(
|
2023-12-01 08:20:48 +01:00
|
|
|
OnboardingStep.objects.filter(user=user).values_list("onboarding_step", flat=True)
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2024-05-10 15:37:43 +02:00
|
|
|
onboarding_steps: List[Dict[str, Any]] = []
|
2023-12-01 14:36:24 +01:00
|
|
|
for one_time_notice in ONE_TIME_NOTICES:
|
|
|
|
if one_time_notice.name in seen_onboarding_steps:
|
|
|
|
continue
|
|
|
|
onboarding_steps.append(one_time_notice.to_dict())
|
2021-05-08 11:00:12 +02:00
|
|
|
|
2023-12-01 14:36:24 +01:00
|
|
|
return onboarding_steps
|
2018-06-13 14:10:53 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2024-05-10 13:14:45 +02:00
|
|
|
def copy_onboarding_steps(source_profile: UserProfile, target_profile: UserProfile) -> None:
|
|
|
|
for onboarding_step in frozenset(OnboardingStep.objects.filter(user=source_profile)):
|
2023-12-01 08:20:48 +01:00
|
|
|
OnboardingStep.objects.create(
|
|
|
|
user=target_profile,
|
2024-05-10 13:14:45 +02:00
|
|
|
onboarding_step=onboarding_step.onboarding_step,
|
|
|
|
timestamp=onboarding_step.timestamp,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2018-06-13 14:10:53 +02:00
|
|
|
|
2024-05-29 14:38:50 +02:00
|
|
|
# TODO: The 'tutorial_status' field of 'UserProfile' model
|
|
|
|
# is no longer used. Remove it.
|
2018-06-13 14:10:53 +02:00
|
|
|
target_profile.tutorial_status = source_profile.tutorial_status
|
2024-05-29 14:38:50 +02:00
|
|
|
target_profile.save(update_fields=["tutorial_status"])
|