mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-30 06:03:34 -05:00
update description api
This commit is contained in:
@@ -128,7 +128,7 @@ impl Resolve<GetUpdate, RequestUser> for State {
|
||||
return Ok(update);
|
||||
}
|
||||
match &update.target {
|
||||
ResourceTarget::System => {
|
||||
ResourceTarget::System(_) => {
|
||||
return Err(anyhow!("user must be admin to view system updates"))
|
||||
}
|
||||
ResourceTarget::Server(id) => {
|
||||
|
||||
57
bin/core/src/requests/write/description.rs
Normal file
57
bin/core/src/requests/write/description.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use anyhow::anyhow;
|
||||
use async_trait::async_trait;
|
||||
use monitor_types::{
|
||||
entities::{
|
||||
alerter::Alerter, build::Build, builder::Builder, deployment::Deployment, repo::Repo,
|
||||
server::Server, update::ResourceTarget,
|
||||
},
|
||||
requests::write::{UpdateDescription, UpdateDescriptionResponse},
|
||||
};
|
||||
use resolver_api::Resolve;
|
||||
|
||||
use crate::{auth::RequestUser, resource::Resource, state::State};
|
||||
|
||||
#[async_trait]
|
||||
impl Resolve<UpdateDescription, RequestUser> for State {
|
||||
async fn resolve(
|
||||
&self,
|
||||
UpdateDescription {
|
||||
target,
|
||||
description,
|
||||
}: UpdateDescription,
|
||||
user: RequestUser,
|
||||
) -> anyhow::Result<UpdateDescriptionResponse> {
|
||||
match target {
|
||||
ResourceTarget::System(_) => {
|
||||
return Err(anyhow!(
|
||||
"cannot update description of System resource target"
|
||||
))
|
||||
}
|
||||
ResourceTarget::Server(id) => {
|
||||
<State as Resource<Server>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
ResourceTarget::Deployment(id) => {
|
||||
<State as Resource<Deployment>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
ResourceTarget::Build(id) => {
|
||||
<State as Resource<Build>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
ResourceTarget::Repo(id) => {
|
||||
<State as Resource<Repo>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
ResourceTarget::Builder(id) => {
|
||||
<State as Resource<Builder>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
ResourceTarget::Alerter(id) => {
|
||||
<State as Resource<Alerter>>::update_description(self, &id, &description, &user)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Ok(UpdateDescriptionResponse {})
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ mod alerter;
|
||||
mod build;
|
||||
mod builder;
|
||||
mod deployment;
|
||||
mod description;
|
||||
mod permissions;
|
||||
mod repo;
|
||||
mod secret;
|
||||
@@ -44,6 +45,9 @@ enum WriteRequest {
|
||||
UpdateUserPerimissions(UpdateUserPermissions),
|
||||
UpdateUserPermissionsOnTarget(UpdateUserPermissionsOnTarget),
|
||||
|
||||
// ==== DESCRIPTION ====
|
||||
UpdateDescription(UpdateDescription),
|
||||
|
||||
// ==== SERVER ====
|
||||
CreateServer(CreateServer),
|
||||
DeleteServer(DeleteServer),
|
||||
|
||||
@@ -57,7 +57,7 @@ impl Resolve<UpdateUserPermissions, RequestUser> for State {
|
||||
.await?;
|
||||
let end_ts = monitor_timestamp();
|
||||
let mut update = Update {
|
||||
target: ResourceTarget::System,
|
||||
target: ResourceTarget::System("System".to_string()),
|
||||
operation: Operation::UpdateUserPermissions,
|
||||
logs: vec![Log::simple(
|
||||
"modify user enabled",
|
||||
@@ -111,7 +111,7 @@ impl Resolve<UpdateUserPermissionsOnTarget, RequestUser> for State {
|
||||
return Err(anyhow!("user not enabled"));
|
||||
}
|
||||
let log_text = match &target {
|
||||
ResourceTarget::System => return Err(anyhow!("target can not be system")),
|
||||
ResourceTarget::System(_) => return Err(anyhow!("target can not be system")),
|
||||
ResourceTarget::Build(id) => {
|
||||
let build = self
|
||||
.db
|
||||
|
||||
@@ -118,6 +118,20 @@ pub trait Resource<T: Indexed + Send + Unpin + Permissioned> {
|
||||
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
async fn update_description(
|
||||
&self,
|
||||
id: &str,
|
||||
description: &str,
|
||||
user: &RequestUser,
|
||||
) -> anyhow::Result<()> {
|
||||
self.get_resource_check_permissions(id, user, PermissionLevel::Update)
|
||||
.await?;
|
||||
self.coll()
|
||||
.update_one(id, mungos::Update::Set(doc! { "description": description }))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
@@ -194,7 +194,7 @@ impl State {
|
||||
ResourceTargetVariant::Alerter,
|
||||
)
|
||||
}
|
||||
ResourceTarget::System => {
|
||||
ResourceTarget::System(_) => {
|
||||
return Err(anyhow!("user not admin, can't recieve system updates"))
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user