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.

support: Display plan data for users and confirmations.

Zixuan James Lia76c7d374bb4
diff --git a/analytics/tests/test_support_views.py b/analytics/tests/test_support_views.py
index 98dfd7841f3..8cf04462d28 100644
--- a/analytics/tests/test_support_views.py
+++ b/analytics/tests/test_support_views.py
@@ -28,6 +28,9 @@ if TYPE_CHECKING:
class TestSupportEndpoint(ZulipTestCase):
def test_search(self) -> None:
reset_emails_in_zulip_realm()
+ lear_user = self.lear_user("king")
+ lear_user.is_staff = True
+ lear_user.save(update_fields=["is_staff"])
lear_realm = get_realm("lear")
def assert_user_details_in_html_response(
@@ -75,6 +78,11 @@ class TestSupportEndpoint(ZulipTestCase):
result,
)
+ def check_lear_user_query_result(result: "TestHttpResponse") -> None:
+ assert_user_details_in_html_response(
+ result, lear_user.full_name, lear_user.email, "Member"
+ )
+
def check_othello_user_query_result(result: "TestHttpResponse") -> None:
assert_user_details_in_html_response(
result, "Othello, the Moor of Venice", self.example_email("othello"), "Member"
@@ -240,6 +248,10 @@ class TestSupportEndpoint(ZulipTestCase):
check_hamlet_user_query_result(result)
check_zulip_realm_query_result(result)
+ result = get_check_query_result(lear_user.email, 1)
+ check_lear_user_query_result(result)
+ check_lear_realm_query_result(result)
+
result = get_check_query_result(self.example_email("polonius"), 1)
check_polonius_user_query_result(result)
check_zulip_realm_query_result(result)
@@ -309,6 +321,18 @@ class TestSupportEndpoint(ZulipTestCase):
check_realm_reactivation_link_query_result(result)
check_zulip_realm_query_result(result)
+ lear_nonreg_email = "[email protected]"
+ self.client_post("/accounts/home/", {"email": lear_nonreg_email}, subdomain="lear")
+ result = get_check_query_result(lear_nonreg_email, 1)
+ check_preregistration_user_query_result(result, lear_nonreg_email)
+ check_lear_realm_query_result(result)
+
+ self.login_user(lear_user)
+ create_invitation("general", "[email protected]", lear_realm)
+ result = get_check_query_result("[email protected]", 1, lear_realm.string_id)
+ check_preregistration_user_query_result(result, "[email protected]", invite=True)
+ check_lear_realm_query_result(result)
+
def test_get_org_type_display_name(self) -> None:
self.assertEqual(get_org_type_display_name(Realm.ORG_TYPES["business"]["id"]), "Business")
self.assertEqual(get_org_type_display_name(883), "")
diff --git a/analytics/views/support.py b/analytics/views/support.py
index 1a2724ef7fc..5fc0a935f8c 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -287,30 +287,11 @@ def support(
except ValidationError:
users.update(UserProfile.objects.filter(full_name__iexact=key_word))
- plan_data: Dict[int, PlanData] = {}
- for realm in realms:
- current_plan = get_current_plan_by_realm(realm)
- plan_data[realm.id] = PlanData(
- customer=get_customer_by_realm(realm),
- current_plan=current_plan,
- )
- if current_plan is not None:
- new_plan, last_ledger_entry = make_end_of_cycle_updates_if_needed(
- current_plan, timezone_now()
- )
- if last_ledger_entry is not None:
- if new_plan is not None:
- plan_data[realm.id].current_plan = new_plan
- else:
- plan_data[realm.id].current_plan = current_plan
- plan_data[realm.id].licenses = last_ledger_entry.licenses
- plan_data[realm.id].licenses_used = get_latest_seat_count(realm)
# full_names can have , in them
users.update(UserProfile.objects.filter(full_name__iexact=query))
context["users"] = users
context["realms"] = realms
- context["plan_data"] = plan_data
confirmations: List[Dict[str, Any]] = []
@@ -334,6 +315,39 @@ def support(
context["confirmations"] = confirmations
+ # We want a union of all realms that might appear in the search result,
+ # but not necessary as a separate result item.
+ # Therefore, we do not modify the realms object in the context.
+ all_realms = realms.union(
+ [
+ confirmation["object"].realm
+ for confirmation in confirmations
+ # For confirmations, we only display realm details when the type is USER_REGISTRATION
+ # or INVITATION.
+ if confirmation["type"] in (Confirmation.USER_REGISTRATION, Confirmation.INVITATION)
+ ]
+ + [user.realm for user in users]
+ )
+ plan_data: Dict[int, PlanData] = {}
+ for realm in all_realms:
+ current_plan = get_current_plan_by_realm(realm)
+ plan_data[realm.id] = PlanData(
+ customer=get_customer_by_realm(realm),
+ current_plan=current_plan,
+ )
+ if current_plan is not None:
+ new_plan, last_ledger_entry = make_end_of_cycle_updates_if_needed(
+ current_plan, timezone_now()
+ )
+ if last_ledger_entry is not None:
+ if new_plan is not None:
+ plan_data[realm.id].current_plan = new_plan
+ else:
+ plan_data[realm.id].current_plan = current_plan
+ plan_data[realm.id].licenses = last_ledger_entry.licenses
+ plan_data[realm.id].licenses_used = get_latest_seat_count(realm)
+ context["plan_data"] = plan_data
+
def get_realm_owner_emails_as_string(realm: Realm) -> str:
return ", ".join(
realm.get_human_owner_users()