reifydb_transaction/interceptor/
granted_role.rs1use reifydb_core::interface::catalog::identity::GrantedRole;
5use reifydb_type::Result;
6
7use crate::interceptor::chain::InterceptorChain;
8
9pub struct GrantedRolePostCreateContext<'a> {
10 pub post: &'a GrantedRole,
11}
12
13impl<'a> GrantedRolePostCreateContext<'a> {
14 pub fn new(post: &'a GrantedRole) -> Self {
15 Self {
16 post,
17 }
18 }
19}
20
21pub trait GrantedRolePostCreateInterceptor: Send + Sync {
22 fn intercept<'a>(&self, ctx: &mut GrantedRolePostCreateContext<'a>) -> Result<()>;
23}
24
25impl InterceptorChain<dyn GrantedRolePostCreateInterceptor + Send + Sync> {
26 pub fn execute(&self, mut ctx: GrantedRolePostCreateContext) -> Result<()> {
27 for interceptor in &self.interceptors {
28 interceptor.intercept(&mut ctx)?;
29 }
30 Ok(())
31 }
32}
33
34pub struct ClosureGrantedRolePostCreateInterceptor<F>
35where
36 F: for<'a> Fn(&mut GrantedRolePostCreateContext<'a>) -> Result<()> + Send + Sync,
37{
38 closure: F,
39}
40
41impl<F> ClosureGrantedRolePostCreateInterceptor<F>
42where
43 F: for<'a> Fn(&mut GrantedRolePostCreateContext<'a>) -> Result<()> + Send + Sync,
44{
45 pub fn new(closure: F) -> Self {
46 Self {
47 closure,
48 }
49 }
50}
51
52impl<F> Clone for ClosureGrantedRolePostCreateInterceptor<F>
53where
54 F: for<'a> Fn(&mut GrantedRolePostCreateContext<'a>) -> Result<()> + Send + Sync + Clone,
55{
56 fn clone(&self) -> Self {
57 Self {
58 closure: self.closure.clone(),
59 }
60 }
61}
62
63impl<F> GrantedRolePostCreateInterceptor for ClosureGrantedRolePostCreateInterceptor<F>
64where
65 F: for<'a> Fn(&mut GrantedRolePostCreateContext<'a>) -> Result<()> + Send + Sync,
66{
67 fn intercept<'a>(&self, ctx: &mut GrantedRolePostCreateContext<'a>) -> Result<()> {
68 (self.closure)(ctx)
69 }
70}
71
72pub fn granted_role_post_create<F>(f: F) -> ClosureGrantedRolePostCreateInterceptor<F>
73where
74 F: for<'a> Fn(&mut GrantedRolePostCreateContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
75{
76 ClosureGrantedRolePostCreateInterceptor::new(f)
77}
78
79pub struct GrantedRolePreDeleteContext<'a> {
80 pub pre: &'a GrantedRole,
81}
82
83impl<'a> GrantedRolePreDeleteContext<'a> {
84 pub fn new(pre: &'a GrantedRole) -> Self {
85 Self {
86 pre,
87 }
88 }
89}
90
91pub trait GrantedRolePreDeleteInterceptor: Send + Sync {
92 fn intercept<'a>(&self, ctx: &mut GrantedRolePreDeleteContext<'a>) -> Result<()>;
93}
94
95impl InterceptorChain<dyn GrantedRolePreDeleteInterceptor + Send + Sync> {
96 pub fn execute(&self, mut ctx: GrantedRolePreDeleteContext) -> Result<()> {
97 for interceptor in &self.interceptors {
98 interceptor.intercept(&mut ctx)?;
99 }
100 Ok(())
101 }
102}
103
104pub struct ClosureGrantedRolePreDeleteInterceptor<F>
105where
106 F: for<'a> Fn(&mut GrantedRolePreDeleteContext<'a>) -> Result<()> + Send + Sync,
107{
108 closure: F,
109}
110
111impl<F> ClosureGrantedRolePreDeleteInterceptor<F>
112where
113 F: for<'a> Fn(&mut GrantedRolePreDeleteContext<'a>) -> Result<()> + Send + Sync,
114{
115 pub fn new(closure: F) -> Self {
116 Self {
117 closure,
118 }
119 }
120}
121
122impl<F> Clone for ClosureGrantedRolePreDeleteInterceptor<F>
123where
124 F: for<'a> Fn(&mut GrantedRolePreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone,
125{
126 fn clone(&self) -> Self {
127 Self {
128 closure: self.closure.clone(),
129 }
130 }
131}
132
133impl<F> GrantedRolePreDeleteInterceptor for ClosureGrantedRolePreDeleteInterceptor<F>
134where
135 F: for<'a> Fn(&mut GrantedRolePreDeleteContext<'a>) -> Result<()> + Send + Sync,
136{
137 fn intercept<'a>(&self, ctx: &mut GrantedRolePreDeleteContext<'a>) -> Result<()> {
138 (self.closure)(ctx)
139 }
140}
141
142pub fn granted_role_pre_delete<F>(f: F) -> ClosureGrantedRolePreDeleteInterceptor<F>
143where
144 F: for<'a> Fn(&mut GrantedRolePreDeleteContext<'a>) -> Result<()> + Send + Sync + Clone + 'static,
145{
146 ClosureGrantedRolePreDeleteInterceptor::new(f)
147}