@@ -7,14 +7,16 @@ use crate::{
77 session:: Session ,
88} ;
99
10- pub const SIGN_IN_ACTION_ID : & str = "sign-in" ;
11- pub const SIGN_IN_CALLBACK_ACTION_ID : & str = "sign-in-callback" ;
12- pub const SIGN_OUT_ACTION_ID : & str = "sign-out" ;
13-
1410#[ async_trait]
1511pub trait Action < P : Provider > : ErasedAction + Send + Sync {
1612 fn id ( & self ) -> String ;
1713
14+ fn name ( & self ) -> String ;
15+
16+ fn condition ( & self , _provider : & P , _session : Session ) -> Result < bool , ShieldError > {
17+ Ok ( true )
18+ }
19+
1820 fn form ( & self , provider : P ) -> Form ;
1921
2022 async fn call (
@@ -29,6 +31,14 @@ pub trait Action<P: Provider>: ErasedAction + Send + Sync {
2931pub trait ErasedAction : Send + Sync {
3032 fn erased_id ( & self ) -> String ;
3133
34+ fn erased_name ( & self ) -> String ;
35+
36+ fn erased_condition (
37+ & self ,
38+ provider : & ( dyn Any + Send + Sync ) ,
39+ session : Session ,
40+ ) -> Result < bool , ShieldError > ;
41+
3242 fn erased_form ( & self , provider : Box < dyn Any + Send + Sync > ) -> Form ;
3343
3444 async fn erased_call (
@@ -48,6 +58,14 @@ macro_rules! erased_action {
4858 self . id( )
4959 }
5060
61+ fn erased_name( & self ) -> String {
62+ self . name( )
63+ }
64+
65+ fn erased_condition( & self , provider: & ( dyn std:: any:: Any + Send + Sync ) , session: $crate:: Session ) -> Result <bool , $crate:: ShieldError > {
66+ self . condition( provider. downcast_ref( ) . expect( "TODO" ) , session)
67+ }
68+
5169 fn erased_form( & self , provider: Box <dyn std:: any:: Any + Send + Sync >) -> $crate:: Form {
5270 self . form( * provider. downcast( ) . expect( "TODO" ) )
5371 }
@@ -57,7 +75,7 @@ macro_rules! erased_action {
5775 provider: Box <dyn std:: any:: Any + Send + Sync >,
5876 session: $crate:: Session ,
5977 request: $crate:: Request ,
60- ) -> Result <$crate:: Response , ShieldError > {
78+ ) -> Result <$crate:: Response , $crate :: ShieldError > {
6179 self . call( * provider. downcast( ) . expect( "TODO" ) , session, request)
6280 . await
6381 }
@@ -76,7 +94,8 @@ pub(crate) mod tests {
7694
7795 use super :: Action ;
7896
79- pub const TEST_ACTION_ID : & str = "action" ;
97+ pub const TEST_ACTION_ID : & str = "test" ;
98+ pub const TEST_ACTION_NAME : & str = "Test" ;
8099
81100 #[ derive( Default ) ]
82101 pub struct TestAction { }
@@ -87,6 +106,10 @@ pub(crate) mod tests {
87106 TEST_ACTION_ID . to_owned ( )
88107 }
89108
109+ fn name ( & self ) -> String {
110+ TEST_ACTION_NAME . to_owned ( )
111+ }
112+
90113 fn form ( & self , _provider : TestProvider ) -> Form {
91114 Form { inputs : vec ! [ ] }
92115 }
0 commit comments