From f32791b4b2af83b0c6d3adde6de6ec7dc5a828df Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 14 May 2021 16:36:02 +0200 Subject: [PATCH] api2/admin/datastore: add delete for groups so that a user can delete a whole group at once, until now, the fastest way for this was to prune to one snapshot, and delete that code is basically a copy/paste from the snapshot delete, sans the 'backup-time' parameter Signed-off-by: Dominik Csapak --- src/api2/admin/datastore.rs | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 97860910..e0dfeecc 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -219,6 +219,48 @@ pub fn list_groups( Ok(group_info) } +#[api( + input: { + properties: { + store: { + schema: DATASTORE_SCHEMA, + }, + "backup-type": { + schema: BACKUP_TYPE_SCHEMA, + }, + "backup-id": { + schema: BACKUP_ID_SCHEMA, + }, + }, + }, + access: { + permission: &Permission::Privilege( + &["datastore", "{store}"], + PRIV_DATASTORE_MODIFY| PRIV_DATASTORE_PRUNE, + true), + }, +)] +/// Delete backup group including all snapshots. +pub fn delete_group( + store: String, + backup_type: String, + backup_id: String, + _info: &ApiMethod, + rpcenv: &mut dyn RpcEnvironment, +) -> Result { + + let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?; + + let group = BackupGroup::new(backup_type, backup_id); + let datastore = DataStore::lookup_datastore(&store)?; + + check_priv_or_backup_owner(&datastore, &group, &auth_id, PRIV_DATASTORE_MODIFY)?; + + datastore.remove_backup_group(&group)?; + + Ok(Value::Null) +} + #[api( input: { properties: { @@ -1722,6 +1764,7 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ "groups", &Router::new() .get(&API_METHOD_LIST_GROUPS) + .delete(&API_METHOD_DELETE_GROUP) ), ( "notes",