]> git.proxmox.com Git - proxmox-backup.git/commitdiff
fix #2847: api: datastore: change backup owner
authorDylan Whyte <d.whyte@proxmox.com>
Tue, 13 Oct 2020 08:58:40 +0000 (10:58 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 14 Oct 2020 06:31:17 +0000 (08:31 +0200)
This adds an api method to change the owner of
a backup-group.

Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
src/api2/admin/datastore.rs
src/config/cached_user_info.rs

index c260b62da7721b002fc97fd125edb06bd5e16410..96faafee6ae129a287b4b99367104fad4409914f 100644 (file)
@@ -1492,6 +1492,51 @@ fn set_notes(
     Ok(())
 }
 
+#[api(
+   input: {
+        properties: {
+            store: {
+                schema: DATASTORE_SCHEMA,
+            },
+            "backup-type": {
+                schema: BACKUP_TYPE_SCHEMA,
+            },
+            "backup-id": {
+                schema: BACKUP_ID_SCHEMA,
+            },
+            "new-owner": {
+                type: Userid,
+            },
+        },
+   },
+   access: {
+       permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY, true),
+   },
+)]
+/// Change owner of a backup group
+fn set_backup_owner(
+    store: String,
+    backup_type: String,
+    backup_id: String,
+    new_owner: Userid,
+    rpcenv: &mut dyn RpcEnvironment,
+) -> Result<(), Error> {
+
+    let datastore = DataStore::lookup_datastore(&store)?;
+
+    let backup_group = BackupGroup::new(backup_type, backup_id);
+
+    let user_info = CachedUserInfo::new()?;
+
+    if !user_info.is_active_user(&new_owner) {
+        bail!("user '{}' is inactive or non-existent", new_owner);
+    }
+
+    datastore.set_owner(&backup_group, &new_owner, true)?;
+
+    Ok(())
+}
+
 #[sortable]
 const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
     (
@@ -1499,6 +1544,11 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
         &Router::new()
             .get(&API_METHOD_CATALOG)
     ),
+    (
+        "change-owner",
+        &Router::new()
+            .post(&API_METHOD_SET_BACKUP_OWNER)
+    ),
     (
         "download",
         &Router::new()
index 2140d9db55a7b1f088d1f880891b179b6cfe9e87..026c3e47dd7b936691a48d96292deb03f4144032 100644 (file)
@@ -96,9 +96,7 @@ impl CachedUserInfo {
         }
         Ok(())
     }
-}
 
-impl CachedUserInfo {
     pub fn is_superuser(&self, userid: &Userid) -> bool {
         userid == "root@pam"
     }