hidden columns from clients
This commit is contained in:
2
client
2
client
Submodule client updated: 7eaf34d09e...2e4b158935
@@ -58,6 +58,11 @@ service TableDefinition {
|
||||
// Physical column names and identities remain unchanged.
|
||||
rpc SetColumnPresentation(SetColumnPresentationRequest) returns (SetColumnPresentationResponse);
|
||||
|
||||
// Shows or hides one column in bundled data-entry forms. This is presentation
|
||||
// metadata only: hidden columns remain available to data APIs, scripts and
|
||||
// backend calculations.
|
||||
rpc SetColumnFormVisibility(SetColumnFormVisibilityRequest) returns (SetColumnFormVisibilityResponse);
|
||||
|
||||
// Drops a table and its metadata, then deletes the profile if it becomes empty.
|
||||
rpc DeleteTable(DeleteTableRequest) returns (DeleteTableResponse);
|
||||
}
|
||||
@@ -471,6 +476,10 @@ message ColumnBehavior {
|
||||
|
||||
// Stable public identity used when updating this column's presentation.
|
||||
int64 column_id = 5;
|
||||
|
||||
// True when bundled data-entry clients should not render this column.
|
||||
// This is not an authorization boundary; data APIs still expose the column.
|
||||
bool hidden_from_forms = 6;
|
||||
}
|
||||
|
||||
// A script that targets a specific column in a table.
|
||||
@@ -507,6 +516,24 @@ message SetColumnPresentationResponse {
|
||||
int64 row_version = 4;
|
||||
}
|
||||
|
||||
message SetColumnFormVisibilityRequest {
|
||||
string profile_name = 1;
|
||||
string table_name = 2;
|
||||
int64 column_id = 3;
|
||||
bool hidden_from_forms = 4;
|
||||
// Row version returned by GetProfileDetails when the column was read.
|
||||
int64 expected_row_version = 5;
|
||||
}
|
||||
|
||||
message SetColumnFormVisibilityResponse {
|
||||
bool success = 1;
|
||||
string message = 2;
|
||||
int64 column_id = 3;
|
||||
bool hidden_from_forms = 4;
|
||||
// New row version after the update.
|
||||
int64 row_version = 5;
|
||||
}
|
||||
|
||||
// Request to delete one table definition entirely.
|
||||
message DeleteTableRequest {
|
||||
// Profile (schema) name owning the table (must exist).
|
||||
|
||||
Binary file not shown.
@@ -495,6 +495,10 @@ pub struct ColumnBehavior {
|
||||
/// Stable public identity used when updating this column's presentation.
|
||||
#[prost(int64, tag = "5")]
|
||||
pub column_id: i64,
|
||||
/// True when bundled data-entry clients should not render this column.
|
||||
/// This is not an authorization boundary; data APIs still expose the column.
|
||||
#[prost(bool, tag = "6")]
|
||||
pub hidden_from_forms: bool,
|
||||
}
|
||||
/// A script that targets a specific column in a table.
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -549,6 +553,36 @@ pub struct SetColumnPresentationResponse {
|
||||
#[prost(int64, tag = "4")]
|
||||
pub row_version: i64,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
||||
pub struct SetColumnFormVisibilityRequest {
|
||||
#[prost(string, tag = "1")]
|
||||
pub profile_name: ::prost::alloc::string::String,
|
||||
#[prost(string, tag = "2")]
|
||||
pub table_name: ::prost::alloc::string::String,
|
||||
#[prost(int64, tag = "3")]
|
||||
pub column_id: i64,
|
||||
#[prost(bool, tag = "4")]
|
||||
pub hidden_from_forms: bool,
|
||||
/// Row version returned by GetProfileDetails when the column was read.
|
||||
#[prost(int64, tag = "5")]
|
||||
pub expected_row_version: i64,
|
||||
}
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
||||
pub struct SetColumnFormVisibilityResponse {
|
||||
#[prost(bool, tag = "1")]
|
||||
pub success: bool,
|
||||
#[prost(string, tag = "2")]
|
||||
pub message: ::prost::alloc::string::String,
|
||||
#[prost(int64, tag = "3")]
|
||||
pub column_id: i64,
|
||||
#[prost(bool, tag = "4")]
|
||||
pub hidden_from_forms: bool,
|
||||
/// New row version after the update.
|
||||
#[prost(int64, tag = "5")]
|
||||
pub row_version: i64,
|
||||
}
|
||||
/// Request to delete one table definition entirely.
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
||||
@@ -1227,6 +1261,38 @@ pub mod table_definition_client {
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
/// Shows or hides one column in bundled data-entry forms. This is presentation
|
||||
/// metadata only: hidden columns remain available to data APIs, scripts and
|
||||
/// backend calculations.
|
||||
pub async fn set_column_form_visibility(
|
||||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::SetColumnFormVisibilityRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::SetColumnFormVisibilityResponse>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tonic::Status::unknown(
|
||||
format!("Service was not ready: {}", e.into()),
|
||||
)
|
||||
})?;
|
||||
let codec = tonic_prost::ProstCodec::default();
|
||||
let path = http::uri::PathAndQuery::from_static(
|
||||
"/komp_ac.table_definition.TableDefinition/SetColumnFormVisibility",
|
||||
);
|
||||
let mut req = request.into_request();
|
||||
req.extensions_mut()
|
||||
.insert(
|
||||
GrpcMethod::new(
|
||||
"komp_ac.table_definition.TableDefinition",
|
||||
"SetColumnFormVisibility",
|
||||
),
|
||||
);
|
||||
self.inner.unary(req, path, codec).await
|
||||
}
|
||||
/// Drops a table and its metadata, then deletes the profile if it becomes empty.
|
||||
pub async fn delete_table(
|
||||
&mut self,
|
||||
@@ -1381,6 +1447,16 @@ pub mod table_definition_server {
|
||||
tonic::Response<super::SetColumnPresentationResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
/// Shows or hides one column in bundled data-entry forms. This is presentation
|
||||
/// metadata only: hidden columns remain available to data APIs, scripts and
|
||||
/// backend calculations.
|
||||
async fn set_column_form_visibility(
|
||||
&self,
|
||||
request: tonic::Request<super::SetColumnFormVisibilityRequest>,
|
||||
) -> std::result::Result<
|
||||
tonic::Response<super::SetColumnFormVisibilityResponse>,
|
||||
tonic::Status,
|
||||
>;
|
||||
/// Drops a table and its metadata, then deletes the profile if it becomes empty.
|
||||
async fn delete_table(
|
||||
&self,
|
||||
@@ -2052,6 +2128,57 @@ pub mod table_definition_server {
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_definition.TableDefinition/SetColumnFormVisibility" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct SetColumnFormVisibilitySvc<T: TableDefinition>(pub Arc<T>);
|
||||
impl<
|
||||
T: TableDefinition,
|
||||
> tonic::server::UnaryService<super::SetColumnFormVisibilityRequest>
|
||||
for SetColumnFormVisibilitySvc<T> {
|
||||
type Response = super::SetColumnFormVisibilityResponse;
|
||||
type Future = BoxFuture<
|
||||
tonic::Response<Self::Response>,
|
||||
tonic::Status,
|
||||
>;
|
||||
fn call(
|
||||
&mut self,
|
||||
request: tonic::Request<
|
||||
super::SetColumnFormVisibilityRequest,
|
||||
>,
|
||||
) -> Self::Future {
|
||||
let inner = Arc::clone(&self.0);
|
||||
let fut = async move {
|
||||
<T as TableDefinition>::set_column_form_visibility(
|
||||
&inner,
|
||||
request,
|
||||
)
|
||||
.await
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
let accept_compression_encodings = self.accept_compression_encodings;
|
||||
let send_compression_encodings = self.send_compression_encodings;
|
||||
let max_decoding_message_size = self.max_decoding_message_size;
|
||||
let max_encoding_message_size = self.max_encoding_message_size;
|
||||
let inner = self.inner.clone();
|
||||
let fut = async move {
|
||||
let method = SetColumnFormVisibilitySvc(inner);
|
||||
let codec = tonic_prost::ProstCodec::default();
|
||||
let mut grpc = tonic::server::Grpc::new(codec)
|
||||
.apply_compression_config(
|
||||
accept_compression_encodings,
|
||||
send_compression_encodings,
|
||||
)
|
||||
.apply_max_message_size_config(
|
||||
max_decoding_message_size,
|
||||
max_encoding_message_size,
|
||||
);
|
||||
let res = grpc.unary(method, req).await;
|
||||
Ok(res)
|
||||
};
|
||||
Box::pin(fut)
|
||||
}
|
||||
"/komp_ac.table_definition.TableDefinition/DeleteTable" => {
|
||||
#[allow(non_camel_case_types)]
|
||||
struct DeleteTableSvc<T: TableDefinition>(pub Arc<T>);
|
||||
|
||||
2
server
2
server
Submodule server updated: 2e9522fe25...9d960ff719
@@ -59,6 +59,7 @@ column-flag-half-up = zaokrouhleno nahoru
|
||||
column-flag-read-only = pouze pro čtení
|
||||
column-flag-generated = generovaný
|
||||
column-flag-generated-from = generováno z { $source }
|
||||
column-flag-hidden-from-forms = skrytý ve formulářích
|
||||
|
||||
# --- Přihlášení / registrace / změna hesla -----------------------------------
|
||||
login-title = Přihlášení
|
||||
@@ -189,6 +190,9 @@ td-columns-now = Současné sloupce
|
||||
td-col-column = Sloupec
|
||||
td-col-type = Typ
|
||||
td-col-notes = Poznámky
|
||||
td-form-visibility = Viditelnost ve formuláři
|
||||
td-hide-from-forms = Skrýt
|
||||
td-show-in-forms = Zobrazit
|
||||
td-scripts = Skripty
|
||||
td-col-target-column = Cílový sloupec
|
||||
td-col-description = Popis
|
||||
|
||||
@@ -64,6 +64,7 @@ column-flag-half-up = half-up
|
||||
column-flag-read-only = read only
|
||||
column-flag-generated = generated
|
||||
column-flag-generated-from = generated from { $source }
|
||||
column-flag-hidden-from-forms = hidden from forms
|
||||
|
||||
# --- Login / register / change password ------------------------------------
|
||||
login-title = Sign in
|
||||
@@ -193,6 +194,9 @@ td-columns-now = Columns it has now
|
||||
td-col-column = Column
|
||||
td-col-type = Type
|
||||
td-col-notes = Notes
|
||||
td-form-visibility = Form visibility
|
||||
td-hide-from-forms = Hide
|
||||
td-show-in-forms = Show
|
||||
td-scripts = Scripts
|
||||
td-col-target-column = Target column
|
||||
td-col-description = Description
|
||||
|
||||
@@ -59,6 +59,7 @@ column-flag-half-up = zaokrúhlené nahor
|
||||
column-flag-read-only = len na čítanie
|
||||
column-flag-generated = generovaný
|
||||
column-flag-generated-from = generovaný z { $source }
|
||||
column-flag-hidden-from-forms = skrytý vo formulároch
|
||||
|
||||
# --- Prihlásenie / registrácia / zmena hesla -------------------------------
|
||||
login-title = Prihlásenie
|
||||
@@ -189,6 +190,9 @@ td-columns-now = Súčasné stĺpce
|
||||
td-col-column = Stĺpec
|
||||
td-col-type = Typ
|
||||
td-col-notes = Poznámky
|
||||
td-form-visibility = Viditeľnosť vo formulári
|
||||
td-hide-from-forms = Skryť
|
||||
td-show-in-forms = Zobraziť
|
||||
td-scripts = Skripty
|
||||
td-col-target-column = Cieľový stĺpec
|
||||
td-col-description = Popis
|
||||
|
||||
@@ -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", ""),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -288,6 +288,7 @@ mod tests {
|
||||
read_only: false,
|
||||
generated_from: String::new(),
|
||||
renameable: true,
|
||||
hidden_from_forms: false,
|
||||
}],
|
||||
}),
|
||||
history: Vec::new(),
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<section class="panel">
|
||||
<h2>{{ nav.tr("td-columns-now") }} <span class="count">{{ detail.columns.len() }}</span></h2>
|
||||
<table class="builder-table">
|
||||
<thead><tr><th>{{ nav.tr("td-col-column") }}</th><th>{{ nav.tr("td-col-type") }}</th><th>{{ nav.tr("td-col-notes") }}</th></tr></thead>
|
||||
<thead><tr><th>{{ nav.tr("td-col-column") }}</th><th>{{ nav.tr("td-col-type") }}</th><th>{{ nav.tr("td-col-notes") }}</th><th>{{ nav.tr("td-form-visibility") }}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for column in detail.columns %}
|
||||
<tr>
|
||||
@@ -91,6 +91,21 @@
|
||||
<td>
|
||||
{%- for flag in column.flags(nav.locale) %}<span class="tag">{{ flag }}</span>{% endfor -%}
|
||||
</td>
|
||||
<td>
|
||||
{% if page.table_is_writable() %}
|
||||
<form hx-post="/admin/tables/presentation/visibility"
|
||||
hx-target="#table-panel" hx-swap="innerHTML">
|
||||
<input type="hidden" name="profile" value="{{ page.selection.profile }}">
|
||||
<input type="hidden" name="table" value="{{ page.selection.table }}">
|
||||
<input type="hidden" name="expected_row_version" value="{{ detail.row_version }}">
|
||||
<input type="hidden" name="column_id" value="{{ column.column_id }}">
|
||||
<input type="hidden" name="hidden_from_forms" value="{% if column.hidden_from_forms %}false{% else %}true{% endif %}">
|
||||
<button class="secondary" type="submit">
|
||||
{% if column.hidden_from_forms %}{{ nav.tr("td-show-in-forms") }}{% else %}{{ nav.tr("td-hide-from-forms") }}{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user