From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager v5 03/26] server: api: implement CRUD api for views
Date: Wed, 26 Nov 2025 16:17:56 +0100 [thread overview]
Message-ID: <20251126151833.3637080-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251126151833.3637080-1-d.csapak@proxmox.com>
namely list/read/update/delete api calls in `/config/views` api
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v4:
* adapt to lukas changes: add include-all (also to DeletableProperty)
server/src/api/config/mod.rs | 2 +
server/src/api/config/views.rs | 263 +++++++++++++++++++++++++++++++++
2 files changed, 265 insertions(+)
create mode 100644 server/src/api/config/views.rs
diff --git a/server/src/api/config/mod.rs b/server/src/api/config/mod.rs
index 7b58c756..8f646c15 100644
--- a/server/src/api/config/mod.rs
+++ b/server/src/api/config/mod.rs
@@ -6,6 +6,7 @@ pub mod access;
pub mod acme;
pub mod certificate;
pub mod notes;
+pub mod views;
#[sortable]
const SUBDIRS: SubdirMap = &sorted!([
@@ -13,6 +14,7 @@ const SUBDIRS: SubdirMap = &sorted!([
("acme", &acme::ROUTER),
("certificate", &certificate::ROUTER),
("notes", ¬es::ROUTER),
+ ("views", &views::ROUTER)
]);
pub const ROUTER: Router = Router::new()
diff --git a/server/src/api/config/views.rs b/server/src/api/config/views.rs
new file mode 100644
index 00000000..1401a0a0
--- /dev/null
+++ b/server/src/api/config/views.rs
@@ -0,0 +1,263 @@
+use anyhow::Error;
+use serde::{Deserialize, Serialize};
+
+use proxmox_access_control::CachedUserInfo;
+use proxmox_config_digest::ConfigDigest;
+use proxmox_router::{http_bail, http_err, Permission, Router, RpcEnvironment};
+use proxmox_schema::{api, param_bail};
+
+use pdm_api_types::{
+ views::{ViewConfig, ViewConfigEntry, ViewConfigUpdater},
+ PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MODIFY,
+};
+
+const VIEW_ROUTER: Router = Router::new()
+ .put(&API_METHOD_UPDATE_VIEW)
+ .delete(&API_METHOD_REMOVE_VIEW)
+ .get(&API_METHOD_READ_VIEW);
+
+pub const ROUTER: Router = Router::new()
+ .get(&API_METHOD_GET_VIEWS)
+ .post(&API_METHOD_ADD_VIEW)
+ .match_all("id", &VIEW_ROUTER);
+
+#[api(
+ protected: true,
+ access: {
+ permission: &Permission::Anybody,
+ description: "Returns the views the user has access to.",
+ },
+ returns: {
+ description: "List of views.",
+ type: Array,
+ items: {
+ type: String,
+ description: "The name of a view."
+ },
+ },
+)]
+/// List views.
+pub fn get_views(rpcenv: &mut dyn RpcEnvironment) -> Result<Vec<ViewConfig>, Error> {
+ let (config, _) = pdm_config::views::config()?;
+
+ let user_info = CachedUserInfo::new()?;
+ let auth_id = rpcenv.get_auth_id().unwrap().parse()?;
+ let top_level_allowed = user_info
+ .check_privs(&auth_id, &["view"], PRIV_RESOURCE_AUDIT, false)
+ .is_ok();
+
+ let views: Vec<ViewConfig> = config
+ .into_iter()
+ .filter_map(|(view, value)| {
+ if !top_level_allowed
+ && user_info
+ .check_privs(&auth_id, &["view", &view], PRIV_RESOURCE_AUDIT, false)
+ .is_err()
+ {
+ return None;
+ };
+ match value {
+ ViewConfigEntry::View(conf) => Some(conf),
+ }
+ })
+ .collect();
+
+ Ok(views)
+}
+
+#[api(
+ protected: true,
+ input: {
+ properties: {
+ view: {
+ flatten: true,
+ type: ViewConfig,
+ },
+ digest: {
+ type: ConfigDigest,
+ optional: true,
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Privilege(&["view"], PRIV_RESOURCE_MODIFY, false),
+ },
+)]
+/// Add new view.
+pub fn add_view(view: ViewConfig, digest: Option<ConfigDigest>) -> Result<(), Error> {
+ let _lock = pdm_config::views::lock_config()?;
+
+ let (mut config, config_digest) = pdm_config::views::config()?;
+
+ config_digest.detect_modification(digest.as_ref())?;
+
+ let id = view.id.clone();
+
+ if let Some(ViewConfigEntry::View(_)) = config.insert(id.clone(), ViewConfigEntry::View(view)) {
+ param_bail!("id", "view '{}' already exists.", id)
+ }
+
+ pdm_config::views::save_config(&config)?;
+
+ Ok(())
+}
+
+#[api()]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "kebab-case")]
+/// Deletable property name
+pub enum DeletableProperty {
+ /// Delete the include filters.
+ Include,
+ /// Delete the exclude filters.
+ Exclude,
+ /// Delete the layout.
+ Layout,
+ /// Delete include-all flag
+ IncludeAll,
+}
+
+#[api(
+ protected: true,
+ input: {
+ properties: {
+ id: {
+ type: String,
+ description: "",
+ },
+ view: {
+ flatten: true,
+ type: ViewConfigUpdater,
+ },
+ delete: {
+ description: "List of properties to delete.",
+ type: Array,
+ optional: true,
+ items: {
+ type: DeletableProperty,
+ }
+ },
+ digest: {
+ type: ConfigDigest,
+ optional: true,
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Privilege(&["view", "{id}"], PRIV_RESOURCE_MODIFY, false),
+ },
+)]
+/// Update View.
+pub fn update_view(
+ id: String,
+ view: ViewConfigUpdater,
+ delete: Option<Vec<DeletableProperty>>,
+ digest: Option<ConfigDigest>,
+) -> Result<(), Error> {
+ let _lock = pdm_config::views::lock_config()?;
+
+ let (mut config, config_digest) = pdm_config::views::config()?;
+
+ config_digest.detect_modification(digest.as_ref())?;
+
+ let entry = config
+ .get_mut(&id)
+ .ok_or_else(|| http_err!(NOT_FOUND, "no such remote {id}"))?;
+
+ let ViewConfigEntry::View(conf) = entry;
+
+ if let Some(delete) = delete {
+ for delete_prop in delete {
+ match delete_prop {
+ DeletableProperty::Include => conf.include = Vec::new(),
+ DeletableProperty::Exclude => conf.exclude = Vec::new(),
+ DeletableProperty::Layout => conf.layout = String::new(),
+ DeletableProperty::IncludeAll => conf.include_all = None,
+ }
+ }
+ }
+
+ if let Some(include) = view.include {
+ conf.include = include;
+ }
+
+ if let Some(exclude) = view.exclude {
+ conf.exclude = exclude;
+ }
+
+ if view.include_all.is_some() {
+ conf.include_all = view.include_all;
+ }
+
+ if let Some(layout) = view.layout {
+ conf.layout = layout;
+ }
+
+ pdm_config::views::save_config(&config)?;
+
+ Ok(())
+}
+
+#[api(
+ protected: true,
+ input: {
+ properties: {
+ id: {
+ type: String,
+ description: "",
+ },
+ digest: {
+ type: ConfigDigest,
+ optional: true,
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Privilege(&["view"], PRIV_RESOURCE_MODIFY, false),
+ },
+)]
+/// Delete the view with the given id.
+pub fn remove_view(id: String, digest: Option<ConfigDigest>) -> Result<(), Error> {
+ let _lock = pdm_config::views::lock_config()?;
+
+ let (mut config, config_digest) = pdm_config::views::config()?;
+
+ config_digest.detect_modification(digest.as_ref())?;
+
+ match config.remove(&id) {
+ Some(ViewConfigEntry::View(_)) => {}
+ None => http_bail!(NOT_FOUND, "view '{id}' does not exist."),
+ }
+
+ pdm_config::views::save_config(&config)?;
+
+ Ok(())
+}
+
+#[api(
+ input: {
+ properties: {
+ id: {
+ type: String,
+ description: "",
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Privilege(&["view", "{id}"], PRIV_RESOURCE_AUDIT, false),
+ },
+)]
+/// Get the config of a single view.
+pub fn read_view(id: String) -> Result<ViewConfig, Error> {
+ let (config, _) = pdm_config::views::config()?;
+
+ let view = config
+ .get(&id)
+ .ok_or_else(|| http_err!(NOT_FOUND, "no such view '{id}'"))?;
+
+ let view = match view {
+ ViewConfigEntry::View(view) => view.clone(),
+ };
+
+ Ok(view)
+}
--
2.47.3
_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel
next prev parent reply other threads:[~2025-11-26 15:18 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 15:17 [pdm-devel] [PATCH datacenter-manager v5 00/26] enable custom views on the UI Dominik Csapak
2025-11-26 15:17 ` [pdm-devel] [PATCH datacenter-manager v5 01/26] lib: pdm-config: views: add locking/saving methods Dominik Csapak
2025-11-26 15:17 ` [pdm-devel] [PATCH datacenter-manager v5 02/26] lib: api-types: add 'layout' property to ViewConfig Dominik Csapak
2025-11-26 15:17 ` Dominik Csapak [this message]
2025-11-26 15:17 ` [pdm-devel] [PATCH datacenter-manager v5 04/26] server: api: resources: add 'view' category to search syntax Dominik Csapak
2025-11-26 15:17 ` [pdm-devel] [PATCH datacenter-manager v5 05/26] ui: remote selector: allow forcing of value Dominik Csapak
2025-11-26 15:17 ` [pdm-devel] [PATCH datacenter-manager v5 06/26] ui: dashboard types: add missing 'default's to de-serialization Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 07/26] ui: dashboard: status row: add optional 'editing state' Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 08/26] ui: dashboard: prepare view for editing custom views Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 09/26] ui: views: implement view loading from api Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 10/26] ui: views: make 'view' name property optional Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 11/26] ui: views: add 'view' parameter to api calls Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 12/26] ui: views: save updated layout to backend Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 13/26] ui: add view list context Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 14/26] ui: configuration: add view CRUD panels Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 15/26] ui: main menu: add optional view_list property Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 16/26] ui: load view list on page init Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 17/26] lib/ui: move views types to pdm-api-types Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 18/26] server: api: views: check layout string for validity Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 19/26] ui: dashboard: add current view to search terms Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 20/26] ui: resource tree: fix loading logic Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 21/26] ui: resource tree: move error message into first column Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 22/26] ui: resource tree: use `ViewContext` to limit the api calls to a view Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 23/26] ui: resource tree: show guest tags Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 24/26] api-types/ui: add ResourceTree variant for WidgetType Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 25/26] ui: dashboard view: refactor widget rendering arguments into struct Dominik Csapak
2025-11-26 15:18 ` [pdm-devel] [PATCH datacenter-manager v5 26/26] ui: resource tree/view: reload tree in a view on refresh Dominik Csapak
2025-11-26 21:15 ` [pdm-devel] applied: [PATCH datacenter-manager v5 00/26] enable custom views on the UI Thomas Lamprecht
2025-11-26 21:17 ` [pdm-devel] " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251126151833.3637080-4-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.