Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

users: Use is_imported_stub flag for imported users.

Sahil Batra9c571c6f671c
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index adf2b8cdf9a..56808aeea43 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,18 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 12.0
+**Feature level 433**
+
+* [`GET /users`](/api/get-users), [`GET /users/{user_id}`](/api/get-user),
+ [`GET /users/{email}`](/api/get-user-by-email) and
+ [`GET /users/me`](/api/get-own-user): Added `is_imported_stub` field to
+ returned user objects.
+* [`POST /register`](/api/register-queue): Added `is_imported` field
+ in the user objects returned in the `realm_users` field and in the bot
+ objects returned in `cross_realm_bots` field.
+* [`GET /events`](/api/get-events): Added `is_imported_stub` field to
+ user objects sent in `realm_user` events.
+
**Feature level 432**
* [`POST /mobile_push/register`](/api/register-push-device): Replaced
diff --git a/version.py b/version.py
index 9eb1b21201d..f9a52667aaa 100644
--- a/version.py
+++ b/version.py
@@ -35,7 +35,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 432
+API_FEATURE_LEVEL = 433
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/zerver/actions/users.py b/zerver/actions/users.py
index 4c9d5ed1eb2..dc8cd58d02f 100644
--- a/zerver/actions/users.py
+++ b/zerver/actions/users.py
@@ -1001,3 +1001,22 @@ def do_send_password_reset_email(
realm=realm,
request=request,
)
+
+
[email protected](durable=True)
+def do_change_is_imported_stub(user_profile: UserProfile) -> None:
+ user_profile.is_imported_stub = False
+ user_profile.save(update_fields=["is_imported_stub"])
+
+ RealmAuditLog.objects.create(
+ realm=user_profile.realm,
+ modified_user=user_profile,
+ acting_user=user_profile,
+ event_type=AuditLogEventType.USER_IS_IMPORTED_STUB_CHANGED,
+ event_time=timezone_now(),
+ )
+
+ event = dict(
+ type="realm_user", op="update", person=dict(user_id=user_profile.id, is_imported_stub=False)
+ )
+ send_event_on_commit(user_profile.realm, event, get_user_ids_who_can_access_user(user_profile))
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.py
index f55596d6d92..7b0f74dd9be 100644
--- a/zerver/data_import/import_util.py
+++ b/zerver/data_import/import_util.py
@@ -127,6 +127,7 @@ def build_user_profile(
timezone=timezone,
is_bot=is_bot,
bot_type=bot_type,
+ is_imported_stub=True,
)
dct = model_to_dict(obj)
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index ce21115c7c4..1a937584205 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -371,6 +371,7 @@ def users_to_zerver_userprofile(
date_joined=timestamp,
timezone=timezone,
last_login=timestamp,
+ is_imported_stub=True,
)
userprofile_dict = model_to_dict(userprofile)
# Set realm id separately as the corresponding realm is not yet a Realm model instance
diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py
index a071f44fe19..0ac08c61596 100644
--- a/zerver/lib/cache.py
+++ b/zerver/lib/cache.py
@@ -535,6 +535,7 @@ realm_user_dict_fields: list[str] = [
"bot_type",
"long_term_idle",
"email_address_visibility",
+ "is_imported_stub",
]
diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.py
index c8da9473514..097247050e4 100644
--- a/zerver/lib/event_schema.py
+++ b/zerver/lib/event_schema.py
@@ -117,6 +117,7 @@ from zerver.lib.event_types import (
PersonEmail,
PersonFullName,
PersonIsActive,
+ PersonIsImportedStub,
PersonRole,
PersonTimezone,
PlanTypeData,
@@ -278,6 +279,7 @@ PERSON_TYPES: dict[str, type[BaseModel]] = dict(
role=PersonRole,
timezone=PersonTimezone,
is_active=PersonIsActive,
+ is_imported_stub=PersonIsImportedStub,
)
diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.py
index ab90d87102a..e79a0573db1 100644
--- a/zerver/lib/event_types.py
+++ b/zerver/lib/event_types.py
@@ -752,6 +752,11 @@ class PersonIsActive(BaseModel):
is_active: bool
+class PersonIsImportedStub(BaseModel):
+ user_id: int
+ is_imported_stub: bool
+
+
class EventRealmUserUpdate(BaseEvent):
type: Literal["realm_user"]
op: Literal["update"]
@@ -765,6 +770,7 @@ class EventRealmUserUpdate(BaseEvent):
| PersonRole
| PersonTimezone
| PersonIsActive
+ | PersonIsImportedStub
)
diff --git a/zerver/lib/types.py b/zerver/lib/types.py
index db336f7de96..669c87faf7a 100644
--- a/zerver/lib/types.py
+++ b/zerver/lib/types.py
@@ -395,6 +395,7 @@ class RawUserDict(TypedDict):
bot_type: int | None
long_term_idle: bool
email_address_visibility: int
+ is_imported_stub: bool
class RemoteRealmDictValue(TypedDict):
diff --git a/zerver/lib/users.py b/zerver/lib/users.py
index cf1df12a3b4..8d48eb135e6 100644
--- a/zerver/lib/users.py
+++ b/zerver/lib/users.py
@@ -583,6 +583,7 @@ class APIUserDict(TypedDict):
profile_data: NotRequired[dict[str, Any] | None]
is_system_bot: NotRequired[bool]
max_message_id: NotRequired[int]
+ is_imported_stub: bool
def format_user_row(
@@ -627,6 +628,7 @@ def format_user_row(
if acting_user is None
else row["date_joined"].isoformat(timespec="minutes"),
delivery_email=delivery_email,
+ is_imported_stub=row["is_imported_stub"],
)
if acting_user is None:
@@ -976,6 +978,7 @@ def user_profile_to_user_row(user_profile: UserProfile) -> RawUserDict:
bot_type=user_profile.bot_type,
long_term_idle=user_profile.long_term_idle,
email_address_visibility=user_profile.email_address_visibility,
+ is_imported_stub=user_profile.is_imported_stub,
)
@@ -1029,6 +1032,7 @@ def get_data_for_inaccessible_user(realm: Realm, user_id: int) -> APIUserDict:
delivery_email=None,
avatar_url=get_avatar_for_inaccessible_user(),
profile_data={},
+ is_imported_stub=False,
)
return user_dict
diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.py
index 981d8d76a0c..a97aaa0ff84 100644
--- a/zerver/models/realm_audit_logs.py
+++ b/zerver/models/realm_audit_logs.py
@@ -37,6 +37,7 @@ class AuditLogEventType(IntEnum):
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED = 131
USER_SETTING_CHANGED = 132
USER_DIGEST_EMAIL_CREATED = 133
+ USER_IS_IMPORTED_STUB_CHANGED = 134
REALM_DEACTIVATED = 201
REALM_REACTIVATED = 202
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index ed2b5485f0e..240262a8aa7 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -631,6 +631,21 @@ paths:
type: boolean
description: |
A boolean describing whether the user account has been deactivated.
+ - type: object
+ additionalProperties: false
+ description: |
+ When an imported user logs into the organization for
+ the first time.
+
+ **Changes**: New in Zulip 12.0 (feature level 433).
+ properties:
+ user_id:
+ type: integer
+ description: |
+ The ID of the user affected by this change.
+ is_imported_stub:
+ type: boolean
+ description: This value is always `false`.
additionalProperties: false
example:
{
@@ -1132,6 +1147,7 @@ paths:
"date_joined": "2020-07-15T15:04:02.030833+00:00",
"avatar_url": "https://secure.gravatar.com/avatar/c6b5578d4964bd9c5fae593c6868912a?d=identicon&version=1",
"profile_data": {},
+ "is_imported_stub": false,
},
"id": 0,
}
@@ -10463,6 +10479,7 @@ paths:
"is_guest": false,
"date_joined": "2019-10-20T07:50:53.728864+00:00",
"full_name": "aaron",
+ "is_imported_stub": false,
},
{
"date_joined": "2019-10-20T07:50:53.729659+00:00",
@@ -10502,6 +10519,7 @@ paths:
"is_active": true,
"email": "[email protected]",
"delivery_email": null,
+ "is_imported_stub": false,
},
{
"bot_owner_id": 11,
@@ -10519,6 +10537,7 @@ paths:
"bot_type": 1,
"timezone": "",
"is_bot": true,
+ "is_imported_stub": false,
},
],
}
@@ -11056,6 +11075,17 @@ paths:
present only when `email_address_visibility` was restricted and the
requesting user had permission to access realm users' emails. As of
this feature level, this field is always present.
+ is_imported_stub:
+ type: boolean
+ description: |
+ Indicates whether this user object is a stub account imported from
+ another chat system. Stub accounts are used to represent the senders
+ for imported messages. Stub accounts can be converted to regular Zulip
+ accounts when the user starts using Zulip, preserving that imported
+ user's message history.
+
+ **Changes**: New in Zulip 12.0 (feature level 433).
+ example: false
profile_data:
$ref: "#/components/schemas/profile_data"
example:
@@ -11077,6 +11107,7 @@ paths:
"msg": "",
"result": "success",
"user_id": 5,
+ "is_imported_stub": false,
"profile_data":
{
"5": {"value": "2000-01-01"},
@@ -14875,6 +14906,7 @@ paths:
"is_active": true,
"email": "[email protected]",
"delivery_email": null,
+ "is_imported_stub": false,
},
}
patch:
@@ -15009,6 +15041,7 @@ paths:
"is_active": true,
"email": "[email protected]",
"delivery_email": null,
+ "is_imported_stub": false,
},
}
patch:
@@ -21340,6 +21373,7 @@ paths:
nullable: true
avatar_version: {}
profile_data: {}
+ is_imported_stub: {}
server_supported_permission_settings:
description: |
Present if `realm` is present in `fetch_event_types`.
@@ -28140,6 +28174,7 @@ components:
avatar_url:
nullable: true
avatar_version: {}
+ is_imported_stub: {}
profile_data: {}
UserBase:
type: object
@@ -28276,6 +28311,17 @@ components:
Version for the user's avatar. Used for cache-busting requests
for the user's avatar. Clients generally shouldn't need to use this;
most avatar URLs sent by Zulip will already end with `?v={avatar_version}`.
+ is_imported_stub:
+ type: boolean
+ description: |
+ Indicates whether this user object is a stub account imported from
+ another chat system. Stub accounts are used to represent the senders
+ for imported messages. Stub accounts can be converted to regular Zulip
+ accounts when the user starts using Zulip, preserving that imported
+ user's message history.
+
+ **Changes**: New in Zulip 12.0 (feature level 433).
+ example: false
profile_data:
$ref: "#/components/schemas/profile_data"
profile_data:
diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py
index 7dec380352f..470a284be78 100644
--- a/zerver/tests/test_audit_log.py
+++ b/zerver/tests/test_audit_log.py
@@ -82,7 +82,7 @@ from zerver.actions.user_settings import (
do_change_user_setting,
do_regenerate_api_key,
)
-from zerver.actions.users import do_change_user_role, do_deactivate_user
+from zerver.actions.users import do_change_is_imported_stub, do_change_user_role, do_deactivate_user
from zerver.lib.emoji import get_emoji_file_name, get_emoji_url
from zerver.lib.message import get_last_message_id
from zerver.lib.stream_traffic import get_streams_traffic
@@ -1784,3 +1784,21 @@ class TestRealmAuditLog(ZulipTestCase):
self.assert_length(audit_log_entries, 1)
self.assertEqual(audit_log_entries[0].modified_user, hamlet)
self.assertEqual(audit_log_entries[0].extra_data, {"fragment": "inbox"})
+
+ def test_changing_is_imported_stub(self) -> None:
+ hamlet = self.example_user("hamlet")
+ hamlet.is_imported_stub = True
+ hamlet.save()
+
+ now = timezone_now()
+ do_change_is_imported_stub(hamlet)
+
+ audit_log_entries = RealmAuditLog.objects.filter(
+ acting_user=hamlet,
+ realm=hamlet.realm,
+ event_time__gte=now,
+ event_type=AuditLogEventType.USER_IS_IMPORTED_STUB_CHANGED,
+ )
+ self.assert_length(audit_log_entries, 1)
+ self.assertEqual(audit_log_entries[0].modified_user, hamlet)
+ self.assertEqual(audit_log_entries[0].extra_data, {})
diff --git a/zerver/tests/test_custom_profile_data.py b/zerver/tests/test_custom_profile_data.py
index 1ae3c64f821..2b51460428b 100644
--- a/zerver/tests/test_custom_profile_data.py
+++ b/zerver/tests/test_custom_profile_data.py
@@ -1171,6 +1171,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"is_active",
"date_joined",
"profile_data",
+ "is_imported_stub",
}
self.assertEqual(set(iago_raw_data.keys()), expected_keys_for_iago)
self.assertNotEqual(iago_raw_data["profile_data"], {})
@@ -1192,6 +1193,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"date_joined",
"bot_type",
"bot_owner_id",
+ "is_imported_stub",
}
self.assertEqual(set(test_bot_raw_data.keys()), expected_keys_for_test_bot)
self.assertEqual(test_bot_raw_data["bot_type"], 1)
@@ -1230,6 +1232,7 @@ class ListCustomProfileFieldTest(CustomProfileFieldTestCase):
"is_active",
"is_guest",
"date_joined",
+ "is_imported_stub",
}
url = "/json/users/me"
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 04493473c03..bb671430972 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -159,6 +159,7 @@ from zerver.actions.user_settings import (
from zerver.actions.user_status import do_update_user_status
from zerver.actions.user_topics import do_set_user_topic_visibility_policy
from zerver.actions.users import (
+ do_change_is_imported_stub,
do_change_user_role,
do_deactivate_user,
do_update_outgoing_webhook_service,
@@ -3859,6 +3860,17 @@ class NormalActionsTest(BaseAction):
check_subscription_peer_add("events[2]", events[2])
check_user_group_add_members("events[3]", events[3])
+ def test_do_activate_imported_stub_user(self) -> None:
+ self.user_profile.is_imported_stub = True
+ self.user_profile.save()
+
+ with self.verify_action() as events:
+ do_change_is_imported_stub(self.user_profile)
+
+ check_realm_user_update("events[0]", events[0], "is_imported_stub")
+ self.assertEqual(events[0]["person"]["user_id"], self.user_profile.id)
+ self.assertFalse(events[0]["person"]["is_imported_stub"])
+
def test_do_deactivate_realm(self) -> None:
realm = self.user_profile.realm
diff --git a/zerver/tests/test_example.py b/zerver/tests/test_example.py
index e56897c7424..b5486e104e7 100644
--- a/zerver/tests/test_example.py
+++ b/zerver/tests/test_example.py
@@ -137,6 +137,7 @@ class TestFullStack(ZulipTestCase):
role=UserProfile.ROLE_MEMBER,
timezone="Etc/UTC",
user_id=cordelia.id,
+ is_imported_stub=False,
),
)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 455f9007f4f..c37fd100d2e 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -744,6 +744,18 @@ class HomeTest(ZulipTestCase):
user.email_address_visibility, UserProfile.EMAIL_ADDRESS_VISIBILITY_MODERATORS
)
+ # Test is_imported_stub is set to False when user accepts terms of service.
+ user.tos_version = "-1"
+ user.is_imported_stub = True
+ user.save()
+
+ result = self.client_post("/accounts/accept_terms/", {"terms": True})
+ self.assertEqual(result.status_code, 302)
+ self.assertEqual(result["Location"], "/")
+
+ user = self.example_user("hamlet")
+ self.assertFalse(user.is_imported_stub)
+
def test_set_email_address_visibility_without_terms_of_service(self) -> None:
self.login("hamlet")
user = self.example_user("hamlet")
@@ -962,6 +974,7 @@ class HomeTest(ZulipTestCase):
role=cross_realm_email_gateway_bot.role,
is_system_bot=True,
is_guest=False,
+ is_imported_stub=False,
),
dict(
avatar_version=cross_realm_notification_bot.avatar_version,
@@ -978,6 +991,7 @@ class HomeTest(ZulipTestCase):
role=cross_realm_notification_bot.role,
is_system_bot=True,
is_guest=False,
+ is_imported_stub=False,
),
dict(
avatar_version=cross_realm_welcome_bot.avatar_version,
@@ -994,6 +1008,7 @@ class HomeTest(ZulipTestCase):
role=cross_realm_welcome_bot.role,
is_system_bot=True,
is_guest=False,
+ is_imported_stub=False,
),
],
key=by_email,
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 549c3379073..d69c6a3a53b 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -1780,6 +1780,11 @@ class RealmImportExportTest(ExportFile):
).count(),
)
+ # Check is_imported_stub is False for users imported from another
+ # Zulip organization.
+ for user_profile in UserProfile.objects.filter(realm=imported_realm):
+ self.assertFalse(user_profile.is_imported_stub)
+
# Check folder field for imported streams
for stream in Stream.objects.filter(realm=imported_realm):
if stream.name == "Verona":
diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.py
index ab4a504999c..707a593fad1 100644
--- a/zerver/tests/test_mattermost_importer.py
+++ b/zerver/tests/test_mattermost_importer.py
@@ -109,6 +109,7 @@ class MatterMostImporter(ZulipTestCase):
self.assertEqual(user["realm"], 3)
self.assertEqual(user["short_name"], "harry")
self.assertEqual(user["timezone"], "UTC")
+ self.assertEqual(user["is_imported_stub"], True)
# A user with a `null` team value shouldn't be an admin.
harry_dict["teams"] = None
@@ -130,6 +131,7 @@ class MatterMostImporter(ZulipTestCase):
self.assertEqual(user["realm"], 3)
self.assertEqual(user["short_name"], "snape")
self.assertEqual(user["timezone"], "UTC")
+ self.assertEqual(user["is_imported_stub"], True)
def test_process_guest_user(self) -> None:
user_id_mapper = IdMapper[str]()
@@ -154,6 +156,7 @@ class MatterMostImporter(ZulipTestCase):
self.assertEqual(user["realm"], 3)
self.assertEqual(user["short_name"], "sirius")
self.assertEqual(user["timezone"], "UTC")
+ self.assertEqual(user["is_imported_stub"], True)
# A guest user with a `null` team value should be a regular
# user. (It's a bit of a mystery why the Mattermost export
diff --git a/zerver/tests/test_rocketchat_importer.py b/zerver/tests/test_rocketchat_importer.py
index be3d977bd1b..90811c52a0d 100644
--- a/zerver/tests/test_rocketchat_importer.py
+++ b/zerver/tests/test_rocketchat_importer.py
@@ -128,6 +128,7 @@ class RocketChatImporter(ZulipTestCase):
self.assertEqual(user["realm"], realm_id)
self.assertEqual(user["short_name"], "rocket.cat")
self.assertEqual(user["timezone"], "UTC")
+ self.assertEqual(user["is_imported_stub"], True)
user_id = user_id_mapper.get(rocketchat_data["user"][2]["_id"])
user = user_handler.get_user(user_id)
@@ -147,6 +148,7 @@ class RocketChatImporter(ZulipTestCase):
self.assertEqual(user["realm"], realm_id)
self.assertEqual(user["short_name"], "harry.potter")
self.assertEqual(user["timezone"], "UTC")
+ self.assertEqual(user["is_imported_stub"], True)
# Test `is_mirror_dummy` set for users of type `unknown`
rocketchat_data["user"].append(
diff --git a/zerver/tests/test_slack_importer.py b/zerver/tests/test_slack_importer.py
index 99ec7eebd01..73feedb74a0 100644
--- a/zerver/tests/test_slack_importer.py
+++ b/zerver/tests/test_slack_importer.py
@@ -770,6 +770,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[0]["enable_desktop_notifications"], True)
self.assertEqual(zerver_userprofile[0]["email"], "[email protected]")
self.assertEqual(zerver_userprofile[0]["full_name"], "John Doe")
+ self.assertEqual(zerver_userprofile[0]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[1]["id"], test_slack_user_id_to_zulip_user_id["U0CBK5KAT"]
@@ -778,6 +779,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[1]["is_staff"], False)
self.assertEqual(zerver_userprofile[1]["is_active"], True)
self.assertEqual(zerver_userprofile[0]["is_mirror_dummy"], False)
+ self.assertEqual(zerver_userprofile[1]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[2]["id"], test_slack_user_id_to_zulip_user_id["U09TYF5Sk"]
@@ -788,6 +790,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[2]["email"], "[email protected]")
self.assertEqual(zerver_userprofile[2]["bot_type"], 1)
self.assertEqual(zerver_userprofile[2]["avatar_source"], "U")
+ self.assertEqual(zerver_userprofile[2]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[3]["id"], test_slack_user_id_to_zulip_user_id["UHSG7OPQN"]
@@ -800,6 +803,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[3]["full_name"], "Matt Perry")
self.assertEqual(zerver_userprofile[3]["is_mirror_dummy"], True)
self.assertEqual(zerver_userprofile[3]["can_forge_sender"], False)
+ self.assertEqual(zerver_userprofile[3]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[4]["id"], test_slack_user_id_to_zulip_user_id["U8VAHEVUY"]
@@ -808,6 +812,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[4]["is_staff"], False)
self.assertEqual(zerver_userprofile[4]["is_active"], True)
self.assertEqual(zerver_userprofile[4]["is_mirror_dummy"], False)
+ self.assertEqual(zerver_userprofile[4]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[5]["id"], test_slack_user_id_to_zulip_user_id["U8X25EBAB"]
@@ -816,6 +821,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[5]["is_staff"], False)
self.assertEqual(zerver_userprofile[5]["is_active"], True)
self.assertEqual(zerver_userprofile[5]["is_mirror_dummy"], False)
+ self.assertEqual(zerver_userprofile[5]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[6]["id"], test_slack_user_id_to_zulip_user_id["U015J7JSE"]
@@ -824,6 +830,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[6]["is_staff"], False)
self.assertEqual(zerver_userprofile[6]["is_active"], True)
self.assertEqual(zerver_userprofile[6]["is_mirror_dummy"], False)
+ self.assertEqual(zerver_userprofile[6]["is_imported_stub"], True)
self.assertEqual(
zerver_userprofile[7]["id"], test_slack_user_id_to_zulip_user_id["U1RDFEC80"]
@@ -832,6 +839,7 @@ class SlackImporter(ZulipTestCase):
self.assertEqual(zerver_userprofile[7]["is_staff"], False)
self.assertEqual(zerver_userprofile[7]["is_active"], True)
self.assertEqual(zerver_userprofile[7]["is_mirror_dummy"], False)
+ self.assertEqual(zerver_userprofile[7]["is_imported_stub"], True)
# Importer should raise error when user emails are malformed
bad_email1 = user_data[0]["profile"]["email"] = "jon@gmail,com"
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 754bda7e9d1..391cac6dd5b 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -1683,6 +1683,7 @@ class UserProfileTest(ZulipTestCase):
is_system_bot=True,
role=400,
timezone="",
+ is_imported_stub=False,
)
expected_emails = [
diff --git a/zerver/views/home.py b/zerver/views/home.py
index 5b4b6a97717..22ad42938e1 100644
--- a/zerver/views/home.py
+++ b/zerver/views/home.py
@@ -8,6 +8,7 @@ from django.urls import reverse
from django.utils.cache import patch_cache_control
from zerver.actions.user_settings import do_change_tos_version, do_change_user_setting
+from zerver.actions.users import do_change_is_imported_stub
from zerver.context_processors import get_realm_from_request, get_valid_realm_from_request
from zerver.decorator import web_public_view, zulip_login_required
from zerver.forms import ToSForm
@@ -69,6 +70,10 @@ def accounts_accept_terms(request: HttpRequest) -> HttpResponse:
enable_marketing_emails,
acting_user=request.user,
)
+
+ if request.user.is_imported_stub:
+ do_change_is_imported_stub(request.user)
+
return redirect(home)
else:
form = ToSForm()