mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-09-10 02:35:58 +03:00
* WIP Sync with Upstream WIP on syncing API Responses with upstream. This to prevent issues with new clients, and find possible current issues like members, collections, groups etc.. Signed-off-by: BlackDex <black.dex@gmail.com> * More API Response fixes - Some 2fa checks - Some org checks - Reconfigured the experimental flags and noted which are deprecated Also removed some hard-coded defaults. - Updated crates Signed-off-by: BlackDex <black.dex@gmail.com> * Add avatar color to emergency access api Signed-off-by: BlackDex <black.dex@gmail.com> * Fix spelling and some crate updates Signed-off-by: BlackDex <black.dex@gmail.com> * Use PushId and always generate the PushId Signed-off-by: BlackDex <black.dex@gmail.com> * Fix clippy lints Signed-off-by: BlackDex <black.dex@gmail.com> * Fix several Push issues and API's Signed-off-by: BlackDex <black.dex@gmail.com> * Check if push_uuid is empty and generate when needed Signed-off-by: BlackDex <black.dex@gmail.com> * Updated some comments and removed old export format Signed-off-by: BlackDex <black.dex@gmail.com> * cargo update Signed-off-by: BlackDex <black.dex@gmail.com> * Fix bulk edit Fixes #5737 Signed-off-by: BlackDex <black.dex@gmail.com> * Send an email when an account exists already When you want to change your email address into an account which already exists, upstream sends an email to the existing account. Lets do the same. Kinda fixes #5630 Signed-off-by: BlackDex <black.dex@gmail.com> * Update 2fa removal/revoke email Signed-off-by: BlackDex <black.dex@gmail.com> * Allow col managers to import This commit adds functionality to allow users with manage access to a collection, or managers with all access to import into an organization. Fixes #5592 Signed-off-by: BlackDex <black.dex@gmail.com> * Filter deprected flags and only return active flags Signed-off-by: BlackDex <black.dex@gmail.com> * Fix grammer Signed-off-by: BlackDex <black.dex@gmail.com> * Rename Small to Compact Signed-off-by: BlackDex <black.dex@gmail.com> * Rebase with upstream and fix conflicts Signed-off-by: BlackDex <black.dex@gmail.com> --------- Signed-off-by: BlackDex <black.dex@gmail.com>
103 lines
3.2 KiB
Rust
103 lines
3.2 KiB
Rust
use rocket::serde::json::Json;
|
|
use serde_json::Value;
|
|
|
|
use crate::{
|
|
api::{EmptyResult, JsonResult, Notify, UpdateType},
|
|
auth::Headers,
|
|
db::{models::*, DbConn},
|
|
};
|
|
|
|
pub fn routes() -> Vec<rocket::Route> {
|
|
routes![get_folders, get_folder, post_folders, post_folder, put_folder, delete_folder_post, delete_folder,]
|
|
}
|
|
|
|
#[get("/folders")]
|
|
async fn get_folders(headers: Headers, mut conn: DbConn) -> Json<Value> {
|
|
let folders = Folder::find_by_user(&headers.user.uuid, &mut conn).await;
|
|
let folders_json: Vec<Value> = folders.iter().map(Folder::to_json).collect();
|
|
|
|
Json(json!({
|
|
"data": folders_json,
|
|
"object": "list",
|
|
"continuationToken": null,
|
|
}))
|
|
}
|
|
|
|
#[get("/folders/<folder_id>")]
|
|
async fn get_folder(folder_id: FolderId, headers: Headers, mut conn: DbConn) -> JsonResult {
|
|
match Folder::find_by_uuid_and_user(&folder_id, &headers.user.uuid, &mut conn).await {
|
|
Some(folder) => Ok(Json(folder.to_json())),
|
|
_ => err!("Invalid folder", "Folder does not exist or belongs to another user"),
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct FolderData {
|
|
pub name: String,
|
|
pub id: Option<FolderId>,
|
|
}
|
|
|
|
#[post("/folders", data = "<data>")]
|
|
async fn post_folders(data: Json<FolderData>, headers: Headers, mut conn: DbConn, nt: Notify<'_>) -> JsonResult {
|
|
let data: FolderData = data.into_inner();
|
|
|
|
let mut folder = Folder::new(headers.user.uuid, data.name);
|
|
|
|
folder.save(&mut conn).await?;
|
|
nt.send_folder_update(UpdateType::SyncFolderCreate, &folder, &headers.device, &mut conn).await;
|
|
|
|
Ok(Json(folder.to_json()))
|
|
}
|
|
|
|
#[post("/folders/<folder_id>", data = "<data>")]
|
|
async fn post_folder(
|
|
folder_id: FolderId,
|
|
data: Json<FolderData>,
|
|
headers: Headers,
|
|
conn: DbConn,
|
|
nt: Notify<'_>,
|
|
) -> JsonResult {
|
|
put_folder(folder_id, data, headers, conn, nt).await
|
|
}
|
|
|
|
#[put("/folders/<folder_id>", data = "<data>")]
|
|
async fn put_folder(
|
|
folder_id: FolderId,
|
|
data: Json<FolderData>,
|
|
headers: Headers,
|
|
mut conn: DbConn,
|
|
nt: Notify<'_>,
|
|
) -> JsonResult {
|
|
let data: FolderData = data.into_inner();
|
|
|
|
let Some(mut folder) = Folder::find_by_uuid_and_user(&folder_id, &headers.user.uuid, &mut conn).await else {
|
|
err!("Invalid folder", "Folder does not exist or belongs to another user")
|
|
};
|
|
|
|
folder.name = data.name;
|
|
|
|
folder.save(&mut conn).await?;
|
|
nt.send_folder_update(UpdateType::SyncFolderUpdate, &folder, &headers.device, &mut conn).await;
|
|
|
|
Ok(Json(folder.to_json()))
|
|
}
|
|
|
|
#[post("/folders/<folder_id>/delete")]
|
|
async fn delete_folder_post(folder_id: FolderId, headers: Headers, conn: DbConn, nt: Notify<'_>) -> EmptyResult {
|
|
delete_folder(folder_id, headers, conn, nt).await
|
|
}
|
|
|
|
#[delete("/folders/<folder_id>")]
|
|
async fn delete_folder(folder_id: FolderId, headers: Headers, mut conn: DbConn, nt: Notify<'_>) -> EmptyResult {
|
|
let Some(folder) = Folder::find_by_uuid_and_user(&folder_id, &headers.user.uuid, &mut conn).await else {
|
|
err!("Invalid folder", "Folder does not exist or belongs to another user")
|
|
};
|
|
|
|
// Delete the actual folder entry
|
|
folder.delete(&mut conn).await?;
|
|
|
|
nt.send_folder_update(UpdateType::SyncFolderDelete, &folder, &headers.device, &mut conn).await;
|
|
Ok(())
|
|
}
|