Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
export_consent: Include users email visibility policy in the response.
PieterCKa584b977dbf3
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex fcd214b72c6..d63e2e5da7e 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -20,6 +20,12 @@ format used by the Zulip server that they are interacting with.## Changes in Zulip 12.0+**Feature level 430**++* [`GET /export/realm/consents`](/api/get-realm-export-consents): Added an+ integer field `email_address_visibility` to the objects in the+ `export_consents` array.+**Feature level 429*** Replaced the `pm_users` field with `recipient_user_ids` indiff --git a/version.py b/version.pyindex 6d4f62554a0..9adaade171e 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 = 429+API_FEATURE_LEVEL = 430# 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. Bumpdiff --git a/web/src/settings_exports.ts b/web/src/settings_exports.tsindex 6704f8afd43..53439e476e2 100644--- a/web/src/settings_exports.ts+++ b/web/src/settings_exports.ts@@ -30,6 +30,7 @@ import {user_settings} from "./user_settings.ts";export const export_consent_schema = z.object({user_id: z.number(),consented: z.boolean(),+ email_address_visibility: z.number(),});type ExportConsent = z.output<typeof export_consent_schema>;@@ -152,8 +153,11 @@ function sort_user_by_name(a: ExportConsent, b: ExportConsent): number {}return -1;}--const export_consents = new Map<number, boolean>();+type UserConsentInfo = {+ consented: boolean;+ email_address_visibility: number;+};+const export_consents = new Map<number, UserConsentInfo>();const queued_export_consents: (ExportConsent | number)[] = [];let export_consent_list_widget: ListWidgetType<ExportConsent>;let filter_by_consent_dropdown_widget: DropdownWidget;@@ -170,9 +174,15 @@ const filter_by_consent_options: Option[] = [function get_export_consents_having_consent_value(consent: boolean): ExportConsent[] {const export_consent_list: ExportConsent[] = [];- for (const [user_id, consented] of export_consents.entries()) {- if (consent === consented) {- export_consent_list.push({user_id, consented});+ for (const [user_id, user_consent_info] of export_consents.entries()) {+ const consented = user_consent_info.consented;+ const email_address_visibility = user_consent_info.email_address_visibility;+ if (consent === user_consent_info.consented) {+ export_consent_list.push({+ user_id,+ consented,+ email_address_visibility,+ });}}return export_consent_list;@@ -390,7 +400,10 @@ export function set_up(): void {.parse(raw_data);for (const export_consent of data.export_consents) {- export_consents.set(export_consent.user_id, export_consent.consented);+ export_consents.set(export_consent.user_id, {+ consented: export_consent.consented,+ email_address_visibility: export_consent.email_address_visibility,+ });}// Apply queued_export_consents on top of the received response.@@ -400,7 +413,10 @@ export function set_up(): void {export_consents.delete(item);continue;}- export_consents.set(item.user_id, item.consented);+ export_consents.set(item.user_id, {+ consented: item.consented,+ email_address_visibility: item.email_address_visibility,+ });}queued_export_consents.length = 0;@@ -503,7 +519,10 @@ export function update_export_consent_data_and_redraw(export_consent: ExportConsreturn;}- export_consents.set(export_consent.user_id, export_consent.consented);+ export_consents.set(export_consent.user_id, {+ consented: export_consent.consented,+ email_address_visibility: export_consent.email_address_visibility,+ });redraw_export_consents_list();update_start_export_modal_stats();}diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 4c60599c77a..7c22776ad11 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -15509,7 +15509,11 @@ paths:Fetches which users have [consented](/help/export-your-organization#configure-whether-administrators-can-export-your-private-data)for their private data to be exported by organization administrators.- **Changes**: New in Zulip 10.0 (feature level 295).+ **Changes**: Changes in Zulip 12.0 (feature level 430). Added an+ integer field `email_address_visibility` to the objects in the+ `export_consents` array.++ New in Zulip 10.0 (feature level 295).responses:"200":description: Success.@@ -15526,8 +15530,9 @@ paths:export_consents:type: arraydescription: |- An array of objects where each object contains a user ID and- whether the user has consented for their private data to be exported.+ An array of objects where each object contains a user ID, whether the+ user has consented for their private data to be exported, and their+ email visibility policy.items:type: objectadditionalProperties: false@@ -15540,12 +15545,22 @@ paths:description: |Whether the user has consented for their private data export.type: boolean+ email_address_visibility:+ $ref: "#/components/schemas/EmailAddressVisibility"example:{"export_consents":[- {"user_id": 11, "consented": true},- {"user_id": 6, "consented": false},+ {+ "user_id": 11,+ "consented": true,+ "email_address_visibility": 1,+ },+ {+ "user_id": 6,+ "consented": false,+ "email_address_visibility": 2,+ },],"msg": "","result": "success",diff --git a/zerver/tests/test_realm_export.py b/zerver/tests/test_realm_export.pyindex 70cc8220bfe..0b72ae4a58e 100644--- a/zerver/tests/test_realm_export.py+++ b/zerver/tests/test_realm_export.py@@ -340,10 +340,23 @@ class RealmExportTest(ZulipTestCase):do_change_user_setting(user, "allow_private_data_export", True, acting_user=None)# Verify export consents of users.+ aaron.role = UserProfile.ROLE_REALM_ADMINISTRATOR+ aaron.save()+ do_change_user_setting(+ aaron,+ "email_address_visibility",+ UserProfile.EMAIL_ADDRESS_VISIBILITY_NOBODY,+ acting_user=aaron,+ )result = self.client_get("/json/export/realm/consents")response_dict = self.assert_json_success(result)export_consents = response_dict["export_consents"]for export_consent in export_consents:+ if export_consent["user_id"] == aaron.id:+ self.assertEqual(+ export_consent["email_address_visibility"],+ UserProfile.EMAIL_ADDRESS_VISIBILITY_NOBODY,+ )if export_consent["user_id"] in [hamlet.id, aaron.id]:self.assertTrue(export_consent["consented"])continuediff --git a/zerver/views/realm_export.py b/zerver/views/realm_export.pyindex f8055b07711..718a9fdf499 100644--- a/zerver/views/realm_export.py+++ b/zerver/views/realm_export.py@@ -130,9 +130,16 @@ def delete_realm_export(request: HttpRequest, user: UserProfile, export_id: int)@require_realm_admindef get_users_export_consents(request: HttpRequest, user: UserProfile) -> HttpResponse:rows = UserProfile.objects.filter(realm=user.realm, is_active=True, is_bot=False).values(- "id", "allow_private_data_export"+ "id",+ "allow_private_data_export",+ "email_address_visibility",)export_consents = [- {"user_id": row["id"], "consented": row["allow_private_data_export"]} for row in rows+ {+ "user_id": row["id"],+ "consented": row["allow_private_data_export"],+ "email_address_visibility": row["email_address_visibility"],+ }+ for row in rows]return json_success(request, data={"export_consents": export_consents})