π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Require email addresses for admin account deletion
Manav Rathi16aad744290c
diff --git a/rust/apps/cli-next/src/admin.rs b/rust/apps/cli-next/src/admin.rsindex fcb2b72302..f8bc2245b4 100644--- a/rust/apps/cli-next/src/admin.rs+++ b/rust/apps/cli-next/src/admin.rs@@ -1,15 +1,12 @@use anyhow::{Context, Result, ensure};use chrono::{DateTime, Months, NaiveDate, NaiveTime, Utc};use dialoguer::{Confirm, Input, Select, console::Term};-use ente_accounts::{AccountsClient, admin::User};+use ente_accounts::AccountsClient;use serde_json::json;use crate::{api,- args::{- AdminCommand, AdminEmailCommand, AdminTarget, AdminUserCommand, App, Options,- SubscriptionArgs,- },+ args::{AdminCommand, AdminEmailCommand, AdminUserCommand, App, Options, SubscriptionArgs},output::{self, AdminUserView, SubscriptionView},vault::{Account, State},};@@ -22,10 +19,14 @@ pub async fn run() -> Result<()> {ensure!(!options.offline, "admin commands require network access");if let AdminCommand::User { command } = &command {- let target = match command {- AdminUserCommand::Delete(target)- | AdminUserCommand::DisableTotp(target)- | AdminUserCommand::RemovePasskeys(target) => Some(target),+ let yes = match command {+ AdminUserCommand::Delete { email, yes } => {+ ensure!(email.contains('@'), "supply an email address for deletion");+ Some(*yes)+ }+ AdminUserCommand::DisableTotp(target) | AdminUserCommand::RemovePasskeys(target) => {+ Some(target.yes)+ }AdminUserCommand::UpdateSubscription(args) => {ensure!(args.no_limit@@ -34,13 +35,13 @@ pub async fn run(|| options.can_prompt(),"supply --no-limit, --storage or --expires when running without interactive prompts");- Some(&args.target)+ Some(args.target.yes)}_ => None,};- if let Some(target) = target {+ if let Some(yes) = yes {ensure!(- target.yes || options.can_prompt(),+ yes || options.can_prompt(),"this change requires confirmation; supply --yes when running without interactive prompts");}@@ -100,11 +101,28 @@ async fn execute(AdminUserCommand::UpdateSubscription(args) => {update_subscription(client, account, args, options).await}+ AdminUserCommand::Delete { email, yes } => {+ let target = output::escape_controls(&email);+ confirm(+ "Delete the account currently registered to",+ &target,+ yes,+ account,+ )?;+ let result = client.admin_delete_user(&email).await?;+ output::action(+ options.json,+ &json!({"user": {"id": result.user_id.to_string(), "email": email},+ "deleted": true, "cleanupScheduled": true,+ "subscriptionCancelled": result.is_subscription_cancelled}),+ &format!(+ "{target} ({}): Account deleted; data cleanup scheduled. Subscription cancelled: {}.",+ result.user_id, result.is_subscription_cancelled+ ),+ )+ }command => {let (target, action) = match &command {- AdminUserCommand::Delete(target) => {- (target, "Delete account and schedule data cleanup for")- }AdminUserCommand::DisableTotp(target) => (target,"Disable authenticator-code two-factor authentication for",@@ -113,45 +131,27 @@ async fn execute(_ => unreachable!(),};let user = client.admin_user(&target.user).await?.user;- confirm(action, target, &user, account)?;+ let description = format!("{} ({})", output::escape_controls(&user.email), user.id);+ confirm(action, &description, target.yes, account)?;let view = AdminUserView::new(&user)?;let (value, message) = match command {- AdminUserCommand::Delete(_) => {- let result = client.admin_delete_user(&user.email).await?;- (- json!({"user": view, "deleted": true, "cleanupScheduled": true,- "subscriptionCancelled": result.is_subscription_cancelled}),- format!(- "Account deleted; data cleanup scheduled. Subscription cancelled: {}.",- result.is_subscription_cancelled- ),- )- }AdminUserCommand::DisableTotp(_) => {client.admin_disable_totp(user.id).await?;(json!({"user": view, "totpEnabled": false}),- "Authenticator-code two-factor authentication disabled.".into(),+ "Authenticator-code two-factor authentication disabled.",)}AdminUserCommand::RemovePasskeys(_) => {client.admin_remove_passkeys(user.id).await?;(json!({"user": view, "passkeysRemoved": true}),- "All passkeys removed.".into(),+ "All passkeys removed.",)}_ => unreachable!(),};- output::action(- options.json,- &value,- &format!(- "{} ({}): {message}",- output::escape_controls(&user.email),- user.id- ),- )+ output::action(options.json, &value, &format!("{description}: {message}"))}}}@@ -217,8 +217,12 @@ async fn update_subscription();confirm("Update subscription for",- &args.target,- &details.user,+ &format!(+ "{} ({})",+ output::escape_controls(&details.user.email),+ details.user.id+ ),+ args.target.yes,account,)?;client@@ -227,13 +231,11 @@ async fn update_subscription(output::admin_user(&details, options.json)}-fn confirm(action: &str, target: &AdminTarget, user: &User, account: &Account) -> Result<()> {- if !target.yes {+fn confirm(action: &str, target: &str, yes: bool, account: &Account) -> Result<()> {+ if !yes {let accepted = Confirm::new().with_prompt(format!(- "{action} {} ({}) on {} as {} ({})?",- output::escape_controls(&user.email),- user.id,+ "{action} {target} on {} as {} ({})?",account.origin,output::escape_controls(&account.email),account.user_iddiff --git a/rust/apps/cli-next/src/args.rs b/rust/apps/cli-next/src/args.rsindex 84b5078f7b..41b975ba80 100644--- a/rust/apps/cli-next/src/args.rs+++ b/rust/apps/cli-next/src/args.rs@@ -744,9 +744,15 @@ IDs are strings; timestamps are RFC3339; storageBytes is an integer."},#[command(about = "Delete an account and schedule its data cleanup",- after_long_help = "Requires a login less than ten minutes old. Reports whether the server cancelled the subscription."- )]- Delete(AdminTarget),+ after_long_help = "Deletes the account registered to the supplied email when the server processes the request.+Requires a login less than ten minutes old. Reports the deleted account's ID and whether the server cancelled the subscription."+ )]+ Delete {+ #[arg(help = "Email address of the account to delete")]+ email: String,+ #[arg(long, help = "Approve this change without prompting")]+ yes: bool,+ },#[command(about = "Disable authenticator-code two-factor authentication",after_long_help = "Requires a login less than ten minutes old. Leaves passkeys enabled."diff --git a/rust/apps/cli-next/tests/support/admin.rs b/rust/apps/cli-next/tests/support/admin.rsindex c295740555..f1109f99a5 100644--- a/rust/apps/cli-next/tests/support/admin.rs+++ b/rust/apps/cli-next/tests/support/admin.rs@@ -104,27 +104,34 @@ fn admin_list_and_app_selection() {}#[test]-fn admin_mutations_require_confirmation_and_use_resolved_target() {- for (command, method, path, response, field) in [- (- "delete",- "DELETE",- "/admin/user/delete",- json!({"isSubscriptionCancelled": false}),- "deleted",- ),- (- "disable-totp",- "POST",- "/admin/user/disable-2fa",- json!({}),- "totpEnabled",- ),+fn admin_deletion_uses_email_and_reports_deleted_id() {+ let mut server = Server::new();+ let home = TestHome::new();+ home.seed(&server.url());+ let delete = server+ .mock("DELETE", "/admin/user/delete")+ .match_query(Matcher::UrlEncoded("email".into(), EMAIL.into()))+ .with_body(json!({"userID": USER_ID, "isSubscriptionCancelled": false}).to_string())+ .expect(1)+ .create();+ let mut args = vec!["admin", "user", "delete", EMAIL, "--no-input"];+ assert!(failure(&home.run(&args)).contains("supply --yes"));+ args.push("--yes");+ assert_eq!(+ home.json(&args),+ json!({"user": {"id": USER_ID.to_string(), "email": EMAIL}, "deleted": true,+ "cleanupScheduled": true, "subscriptionCancelled": false})+ );+ delete.assert();+}++#[test]+fn admin_security_mutations_require_confirmation_and_use_resolved_target() {+ for (command, path, field) in [+ ("disable-totp", "/admin/user/disable-2fa", "totpEnabled"),("remove-passkeys",- "POST","/admin/user/disable-passkeys",- json!({}),"passkeysRemoved",),] {@@ -138,26 +145,18 @@ fn admin_mutations_require_confirmation_and_use_resolved_target() {.with_body(details().to_string()).expect(1).create();- let mut change = server- .mock(method, path)- .with_body(response.to_string())- .expect(1);- change = if method == "DELETE" {- change.match_query(Matcher::UrlEncoded("email".into(), EMAIL.into()))- } else {- change.match_body(Matcher::Json(json!({"userID": USER_ID})))- };- let change = change.create();+ let change = server+ .mock("POST", path)+ .match_body(Matcher::Json(json!({"userID": USER_ID})))+ .with_body("{}")+ .expect(1)+ .create();let mut args = vec!["admin", "user", command, &id, "--no-input"];assert!(failure(&home.run(&args)).contains("supply --yes"));args.push("--yes");let result = home.json(&args);assert_eq!(result["user"]["email"], EMAIL);assert_eq!(result[field], command != "disable-totp");- if command == "delete" {- assert_eq!(result["cleanupScheduled"], true);- assert_eq!(result["subscriptionCancelled"], false);- }get.assert();change.assert();}diff --git a/rust/apps/cli-next/tests/support/admin_museum.rs b/rust/apps/cli-next/tests/support/admin_museum.rsindex 3e51749d04..1294f35577 100644--- a/rust/apps/cli-next/tests/support/admin_museum.rs+++ b/rust/apps/cli-next/tests/support/admin_museum.rs@@ -146,7 +146,7 @@ fn admin_user_lifecycle() -> TestResult {);for command in ["delete", "disable-totp", "remove-passkeys"] {- let output = home.run(&["admin", "user", command, &id, "--no-input"]);+ let output = home.run(&["admin", "user", command, &email, "--no-input"]);assert!(failure(&output).contains("supply --yes"));assert!(output.stdout.is_empty());}@@ -223,7 +223,7 @@ fn admin_user_lifecycle() -> TestResult {))?;for args in [vec!["list"],- vec!["delete", &id, "--yes"],+ vec!["delete", &email, "--yes"],vec!["disable-totp", &id, "--yes"],] {let output =@@ -240,7 +240,9 @@ fn admin_user_lifecycle() -> TestResult {admin.user_id.to_string());login(&home, "photos", &admin_email, &["--host", origin, "--no-input"]);- let deleted = home.json(&["admin", "user", "delete", &id, "--yes", "--no-input"]);+ let deleted = home.json(&["admin", "user", "delete", &email, "--yes", "--no-input"]);+ assert_eq!(deleted["user"]["id"], id);+ assert_eq!(deleted["user"]["email"], email);assert_eq!(deleted["deleted"], true);assert_eq!(deleted["cleanupScheduled"], true);assert_eq!(deleted["subscriptionCancelled"], true);diff --git a/rust/crates/accounts/src/admin.rs b/rust/crates/accounts/src/admin.rsindex 848f4a6c0e..ab04fdb9eb 100644--- a/rust/crates/accounts/src/admin.rs+++ b/rust/crates/accounts/src/admin.rs@@ -34,6 +34,8 @@ pub struct Subscription {#[derive(Deserialize)]#[serde(rename_all = "camelCase")]pub struct Deletion {+ #[serde(rename = "userID")]+ pub user_id: i64,pub is_subscription_cancelled: bool,}