mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	support: Show file upload usage compared to realm upload quota.
Implemented on Zulip Cloud support view only since this information isn't relevant for self-hosted support actions. Looking up the realm's currently used upload space adds 3 database queries to the support view test as there is no RealmCount data for the upload quota used in the test. And therefore installation_epoch is called for the realm. With RealmCount upload quota used data, only 2 additional database queries would be made for the realm's support view data.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							798f59a01b
						
					
				
				
					commit
					7fc9d29c1e
				
			@@ -126,12 +126,32 @@ class CloudSupportData:
 | 
			
		||||
    plan_data: PlanData
 | 
			
		||||
    sponsorship_data: SponsorshipData
 | 
			
		||||
    user_data: UserData
 | 
			
		||||
    file_upload_usage: str
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_stripe_customer_url(stripe_id: str) -> str:
 | 
			
		||||
    return f"https://dashboard.stripe.com/customers/{stripe_id}"  # nocoverage
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_formatted_realm_upload_space_used(realm: Realm) -> str:  # nocoverage
 | 
			
		||||
    realm_bytes_used = realm.currently_used_upload_space_bytes()
 | 
			
		||||
    files_uploaded = realm_bytes_used > 0
 | 
			
		||||
 | 
			
		||||
    realm_uploads = "No uploads"
 | 
			
		||||
    if files_uploaded:
 | 
			
		||||
        realm_uploads = str(round(realm_bytes_used / 1024 / 1024, 2))
 | 
			
		||||
 | 
			
		||||
    quota = realm.upload_quota_bytes()
 | 
			
		||||
    if quota is None:
 | 
			
		||||
        if files_uploaded:
 | 
			
		||||
            return f"{realm_uploads} MB / No quota"
 | 
			
		||||
        return f"{realm_uploads} / No quota"
 | 
			
		||||
    if quota == 0:
 | 
			
		||||
        return f"{realm_uploads} / 0.0 MB"
 | 
			
		||||
    quota_mb = round(quota / 1024 / 1024, 2)
 | 
			
		||||
    return f"{realm_uploads} / {quota_mb} MB"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_realm_user_data(realm: Realm) -> UserData:
 | 
			
		||||
    non_guests = get_non_guest_user_count(realm)
 | 
			
		||||
    guests = get_guest_user_count(realm)
 | 
			
		||||
@@ -477,4 +497,5 @@ def get_data_for_cloud_support_view(billing_session: BillingSession) -> CloudSup
 | 
			
		||||
        plan_data=plan_data,
 | 
			
		||||
        sponsorship_data=sponsorship_data,
 | 
			
		||||
        user_data=user_data,
 | 
			
		||||
        file_upload_usage=get_formatted_realm_upload_space_used(billing_session.realm),
 | 
			
		||||
    )
 | 
			
		||||
 
 | 
			
		||||
@@ -751,7 +751,7 @@ class TestSupportEndpoint(ZulipTestCase):
 | 
			
		||||
    def test_realm_support_view_queries(self) -> None:
 | 
			
		||||
        iago = self.example_user("iago")
 | 
			
		||||
        self.login_user(iago)
 | 
			
		||||
        with self.assert_database_query_count(19):
 | 
			
		||||
        with self.assert_database_query_count(22):
 | 
			
		||||
            result = self.client_get("/activity/support", {"q": "zulip"}, subdomain="zulip")
 | 
			
		||||
            self.assertEqual(result.status_code, 200)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -55,6 +55,8 @@
 | 
			
		||||
        {% set user_data = realm_support_data[realm.id].user_data %}
 | 
			
		||||
        {% include 'corporate/support/basic_realm_data.html' %}
 | 
			
		||||
    {% endwith %}
 | 
			
		||||
    <br />
 | 
			
		||||
    <b>File upload usage</b>: {{ realm_support_data[realm.id].file_upload_usage }}<br />
 | 
			
		||||
</div>
 | 
			
		||||
<div>
 | 
			
		||||
    <div class="realm-management-actions">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user