From 4ad1106166d4ef790695a4584de155d1709581dc Mon Sep 17 00:00:00 2001 From: Manuel Gugger Date: Sat, 21 Jan 2023 14:49:00 +0100 Subject: [PATCH] update docs --- .github/workflows/hugo.yml | 2 +- docs/content/docs/adding-crud-models.md | 17 +++++++++++++- docs/content/docs/authentication.md | 30 +++++++++++++++++++++++++ examples/azure_auth/main.rs | 6 ++--- examples/basic/main.rs | 9 ++++---- 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 docs/content/docs/authentication.md diff --git a/.github/workflows/hugo.yml b/.github/workflows/hugo.yml index a8af61c..960b3d4 100644 --- a/.github/workflows/hugo.yml +++ b/.github/workflows/hugo.yml @@ -30,7 +30,7 @@ jobs: build: runs-on: ubuntu-latest env: - HUGO_VERSION: 0.108.0 + HUGO_VERSION: 0.110.0 steps: - name: Install Hugo CLI run: | diff --git a/docs/content/docs/adding-crud-models.md b/docs/content/docs/adding-crud-models.md index 23803ac..c745b77 100644 --- a/docs/content/docs/adding-crud-models.md +++ b/docs/content/docs/adding-crud-models.md @@ -75,4 +75,19 @@ Views / Models can be grouped in the Navbar by using the following functions ins ```rust admin_builder.add_entity::(&comment_view_model); admin_builder.add_entity_to_category::(&comment_view_model, "Group 1"); -``` \ No newline at end of file +``` + +## Additional Model Attributes + +More attributes can be added to the model struct properties: +| | | | +|----|----|----| +| primary_key | required | defines which column is used for the primary key of the model | +| html_input_type= | optional | add the defined value such as *email* as input type to the html input field +| select_list | optional | Where a dropdown is rendered for the specific entity, needs to match the name of a struct or an enum | +| searchable | optional | Adds a search field to the table allowing to search the specific column | +| textarea | optional | renders a textarea instead of a text input field +| file_upload | optional | renders a file upload field, storing the filename in the column, column must be a string | +| not_empty | optional | disallow empty strings such as "" | +| list_sort_position= | optional | orders the column in the list view by ascending position | +| list_hide_column | optional | hides the column in the list view | \ No newline at end of file diff --git a/docs/content/docs/authentication.md b/docs/content/docs/authentication.md new file mode 100644 index 0000000..191b224 --- /dev/null +++ b/docs/content/docs/authentication.md @@ -0,0 +1,30 @@ +--- +title: "Authentication & Authorization" +date: 2023-01-17T11:44:56+01:00 +draft: false +weight: 4 +--- + +# Authentication & Authorization + +The admin interface can optionally enable authentication and authorization, altough the authorization logic needs to happen outside of the admin interface. + +An example for authenticating against Azure Active Directory can be found in the [examples](https://github.com/mgugger/actix-admin/tree/main/examples). + +## Enabling Authentication + +When creating the configuration, auth can be enabled as in the following code: + +```rust +let configuration = ActixAdminConfiguration { + enable_auth: true, + user_is_logged_in: Some(|session: &Session| -> bool { + let user_info = session.get::("user_info").unwrap(); + user_info.is_some() + }), + login_link: Some("/azure-auth/login".to_string()), + logout_link: Some("/azure-auth/logout".to_string()), +}; +``` + +The configuration expects a function taking a session parameter to return a bool whether the user is logged or not. Additionally, the login or logout links should be provided to redirect the user to the login url of choice. \ No newline at end of file diff --git a/examples/azure_auth/main.rs b/examples/azure_auth/main.rs index 4c15470..98aabdb 100644 --- a/examples/azure_auth/main.rs +++ b/examples/azure_auth/main.rs @@ -114,9 +114,9 @@ fn create_actix_admin_builder() -> ActixAdminBuilder { }; let mut admin_builder = ActixAdminBuilder::new(configuration); - // admin_builder.add_custom_handler_for_index::( - // web::get().to(custom_index::) - // ); + admin_builder.add_custom_handler_for_index::( + web::get().to(custom_index::) + ); admin_builder.add_entity::(&post_view_model); admin_builder.add_custom_handler("Custom Route in Menu", "/custom_route_in_menu", web::get().to(custom_index::), true); admin_builder.add_custom_handler("Custom Route not in Menu", "/custom_route_not_in_menu", web::get().to(custom_index::), false); diff --git a/examples/basic/main.rs b/examples/basic/main.rs index 37daa6c..1174f62 100644 --- a/examples/basic/main.rs +++ b/examples/basic/main.rs @@ -23,9 +23,6 @@ impl ActixAdminAppDataTrait for AppState { } fn create_actix_admin_builder() -> ActixAdminBuilder { - let post_view_model = ActixAdminViewModel::from(Post); - let comment_view_model = ActixAdminViewModel::from(Comment); - let configuration = ActixAdminConfiguration { enable_auth: false, user_is_logged_in: None, @@ -36,8 +33,12 @@ fn create_actix_admin_builder() -> ActixAdminBuilder { let mut admin_builder = ActixAdminBuilder::new(configuration); - let some_category = "Groupings"; + + let post_view_model = ActixAdminViewModel::from(Post); admin_builder.add_entity::(&post_view_model); + + let some_category = "Groupings"; + let comment_view_model = ActixAdminViewModel::from(Comment); admin_builder.add_entity_to_category::(&comment_view_model, some_category); admin_builder