hidden columns from clients

This commit is contained in:
Filipriec
2026-08-30 13:00:55 +02:00
parent cdb41c365a
commit 86efa82293
15 changed files with 263 additions and 6 deletions

View File

@@ -344,6 +344,7 @@ mod tests {
"/admin/tables/columns/add/builder",
"/admin/tables/presentation/alias",
"/admin/tables/presentation/order",
"/admin/tables/presentation/visibility",
"/admin/tables/delete",
"/admin/profiles/copy",
"/admin/tables/from-template",
@@ -481,6 +482,10 @@ mod tests {
"/admin/tables/presentation/order",
"profile=billing&table=invoice&column_ids=1&column_ids=2",
),
(
"/admin/tables/presentation/visibility",
"profile=billing&table=invoice&column_id=1&hidden_from_forms=true",
),
("/admin/tables/columns/add", "profile=billing&table=invoice"),
("/admin/tables/builder", ""),
("/admin/tables", ""),

View File

@@ -225,6 +225,8 @@ pub(crate) async fn load_page(
// incomplete server capability response does
// not grant permission by omission.
renameable: behavior.is_some_and(|behavior| behavior.renameable),
hidden_from_forms: behavior
.is_some_and(|behavior| behavior.hidden_from_forms),
}
})
.collect(),

View File

@@ -23,8 +23,8 @@ use crate::{
AppState,
definitions::table_definition::{
AddTableColumnsRequest, CopyProfileRequest, CreateInvoiceTemplateTableRequest,
ColumnPresentation, DeleteTableRequest, SetColumnPresentationRequest,
PutTableDefinitionRequest,
ColumnPresentation, DeleteTableRequest, PutTableDefinitionRequest,
SetColumnFormVisibilityRequest, SetColumnPresentationRequest,
},
{i18n::Locale, tr},
schema::{ColumnForm, proto_columns, validate_column_alias, validate_table_name},
@@ -35,7 +35,7 @@ use super::{
loader::{self, load_page},
state::{
AliasForm, CopyForm, DeleteForm, DetailColumn, GeneratedTableView, InvoiceTemplateForm,
LoadError, OrderForm, PageInputs, Selection, TableDefinitionPageState,
LoadError, OrderForm, PageInputs, Selection, TableDefinitionPageState, VisibilityForm,
},
ui,
};
@@ -551,6 +551,49 @@ pub(crate) async fn set_column_order(
.await
}
/// POST /admin/tables/presentation/visibility — show or hide one column in
/// bundled data-entry forms without changing its data-plane behavior.
pub(crate) async fn set_column_visibility(
State(state): State<AppState>,
headers: HeaderMap,
Form(form): Form<VisibilityForm>,
) -> Response {
if let Some(rejection) = reject_cross_site(&headers) {
return rejection;
}
let inputs = PageInputs::for_selection(Selection {
profile: form.profile.clone(),
table: form.table.clone(),
});
let request = SetColumnFormVisibilityRequest {
profile_name: form.profile,
table_name: form.table,
column_id: form.column_id,
hidden_from_forms: form.hidden_from_forms,
expected_row_version: form.expected_row_version,
};
let Ok(request) = authenticated_request(&headers, request) else {
return Redirect::to("/login").into_response();
};
let mut definitions = state.definitions.clone();
match definitions.set_column_form_visibility(request).await {
Ok(response) if response.get_ref().success => {
let mut inputs = inputs;
inputs.status = Some(response.into_inner().message);
respond(state, headers, inputs, Page::Presentation, StatusCode::OK).await
}
Ok(response) => {
let message = response.into_inner().message;
refuse(state, headers, inputs, Page::Presentation, message).await
}
Err(error) => {
refuse(state, headers, inputs, Page::Presentation, error.message().to_string()).await
}
}
}
/// The table's columns as the backend has them now, in their current order.
///
/// Both presentation writes have to send every column, and the ones they are

View File

@@ -50,6 +50,10 @@ pub(crate) fn router() -> Router<AppState> {
"/admin/tables/presentation/order",
post(logic::set_column_order),
)
.route(
"/admin/tables/presentation/visibility",
post(logic::set_column_visibility),
)
.route("/admin/tables/delete", get(logic::delete_page))
.route("/admin/tables/delete", post(logic::delete_table))
// Profile-scoped.

View File

@@ -159,6 +159,7 @@ pub(crate) struct DetailColumn {
pub read_only: bool,
pub generated_from: String,
pub renameable: bool,
pub hidden_from_forms: bool,
}
impl DetailColumn {
@@ -186,6 +187,9 @@ impl DetailColumn {
if self.read_only {
flags.push(crate::tr!(*locale, "column-flag-read-only"));
}
if self.hidden_from_forms {
flags.push(crate::tr!(*locale, "column-flag-hidden-from-forms"));
}
if !self.generated_from.is_empty() {
flags.push(crate::tr!(
*locale,
@@ -266,6 +270,20 @@ pub(crate) struct OrderForm {
pub column_ids: Vec<i64>,
}
#[derive(Clone, Debug, Default, serde::Deserialize)]
pub(crate) struct VisibilityForm {
#[serde(default)]
pub profile: String,
#[serde(default)]
pub table: String,
#[serde(default)]
pub expected_row_version: i64,
#[serde(default)]
pub column_id: i64,
#[serde(default)]
pub hidden_from_forms: bool,
}
/// The copy-profile panel. An empty `table_names` copies the whole profile,
/// which is what the backend takes an empty list to mean.
#[derive(Clone, Debug, Default, serde::Deserialize)]
@@ -515,6 +533,7 @@ mod tests {
read_only: false,
generated_from: String::new(),
renameable: true,
hidden_from_forms: false,
},
DetailColumn {
column_id: 2,
@@ -528,6 +547,7 @@ mod tests {
read_only: true,
generated_from: "work_phone".to_string(),
renameable: false,
hidden_from_forms: false,
},
DetailColumn {
column_id: 3,
@@ -541,6 +561,7 @@ mod tests {
read_only: false,
generated_from: "accounting".to_string(),
renameable: true,
hidden_from_forms: false,
},
],
};

View File

@@ -288,6 +288,7 @@ mod tests {
read_only: false,
generated_from: String::new(),
renameable: true,
hidden_from_forms: false,
}],
}),
history: Vec::new(),