@@ -4,8 +4,12 @@ use async_trait::async_trait;
44use serde:: { Deserialize , Serialize } ;
55
66use crate :: {
7- error:: ShieldError , form:: Form , provider:: Provider , request:: Request , response:: Response ,
8- session:: Session ,
7+ error:: ShieldError ,
8+ form:: Form ,
9+ provider:: Provider ,
10+ request:: Request ,
11+ response:: Response ,
12+ session:: { BaseSession , MethodSession } ,
913} ;
1014
1115// TODO: Think of a better name.
@@ -31,12 +35,12 @@ pub struct ActionProviderForm {
3135}
3236
3337#[ async_trait]
34- pub trait Action < P : Provider > : ErasedAction + Send + Sync {
38+ pub trait Action < P : Provider , S > : ErasedAction + Send + Sync {
3539 fn id ( & self ) -> String ;
3640
3741 fn name ( & self ) -> String ;
3842
39- fn condition ( & self , _provider : & P , _session : Session ) -> Result < bool , ShieldError > {
43+ fn condition ( & self , _provider : & P , _session : & MethodSession < S > ) -> Result < bool , ShieldError > {
4044 Ok ( true )
4145 }
4246
@@ -45,7 +49,7 @@ pub trait Action<P: Provider>: ErasedAction + Send + Sync {
4549 async fn call (
4650 & self ,
4751 provider : P ,
48- session : Session ,
52+ session : & MethodSession < S > ,
4953 request : Request ,
5054 ) -> Result < Response , ShieldError > ;
5155}
@@ -59,7 +63,8 @@ pub trait ErasedAction: Send + Sync {
5963 fn erased_condition (
6064 & self ,
6165 provider : & ( dyn Any + Send + Sync ) ,
62- session : Session ,
66+ base_session : & BaseSession ,
67+ method_session : & ( dyn Any + Send + Sync ) ,
6368 ) -> Result < bool , ShieldError > ;
6469
6570 async fn erased_forms (
@@ -70,7 +75,8 @@ pub trait ErasedAction: Send + Sync {
7075 async fn erased_call (
7176 & self ,
7277 provider : Box < dyn Any + Send + Sync > ,
73- session : Session ,
78+ base_session : & BaseSession ,
79+ method_session : & ( dyn Any + Send + Sync ) ,
7480 request : Request ,
7581 ) -> Result < Response , ShieldError > ;
7682}
@@ -88,21 +94,44 @@ macro_rules! erased_action {
8894 self . name( )
8995 }
9096
91- fn erased_condition( & self , provider: & ( dyn std:: any:: Any + Send + Sync ) , session: $crate:: Session ) -> Result <bool , $crate:: ShieldError > {
92- self . condition( provider. downcast_ref( ) . expect( "TODO" ) , session)
97+ fn erased_condition(
98+ & self ,
99+ provider: & ( dyn std:: any:: Any + Send + Sync ) ,
100+ base_session: & $crate:: BaseSession ,
101+ method_session: & ( dyn std:: any:: Any + Send + Sync )
102+ ) -> Result <bool , $crate:: ShieldError > {
103+ self . condition(
104+ provider. downcast_ref( ) . expect( "Provider should be downcast" ) ,
105+ & MethodSession {
106+ base: base_session,
107+ method: method_session. downcast_ref( ) . expect( "Session should be downcast" ) ,
108+ } ,
109+ )
93110 }
94111
95- async fn erased_forms( & self , provider: Box <dyn std:: any:: Any + Send + Sync >) -> Result <Vec <$crate:: Form >, $crate:: ShieldError > {
96- self . forms( * provider. downcast( ) . expect( "TODO" ) ) . await
112+ async fn erased_forms(
113+ & self ,
114+ provider: Box <dyn std:: any:: Any + Send + Sync >
115+ ) -> Result <Vec <$crate:: Form >, $crate:: ShieldError > {
116+ self . forms( * provider. downcast( ) . expect( "Provider should be downcast" ) ) . await
97117 }
98118
99119 async fn erased_call(
100120 & self ,
101121 provider: Box <dyn std:: any:: Any + Send + Sync >,
102- session: $crate:: Session ,
122+ base_session: & $crate:: BaseSession ,
123+ method_session: & ( dyn std:: any:: Any + Send + Sync ) ,
103124 request: $crate:: Request ,
104125 ) -> Result <$crate:: Response , $crate:: ShieldError > {
105- self . call( * provider. downcast( ) . expect( "TODO" ) , session, request)
126+ self
127+ . call(
128+ * provider. downcast( ) . expect( "Provider should be downcast" ) ,
129+ & $crate:: MethodSession {
130+ base: base_session,
131+ method: method_session. downcast_ref( ) . expect( "Session should be downcast" ) ,
132+ } ,
133+ request
134+ )
106135 . await
107136 }
108137 }
0 commit comments