2024-06-18 13:34:32 +02:00
|
|
|
# See https://zulip.readthedocs.io/en/latest/subsystems/onboarding-steps.html
|
|
|
|
# for documentation on this subsystem.
|
2023-04-09 16:48:08 +02:00
|
|
|
from dataclasses import dataclass
|
2024-07-12 02:30:17 +02:00
|
|
|
from typing import Any
|
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
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def to_dict(self) -> dict[str, str]:
|
2023-12-01 14:36:24 +01:00
|
|
|
return {
|
|
|
|
"type": "one_time_notice",
|
|
|
|
"name": self.name,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
ONE_TIME_NOTICES: list[OneTimeNotice] = [
|
2023-12-02 13:34:05 +01:00
|
|
|
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",
|
|
|
|
),
|
2024-04-05 13:32:42 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="non_interleaved_view_messages_fading",
|
|
|
|
),
|
2024-04-23 09:04:05 +02:00
|
|
|
OneTimeNotice(
|
|
|
|
name="interleaved_view_messages_fading",
|
|
|
|
),
|
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.
|
2024-07-12 02:30:17 +02:00
|
|
|
ALL_ONBOARDING_STEPS: list[OneTimeNotice] = ONE_TIME_NOTICES
|
2023-04-09 16:48:08 +02:00
|
|
|
|
|
|
|
|
2024-07-12 02:30:17 +02: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-07-12 02:30:17 +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"])
|