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:
parent
fdc00811ce
commit
72be0eb189
|
@ -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()
|
||||
|
|
|
@ -96,9 +96,7 @@ impl CachedUserInfo {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CachedUserInfo {
|
||||
pub fn is_superuser(&self, userid: &Userid) -> bool {
|
||||
userid == "root@pam"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue