From c7f72882a7e545600fe3d7f744b907c97f148c02 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 19 Apr 2024 22:42:01 +0200 Subject: [PATCH] Add raw API token rights editor --- .../src/controllers/server_controller.rs | 3 + virtweb_backend/src/main.rs | 2 +- virtweb_frontend/src/api/ServerApi.ts | 1 + .../src/widgets/forms/SelectInput.tsx | 4 +- .../src/widgets/tokens/APITokenDetails.tsx | 14 ++- .../src/widgets/tokens/RawRightsEditor.tsx | 111 ++++++++++++++++++ 6 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 virtweb_frontend/src/widgets/tokens/RawRightsEditor.tsx diff --git a/virtweb_backend/src/controllers/server_controller.rs b/virtweb_backend/src/controllers/server_controller.rs index 1e729ed..6a80039 100644 --- a/virtweb_backend/src/controllers/server_controller.rs +++ b/virtweb_backend/src/controllers/server_controller.rs @@ -53,6 +53,7 @@ struct ServerConstraints { nwfilter_selectors_count: LenConstraints, api_token_name_size: LenConstraints, api_token_description_size: LenConstraints, + api_token_right_path_size: LenConstraints, } pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder { @@ -110,6 +111,8 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder { min: constants::API_TOKEN_DESCRIPTION_MIN_LENGTH, max: constants::API_TOKEN_DESCRIPTION_MAX_LENGTH, }, + + api_token_right_path_size: LenConstraints { min: 0, max: 255 }, }, }) } diff --git a/virtweb_backend/src/main.rs b/virtweb_backend/src/main.rs index a968342..5e26b74 100644 --- a/virtweb_backend/src/main.rs +++ b/virtweb_backend/src/main.rs @@ -85,7 +85,7 @@ async fn main() -> std::io::Result<()> { let mut cors = Cors::default() .allowed_origin(&AppConfig::get().website_origin) - .allowed_methods(vec!["GET", "POST", "DELETE", "PUT"]) + .allowed_methods(vec!["GET", "POST", "DELETE", "PUT", "PATCH"]) .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT]) .allowed_header(header::CONTENT_TYPE) .supports_credentials() diff --git a/virtweb_frontend/src/api/ServerApi.ts b/virtweb_frontend/src/api/ServerApi.ts index 203d0a0..845fd77 100644 --- a/virtweb_frontend/src/api/ServerApi.ts +++ b/virtweb_frontend/src/api/ServerApi.ts @@ -29,6 +29,7 @@ export interface ServerConstraints { nwfilter_selectors_count: LenConstraint; api_token_name_size: LenConstraint; api_token_description_size: LenConstraint; + api_token_right_path_size: LenConstraint; } export interface LenConstraint { diff --git a/virtweb_frontend/src/widgets/forms/SelectInput.tsx b/virtweb_frontend/src/widgets/forms/SelectInput.tsx index 792a516..21ac0ae 100644 --- a/virtweb_frontend/src/widgets/forms/SelectInput.tsx +++ b/virtweb_frontend/src/widgets/forms/SelectInput.tsx @@ -16,7 +16,7 @@ export interface SelectOption { export function SelectInput(p: { value?: string; editable: boolean; - label: string; + label?: string; options: SelectOption[]; onValueChange: (o?: string) => void; }): React.ReactElement { @@ -29,7 +29,7 @@ export function SelectInput(p: { return ( - {p.label} + {p.label && {p.label}}