Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[rust][space] Remove profile covers and avatars

r4khul647c730837a7
diff --git a/rust/bindings/wasm/space/src/space.rs b/rust/bindings/wasm/space/src/space.rs
index 8ec20fabd6..35e173beff 100644
--- a/rust/bindings/wasm/space/src/space.rs
+++ b/rust/bindings/wasm/space/src/space.rs
@@ -951,6 +951,36 @@ impl SpaceAccountCtxHandle {
.map_err(Into::into)
}
+ #[wasm_bindgen(js_name = removeSpaceProfileCover)]
+ pub async fn remove_space_profile_cover(
+ &self,
+ space_id: String,
+ profile: String,
+ ) -> Result<<UpdateSpaceProfileResponse as Tsify>::JsType, Error> {
+ UpdateSpaceProfileResponse::from(
+ self.inner
+ .remove_space_profile_cover(&space_id, profile.as_bytes())
+ .await?,
+ )
+ .into_js()
+ .map_err(Into::into)
+ }
+
+ #[wasm_bindgen(js_name = removeSpaceProfileAvatar)]
+ pub async fn remove_space_profile_avatar(
+ &self,
+ space_id: String,
+ profile: String,
+ ) -> Result<<UpdateSpaceProfileResponse as Tsify>::JsType, Error> {
+ UpdateSpaceProfileResponse::from(
+ self.inner
+ .remove_space_profile_avatar(&space_id, profile.as_bytes())
+ .await?,
+ )
+ .into_js()
+ .map_err(Into::into)
+ }
+
#[wasm_bindgen(js_name = updateSpaceSlug)]
pub async fn update_space_slug(
&self,
diff --git a/rust/crates/space/src/client/profiles.rs b/rust/crates/space/src/client/profiles.rs
index 2aec1d38f0..29f55b8a9f 100644
--- a/rust/crates/space/src/client/profiles.rs
+++ b/rust/crates/space/src/client/profiles.rs
@@ -142,6 +142,24 @@ impl AccountSpaceCtx {
.await
}
+ pub async fn remove_space_profile_cover(
+ &self,
+ space_id: &str,
+ profile: &[u8],
+ ) -> Result<UpdateSpaceProfileResponse> {
+ self.update_space_profile_assets(space_id, profile, None, None, false, true)
+ .await
+ }
+
+ pub async fn remove_space_profile_avatar(
+ &self,
+ space_id: &str,
+ profile: &[u8],
+ ) -> Result<UpdateSpaceProfileResponse> {
+ self.update_space_profile(space_id, profile, None, true)
+ .await
+ }
+
pub async fn update_space_profile_assets(
&self,
space_id: &str,
diff --git a/rust/crates/space/src/client/tests.rs b/rust/crates/space/src/client/tests.rs
index 0b2f287a01..5245de86cd 100644
--- a/rust/crates/space/src/client/tests.rs
+++ b/rust/crates/space/src/client/tests.rs
@@ -1341,6 +1341,55 @@ async fn update_space_profile_sends_encrypted_profile_and_profile_assets() {
update.assert_async().await;
}
+#[tokio::test]
+async fn removing_profile_images_sets_only_the_requested_asset_flag() {
+ let mut server = Server::new_async().await;
+ let space_root_key = generate_key();
+ let ctx = test_account_ctx_with_space_root_key(&server.url(), space_root_key.clone());
+ let space_key = generate_key();
+ let spaces = server
+ .mock("GET", "/account/space")
+ .with_status(200)
+ .with_body(owned_space_response(
+ &space_root_key,
+ &space_key,
+ "space_owner_main",
+ "owner-main",
+ 3,
+ ))
+ .create_async()
+ .await;
+ let cover = server
+ .mock("POST", "/spaces/space_owner_main/profile")
+ .match_body(Matcher::Regex(
+ r#"^\{"keyVersion":3,"encryptedProfile":"[^"]+","removeCover":true\}$"#.into(),
+ ))
+ .with_status(200)
+ .with_body(r#"{"status":"updated"}"#)
+ .create_async()
+ .await;
+ let avatar = server
+ .mock("POST", "/spaces/space_owner_main/profile")
+ .match_body(Matcher::Regex(
+ r#"^\{"keyVersion":3,"encryptedProfile":"[^"]+","removeAvatar":true\}$"#.into(),
+ ))
+ .with_status(200)
+ .with_body(r#"{"status":"updated"}"#)
+ .create_async()
+ .await;
+
+ ctx.remove_space_profile_cover("space_owner_main", b"profile-v2")
+ .await
+ .expect("cover removal should succeed");
+ ctx.remove_space_profile_avatar("space_owner_main", b"profile-v2")
+ .await
+ .expect("avatar removal should succeed");
+
+ spaces.assert_async().await;
+ cover.assert_async().await;
+ avatar.assert_async().await;
+}
+
#[tokio::test]
async fn get_space_profile_decrypted_loads_and_decrypts_profile() {
let mut server = Server::new_async().await;