1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-26 05:50:29 +01:00

Fix issue with Bitwarden CLI.

The CLI seems to send a String instead of an Integer for the maximum access count.
It now accepts both types and converts it to an i32 in all cases.

Fixes #2196
Dieser Commit ist enthalten in:
BlackDex 2021-12-31 15:59:58 +01:00
Ursprung 920371929b
Commit bf5aefd129
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 58C80A2AA6C765E1

Datei anzeigen

@ -7,7 +7,7 @@ use rocket_contrib::json::Json;
use serde_json::Value; use serde_json::Value;
use crate::{ use crate::{
api::{ApiResult, EmptyResult, JsonResult, JsonUpcase, Notify, UpdateType}, api::{ApiResult, EmptyResult, JsonResult, JsonUpcase, Notify, NumberOrString, UpdateType},
auth::{Headers, Host}, auth::{Headers, Host},
db::{models::*, DbConn, DbPool}, db::{models::*, DbConn, DbPool},
util::SafeString, util::SafeString,
@ -42,21 +42,21 @@ pub fn purge_sends(pool: DbPool) {
#[derive(Deserialize)] #[derive(Deserialize)]
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub struct SendData { struct SendData {
pub Type: i32, Type: i32,
pub Key: String, Key: String,
pub Password: Option<String>, Password: Option<String>,
pub MaxAccessCount: Option<i32>, MaxAccessCount: Option<NumberOrString>,
pub ExpirationDate: Option<DateTime<Utc>>, ExpirationDate: Option<DateTime<Utc>>,
pub DeletionDate: DateTime<Utc>, DeletionDate: DateTime<Utc>,
pub Disabled: bool, Disabled: bool,
pub HideEmail: Option<bool>, HideEmail: Option<bool>,
// Data field // Data field
pub Name: String, Name: String,
pub Notes: Option<String>, Notes: Option<String>,
pub Text: Option<Value>, Text: Option<Value>,
pub File: Option<Value>, File: Option<Value>,
} }
/// Enforces the `Disable Send` policy. A non-owner/admin user belonging to /// Enforces the `Disable Send` policy. A non-owner/admin user belonging to
@ -119,7 +119,10 @@ fn create_send(data: SendData, user_uuid: String) -> ApiResult<Send> {
let mut send = Send::new(data.Type, data.Name, data_str, data.Key, data.DeletionDate.naive_utc()); let mut send = Send::new(data.Type, data.Name, data_str, data.Key, data.DeletionDate.naive_utc());
send.user_uuid = Some(user_uuid); send.user_uuid = Some(user_uuid);
send.notes = data.Notes; send.notes = data.Notes;
send.max_access_count = data.MaxAccessCount; send.max_access_count = match data.MaxAccessCount {
Some(m) => Some(m.into_i32()?),
_ => None,
};
send.expiration_date = data.ExpirationDate.map(|d| d.naive_utc()); send.expiration_date = data.ExpirationDate.map(|d| d.naive_utc());
send.disabled = data.Disabled; send.disabled = data.Disabled;
send.hide_email = data.HideEmail; send.hide_email = data.HideEmail;
@ -414,7 +417,10 @@ fn put_send(id: String, data: JsonUpcase<SendData>, headers: Headers, conn: DbCo
send.akey = data.Key; send.akey = data.Key;
send.deletion_date = data.DeletionDate.naive_utc(); send.deletion_date = data.DeletionDate.naive_utc();
send.notes = data.Notes; send.notes = data.Notes;
send.max_access_count = data.MaxAccessCount; send.max_access_count = match data.MaxAccessCount {
Some(m) => Some(m.into_i32()?),
_ => None,
};
send.expiration_date = data.ExpirationDate.map(|d| d.naive_utc()); send.expiration_date = data.ExpirationDate.map(|d| d.naive_utc());
send.hide_email = data.HideEmail; send.hide_email = data.HideEmail;
send.disabled = data.Disabled; send.disabled = data.Disabled;