Skip to content

Commit 64f93e2

Browse files
feat: add distinct global actions and method actions
1 parent 2ca11a8 commit 64f93e2

File tree

59 files changed

+856
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+856
-825
lines changed

Cargo.lock

Lines changed: 129 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ axum = "0.8.1"
4040
bon = "3.3.2"
4141
chrono = "0.4.39"
4242
console_error_panic_hook = "0.1.2"
43-
dioxus = "0.7.0-rc.3"
44-
dioxus-html = "0.7.0-rc.3"
45-
dioxus-server = "0.7.0-rc.3"
46-
futures = "0.3.31"
43+
dioxus = "0.7.3"
44+
dioxus-html = "0.7.3"
45+
dioxus-server = "0.7.3"
4746
http = "1.2.0"
4847
jsonwebtoken = "10.3.0"
4948
leptos = "0.8.3"

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ wildcards = "deny"
1616
[licenses]
1717
allow = [
1818
"Apache-2.0",
19+
"BSD-2-Clause",
1920
"BSD-3-Clause",
2021
"BSL-1.0",
2122
"CC0-1.0",

examples/axum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ shield.workspace = true
1515
shield-axum = { workspace = true, features = ["utoipa"] }
1616
shield-email = { workspace = true, features = ["sender-tracing"] }
1717
shield-memory = { workspace = true, features = ["method-email", "method-oidc"] }
18-
shield-oidc = { workspace = true, features = ["native-tls"] }
18+
shield-oidc.workspace = true
1919
time = "0.3.47"
2020
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
2121
tower-sessions.workspace = true

examples/dioxus-axum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ shield-email = { workspace = true, features = [
3939
"sender-tracing",
4040
], optional = true }
4141
shield-memory = { workspace = true, optional = true }
42-
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
42+
shield-oidc = { workspace = true, optional = true }
4343
tokio = { workspace = true, features = [
4444
"macros",
4545
"rt-multi-thread",

examples/leptos-actix/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ shield-email = { workspace = true, features = [
5959
shield-leptos.workspace = true
6060
shield-leptos-actix = { workspace = true, optional = true }
6161
shield-memory = { workspace = true, optional = true }
62-
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
62+
shield-oidc = { workspace = true, optional = true }
6363
tracing.workspace = true
6464
tracing-subscriber.workspace = true
6565
wasm-bindgen.workspace = true

examples/leptos-axum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ shield-email = { workspace = true, features = [
5555
shield-leptos.workspace = true
5656
shield-leptos-axum = { workspace = true, optional = true }
5757
shield-memory = { workspace = true, optional = true }
58-
shield-oidc = { workspace = true, features = ["native-tls"], optional = true }
58+
shield-oidc = { workspace = true, optional = true }
5959
time = "0.3.47"
6060
tokio = { workspace = true, features = [
6161
"macros",

examples/sea-orm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ version.workspace = true
1212
[dependencies]
1313
sea-orm = { workspace = true, features = [
1414
"macros",
15-
"runtime-tokio-native-tls",
15+
"runtime-tokio-rustls",
1616
"sqlx-mysql",
1717
"sqlx-postgres",
1818
"sqlx-sqlite",
1919
] }
2020
sea-orm-migration = { workspace = true, features = [
21-
"runtime-tokio-native-tls",
21+
"runtime-tokio-rustls",
2222
"sqlx-mysql",
2323
"sqlx-postgres",
2424
"sqlx-sqlite",

packages/core/shield/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async-trait.workspace = true
1717
bon.workspace = true
1818
chrono = { workspace = true, features = ["serde"] }
1919
convert_case = "0.11.0"
20-
futures.workspace = true
20+
ordered_hash_map = "0.5.0"
2121
serde = { workspace = true, features = ["derive"] }
2222
serde_json.workspace = true
2323
thiserror.workspace = true

packages/core/shield/src/action.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,28 @@ use crate::{
44
error::ShieldError,
55
form::Form,
66
provider::Provider,
7-
request::Request,
7+
request::{Request, RequestMethod},
88
response::Response,
99
session::{BaseSession, MethodSession},
1010
};
1111
use async_trait::async_trait;
1212
use serde::{Deserialize, Serialize};
13-
#[cfg(feature = "utoipa")]
14-
use utoipa::openapi::HttpMethod;
15-
16-
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
17-
pub enum ActionMethod {
18-
Get,
19-
Post,
20-
Put,
21-
Delete,
22-
Options,
23-
Head,
24-
Patch,
25-
Trace,
26-
}
2713

28-
#[cfg(feature = "utoipa")]
29-
impl From<ActionMethod> for HttpMethod {
30-
fn from(value: ActionMethod) -> Self {
31-
match value {
32-
ActionMethod::Get => Self::Get,
33-
ActionMethod::Post => Self::Post,
34-
ActionMethod::Put => Self::Put,
35-
ActionMethod::Delete => Self::Delete,
36-
ActionMethod::Options => Self::Options,
37-
ActionMethod::Head => Self::Head,
38-
ActionMethod::Patch => Self::Patch,
39-
ActionMethod::Trace => Self::Trace,
40-
}
41-
}
14+
#[async_trait]
15+
pub trait Action: Send + Sync {
16+
fn id(&self) -> &'static str;
17+
18+
fn name(&self) -> &'static str;
19+
20+
fn openapi_summary(&self) -> &'static str;
21+
22+
fn openapi_description(&self) -> &'static str;
23+
24+
fn method(&self) -> RequestMethod;
25+
26+
async fn forms(&self) -> Result<Vec<Form>, ShieldError>;
27+
28+
async fn call(&self, session: &BaseSession, request: Request) -> Result<Response, ShieldError>;
4229
}
4330

4431
// TODO: Think of a better name.
@@ -48,6 +35,7 @@ impl From<ActionMethod> for HttpMethod {
4835
pub struct ActionForms {
4936
pub id: String,
5037
pub name: String,
38+
pub forms: Vec<Form>,
5139
pub method_forms: Vec<ActionMethodForm>,
5240
}
5341

@@ -70,7 +58,7 @@ pub struct ActionProviderForm {
7058
}
7159

7260
#[async_trait]
73-
pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
61+
pub trait MethodAction<P: Provider, S>: ErasedMethodAction + Send + Sync {
7462
fn id(&self) -> String;
7563

7664
fn name(&self) -> String;
@@ -79,7 +67,7 @@ pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
7967

8068
fn openapi_description(&self) -> &'static str;
8169

82-
fn method(&self) -> ActionMethod;
70+
fn method(&self) -> RequestMethod;
8371

8472
fn condition(&self, _provider: &P, _session: &MethodSession<S>) -> Result<bool, ShieldError> {
8573
Ok(true)
@@ -96,7 +84,7 @@ pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
9684
}
9785

9886
#[async_trait]
99-
pub trait ErasedAction: Send + Sync {
87+
pub trait ErasedMethodAction: Send + Sync {
10088
fn erased_id(&self) -> String;
10189

10290
fn erased_name(&self) -> String;
@@ -105,7 +93,7 @@ pub trait ErasedAction: Send + Sync {
10593

10694
fn erased_openapi_description(&self) -> &'static str;
10795

108-
fn erased_method(&self) -> ActionMethod;
96+
fn erased_method(&self) -> RequestMethod;
10997

11098
fn erased_condition(
11199
&self,
@@ -129,10 +117,10 @@ pub trait ErasedAction: Send + Sync {
129117
}
130118

131119
#[macro_export]
132-
macro_rules! erased_action {
120+
macro_rules! erased_method_action {
133121
($action:ident $(, < $( $generic_name:ident : $generic_type:ident ),+ > )*) => {
134122
#[async_trait]
135-
impl $( < $( $generic_name: $generic_type + 'static ),+ > )* $crate::ErasedAction for $action $( < $( $generic_name ),+ > )* {
123+
impl $( < $( $generic_name: $generic_type + 'static ),+ > )* $crate::ErasedMethodAction for $action $( < $( $generic_name ),+ > )* {
136124
fn erased_id(&self) -> String {
137125
self.id()
138126
}
@@ -149,7 +137,7 @@ macro_rules! erased_action {
149137
self.openapi_description()
150138
}
151139

152-
fn erased_method(&self) -> $crate::ActionMethod {
140+
fn erased_method(&self) -> $crate::RequestMethod {
153141
self.method()
154142
}
155143

0 commit comments

Comments
 (0)