fix #2847: api: datastore: change backup owner

This adds an api method to change the owner of
a backup-group.

Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
This commit is contained in:
Dylan Whyte 2020-10-13 10:58:40 +02:00 committed by Dietmar Maurer
parent fdc00811ce
commit 72be0eb189
2 changed files with 50 additions and 2 deletions

View File

@ -1492,6 +1492,51 @@ fn set_notes(
Ok(()) 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] #[sortable]
const DATASTORE_INFO_SUBDIRS: SubdirMap = &[ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
( (
@ -1499,6 +1544,11 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&Router::new() &Router::new()
.get(&API_METHOD_CATALOG) .get(&API_METHOD_CATALOG)
), ),
(
"change-owner",
&Router::new()
.post(&API_METHOD_SET_BACKUP_OWNER)
),
( (
"download", "download",
&Router::new() &Router::new()

View File

@ -96,9 +96,7 @@ impl CachedUserInfo {
} }
Ok(()) Ok(())
} }
}
impl CachedUserInfo {
pub fn is_superuser(&self, userid: &Userid) -> bool { pub fn is_superuser(&self, userid: &Userid) -> bool {
userid == "root@pam" userid == "root@pam"
} }