From 5e5ddabacf2e57e62bc975ad039bec691c815f12 Mon Sep 17 00:00:00 2001 From: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> Date: Fri, 19 Jul 2024 16:50:21 -0500 Subject: [PATCH] [SM-1338] Add the ability to edit unassigned secrets (#906) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🎟️ Tracking https://bitwarden.atlassian.net/browse/SM-1338 ## 📔 Objective With the introduction of individual secret permissions, it is possible for a machine account to have **read, write** permission on an unassigned secret. Editing this unassigned secret should be supported by `bws`. This removes the client side validation that restricted the edit of an unassigned secret. --- crates/bws/CHANGELOG.md | 4 ++++ crates/bws/src/command/secret.rs | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/bws/CHANGELOG.md b/crates/bws/CHANGELOG.md index 447f7cad6..695ab43df 100644 --- a/crates/bws/CHANGELOG.md +++ b/crates/bws/CHANGELOG.md @@ -7,6 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- The ability to edit unassigned secrets with direct permissions. (#906) + ### Removed - The deprecated `action type` commands are now removed. Please use `type action` instead. (#836) diff --git a/crates/bws/src/command/secret.rs b/crates/bws/src/command/secret.rs index 794a1a0b9..0f1aa3981 100644 --- a/crates/bws/src/command/secret.rs +++ b/crates/bws/src/command/secret.rs @@ -171,13 +171,10 @@ pub(crate) async fn edit( key: secret.key.unwrap_or(old_secret.key), value: secret.value.unwrap_or(old_secret.value), note: secret.note.unwrap_or(old_secret.note), - project_ids: match secret.project_id { - Some(id) => Some(vec![id]), - None => match old_secret.project_id { - Some(id) => Some(vec![id]), - None => bail!("Editing a secret requires a project_id."), - }, - }, + project_ids: secret + .project_id + .or(old_secret.project_id) + .map(|id| vec![id]), }) .await?; serialize_response(new_secret, output_settings);