Skip to main content

kanidmd_lib/
event.rs

1//! An `event` is a self contained module of data, that contains all of the
2//! required information for any operation to proceed. While there are many
3//! types of potential events, they all eventually lower to one of:
4//!
5//! * AuthEvent
6//! * SearchEvent
7//! * ExistsEvent
8//! * ModifyEvent
9//! * CreateEvent
10//! * DeleteEvent
11//!
12//! An "event" is generally then passed to the `QueryServer` for processing.
13//! By making these fully self contained units, it means that we can assert
14//! at event creation time we have all the correct data required to proceed
15//! with the operation, and a clear path to know how to transform events between
16//! various types.
17
18use std::collections::BTreeSet;
19#[cfg(test)]
20use std::sync::Arc;
21
22use kanidm_proto::{
23    internal::{
24        CreateRequest, DeleteRequest, ModifyList as ProtoModifyList, ModifyRequest, OperationError,
25        SearchRequest, SearchResponse,
26    },
27    v1::{Entry as ProtoEntry, WhoamiResponse},
28};
29use ldap3_proto::simple::LdapFilter;
30use uuid::Uuid;
31
32use crate::{
33    entry::{Entry, EntryCommitted, EntryInit, EntryNew, EntryReduced},
34    filter::{Filter, FilterInvalid, FilterValid},
35    modify::{ModifyInvalid, ModifyList, ModifyValid},
36    prelude::*,
37    schema::SchemaTransaction,
38    value::PartialValue,
39};
40
41#[derive(Debug)]
42pub struct SearchResult {
43    entries: Vec<ProtoEntry>,
44}
45
46impl SearchResult {
47    pub fn new(
48        qs: &mut QueryServerReadTransaction,
49        entries: &[Entry<EntryReduced, EntryCommitted>],
50    ) -> Result<Self, OperationError> {
51        let entries: Result<_, _> = entries
52            .iter()
53            .map(|e| {
54                // All the needed transforms for this result are done
55                // in search_ext. This is just an entry -> protoentry
56                // step.
57                e.to_pe(qs)
58            })
59            .collect();
60        Ok(SearchResult { entries: entries? })
61    }
62
63    // Consume self into a search response
64    pub fn response(self) -> SearchResponse {
65        SearchResponse {
66            entries: self.entries,
67        }
68    }
69
70    // Consume into the array of entries, used in the json proto
71    pub fn into_proto_array(self) -> Vec<ProtoEntry> {
72        self.entries
73    }
74}
75
76#[derive(Debug)]
77pub struct SearchEvent {
78    pub ident: Identity,
79    // This is the filter as we apply and process it.
80    pub filter: Filter<FilterValid>,
81    // This is the original filter, for the purpose of ACI checking.
82    pub filter_orig: Filter<FilterValid>,
83    pub attrs: Option<BTreeSet<Attribute>>,
84    pub effective_access_check: bool,
85}
86
87impl SearchEvent {
88    pub fn from_message(
89        ident: Identity,
90        req: &SearchRequest,
91        qs: &mut QueryServerReadTransaction,
92    ) -> Result<Self, OperationError> {
93        let f = Filter::from_ro(&ident, &req.filter, qs)?;
94        // We do need to do this twice to account for the ignore_hidden
95        // changes.
96        let filter_orig = f
97            .validate(qs.get_schema())
98            .map_err(OperationError::SchemaViolation)?;
99        let filter = filter_orig.clone().into_ignore_hidden();
100        Ok(SearchEvent {
101            ident,
102            filter,
103            filter_orig,
104            // We can't get this from the SearchMessage because it's annoying with the
105            // current macro design.
106            attrs: None,
107            effective_access_check: false,
108        })
109    }
110
111    pub fn from_internal_message(
112        ident: Identity,
113        filter: &Filter<FilterInvalid>,
114        attrs: Option<&[String]>,
115        qs: &mut QueryServerReadTransaction,
116    ) -> Result<Self, OperationError> {
117        let r_attrs: Option<BTreeSet<Attribute>> = attrs.map(|vs| {
118            vs.iter()
119                .filter_map(|a| qs.get_schema().normalise_attr_if_exists(a.as_str()))
120                .collect()
121        });
122
123        if let Some(s) = &r_attrs {
124            if s.is_empty() {
125                request_error!("EmptyRequest for attributes");
126                return Err(OperationError::EmptyRequest);
127            }
128        }
129
130        let filter_orig = filter.validate(qs.get_schema()).map_err(|e| {
131            request_error!(?e, "filter schema violation");
132            OperationError::SchemaViolation(e)
133        })?;
134        let filter = filter_orig.clone().into_ignore_hidden();
135
136        Ok(SearchEvent {
137            ident,
138            filter,
139            filter_orig,
140            attrs: r_attrs,
141            effective_access_check: false,
142        })
143    }
144
145    pub fn from_internal_recycle_message(
146        ident: Identity,
147        filter: &Filter<FilterInvalid>,
148        attrs: Option<&[String]>,
149        qs: &QueryServerReadTransaction,
150    ) -> Result<Self, OperationError> {
151        let r_attrs: Option<BTreeSet<Attribute>> = attrs.map(|vs| {
152            vs.iter()
153                .filter_map(|a| {
154                    qs.get_schema()
155                        .normalise_attr_if_exists(a.as_str())
156                        .map(|a_str| Attribute::from(a_str.as_str()))
157                })
158                .collect()
159        });
160
161        if let Some(s) = &r_attrs {
162            if s.is_empty() {
163                return Err(OperationError::EmptyRequest);
164            }
165        }
166
167        let filter_orig = filter
168            .validate(qs.get_schema())
169            .map(|f| f.into_recycled())
170            .map_err(OperationError::SchemaViolation)?;
171        let filter = filter_orig.clone();
172
173        Ok(SearchEvent {
174            ident,
175            filter,
176            filter_orig,
177            attrs: r_attrs,
178            effective_access_check: false,
179        })
180    }
181
182    pub fn from_whoami_request(
183        ident: Identity,
184        qs: &QueryServerReadTransaction,
185    ) -> Result<Self, OperationError> {
186        let filter_orig = filter_all!(f_self())
187            .validate(qs.get_schema())
188            .map_err(OperationError::SchemaViolation)?;
189        let filter = filter_orig.clone().into_ignore_hidden();
190
191        Ok(SearchEvent {
192            ident,
193            filter,
194            filter_orig,
195            attrs: None,
196            effective_access_check: false,
197        })
198    }
199
200    pub fn from_target_uuid_request(
201        ident: Identity,
202        target_uuid: Uuid,
203        qs: &QueryServerReadTransaction,
204    ) -> Result<Self, OperationError> {
205        let filter_orig = filter_all!(f_eq(Attribute::Uuid, PartialValue::Uuid(target_uuid)))
206            .validate(qs.get_schema())
207            .map_err(OperationError::SchemaViolation)?;
208        let filter = filter_orig.clone().into_ignore_hidden();
209        Ok(SearchEvent {
210            ident,
211            filter,
212            filter_orig,
213            attrs: None,
214            effective_access_check: false,
215        })
216    }
217
218    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
219    /// This is a TEST ONLY method and will never be exposed in production.
220    #[cfg(test)]
221    pub fn new_impersonate_entry(
222        e: Arc<Entry<EntrySealed, EntryCommitted>>,
223        filter: Filter<FilterInvalid>,
224    ) -> Self {
225        SearchEvent {
226            ident: Identity::from_impersonate_entry_readonly(e),
227            filter: filter.clone().into_valid(),
228            filter_orig: filter.into_valid(),
229            attrs: None,
230            effective_access_check: false,
231        }
232    }
233
234    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
235    /// This is a TEST ONLY method and will never be exposed in production.
236    #[cfg(test)]
237    pub fn new_impersonate_identity(ident: Identity, filter: Filter<FilterInvalid>) -> Self {
238        SearchEvent {
239            ident,
240            filter: filter.clone().into_valid(),
241            filter_orig: filter.into_valid(),
242            attrs: None,
243            effective_access_check: false,
244        }
245    }
246
247    pub fn new_impersonate(
248        ident: &Identity,
249        filter: Filter<FilterValid>,
250        filter_orig: Filter<FilterValid>,
251    ) -> Self {
252        SearchEvent {
253            ident: Identity::from_impersonate(ident),
254            filter,
255            filter_orig,
256            attrs: None,
257            effective_access_check: false,
258        }
259    }
260
261    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
262    /// This is a TEST ONLY method and will never be exposed in production.
263    #[cfg(test)]
264    pub fn new_rec_impersonate_entry(
265        e: Arc<Entry<EntrySealed, EntryCommitted>>,
266        filter: Filter<FilterInvalid>,
267    ) -> Self {
268        /* Impersonate a request for recycled objects */
269        let filter_orig = filter.into_valid();
270        let filter = filter_orig.clone().into_recycled();
271        SearchEvent {
272            ident: Identity::from_impersonate_entry_readonly(e),
273            filter,
274            filter_orig,
275            attrs: None,
276            effective_access_check: false,
277        }
278    }
279
280    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
281    /// This is a TEST ONLY method and will never be exposed in production.
282    #[cfg(test)]
283    pub fn new_ext_impersonate_entry(
284        e: Arc<Entry<EntrySealed, EntryCommitted>>,
285        filter: Filter<FilterInvalid>,
286    ) -> Self {
287        /* Impersonate an external request AKA filter ts + recycle */
288        SearchEvent {
289            ident: Identity::from_impersonate_entry_readonly(e),
290            filter: filter.clone().into_valid().into_ignore_hidden(),
291            filter_orig: filter.into_valid(),
292            attrs: None,
293            effective_access_check: false,
294        }
295    }
296
297    pub(crate) fn new_ext_impersonate_uuid(
298        qs: &mut QueryServerReadTransaction,
299        ident: Identity,
300        lf: &LdapFilter,
301        attrs: Option<BTreeSet<Attribute>>,
302    ) -> Result<Self, OperationError> {
303        // Kanidm Filter from LdapFilter
304        let f = Filter::from_ldap_ro(&ident, lf, qs)?;
305        let filter_orig = f
306            .validate(qs.get_schema())
307            .map_err(OperationError::SchemaViolation)?;
308        let filter = filter_orig.clone().into_ignore_hidden();
309        Ok(SearchEvent {
310            ident,
311            filter,
312            filter_orig,
313            attrs,
314            effective_access_check: false,
315        })
316    }
317
318    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
319    /// This is a TEST ONLY method and will never be exposed in production.
320    #[cfg(test)]
321    pub fn new_internal_invalid(filter: Filter<FilterInvalid>) -> Self {
322        SearchEvent {
323            ident: Identity::from_internal(),
324            filter: filter.clone().into_valid(),
325            filter_orig: filter.into_valid(),
326            attrs: None,
327            effective_access_check: false,
328        }
329    }
330
331    pub fn new_internal(filter: Filter<FilterValid>) -> Self {
332        SearchEvent {
333            ident: Identity::from_internal(),
334            filter: filter.clone(),
335            filter_orig: filter,
336            attrs: None,
337            effective_access_check: false,
338        }
339    }
340}
341
342// Represents the decoded entries from the protocol -> internal entry representation
343// including information about the identity performing the request, and if the
344// request is internal or not.
345#[derive(Debug)]
346pub struct CreateEvent {
347    pub ident: Identity,
348    // This may still actually change to handle the *raw* nature of the
349    // input that we plan to parse.
350    pub entries: Vec<Entry<EntryInit, EntryNew>>,
351    // Is the CreateEvent from an internal or external source?
352    // This may affect which plugins are run ...
353    /// If true, the list of created entry UUID's will be returned.
354    pub return_created_uuids: bool,
355}
356
357impl CreateEvent {
358    pub fn from_message(
359        ident: Identity,
360        req: &CreateRequest,
361        qs: &mut QueryServerWriteTransaction,
362    ) -> Result<Self, OperationError> {
363        let rentries: Result<Vec<_>, _> = req
364            .entries
365            .iter()
366            .map(|e| Entry::from_proto_entry(e, qs))
367            .collect();
368        // From ProtoEntry -> Entry
369        // What is the correct consuming iterator here? Can we
370        // even do that?
371        match rentries {
372            Ok(entries) => Ok(CreateEvent {
373                ident,
374                entries,
375                return_created_uuids: false,
376            }),
377            Err(e) => Err(e),
378        }
379    }
380
381    pub fn new_impersonate_identity(
382        ident: Identity,
383        entries: Vec<Entry<EntryInit, EntryNew>>,
384    ) -> Self {
385        CreateEvent {
386            ident,
387            entries,
388            return_created_uuids: false,
389        }
390    }
391
392    pub fn new_internal(entries: Vec<Entry<EntryInit, EntryNew>>) -> Self {
393        CreateEvent {
394            ident: Identity::from_internal(),
395            entries,
396            return_created_uuids: false,
397        }
398    }
399}
400
401#[derive(Debug)]
402pub struct ExistsEvent {
403    pub ident: Identity,
404    // This is the filter, as it will be processed.
405    pub filter: Filter<FilterValid>,
406    // This is the original filter, for the purpose of ACI checking.
407    pub filter_orig: Filter<FilterValid>,
408}
409
410impl ExistsEvent {
411    pub fn new_internal(filter: Filter<FilterValid>) -> Self {
412        ExistsEvent {
413            ident: Identity::from_internal(),
414            filter: filter.clone(),
415            filter_orig: filter,
416        }
417    }
418
419    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
420    /// This is a TEST ONLY method and will never be exposed in production.
421    #[cfg(test)]
422    pub fn new_internal_invalid(filter: Filter<FilterInvalid>) -> Self {
423        ExistsEvent {
424            ident: Identity::from_internal(),
425            filter: filter.clone().into_valid(),
426            filter_orig: filter.into_valid(),
427        }
428    }
429}
430
431#[derive(Debug)]
432pub struct DeleteEvent {
433    pub ident: Identity,
434    // This is the filter, as it will be processed.
435    pub filter: Filter<FilterValid>,
436    // This is the original filter, for the purpose of ACI checking.
437    pub filter_orig: Filter<FilterValid>,
438}
439
440impl DeleteEvent {
441    pub fn from_message(
442        ident: Identity,
443        req: &DeleteRequest,
444        qs: &mut QueryServerWriteTransaction,
445    ) -> Result<Self, OperationError> {
446        let f = Filter::from_rw(&ident, &req.filter, qs)?;
447        let filter_orig = f
448            .validate(qs.get_schema())
449            .map_err(OperationError::SchemaViolation)?;
450        let filter = filter_orig.clone().into_ignore_hidden();
451        Ok(DeleteEvent {
452            ident,
453            filter,
454            filter_orig,
455        })
456    }
457
458    pub fn from_parts(
459        ident: Identity,
460        f: &Filter<FilterInvalid>,
461        qs: &mut QueryServerWriteTransaction,
462    ) -> Result<Self, OperationError> {
463        let filter_orig = f
464            .validate(qs.get_schema())
465            .map_err(OperationError::SchemaViolation)?;
466        let filter = filter_orig.clone().into_ignore_hidden();
467        Ok(DeleteEvent {
468            ident,
469            filter,
470            filter_orig,
471        })
472    }
473
474    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
475    /// This is a TEST ONLY method and will never be exposed in production.
476    #[cfg(test)]
477    pub fn new_impersonate_entry(
478        e: Arc<Entry<EntrySealed, EntryCommitted>>,
479        filter: Filter<FilterInvalid>,
480    ) -> Self {
481        DeleteEvent {
482            ident: Identity::from_impersonate_entry_readwrite(e),
483            filter: filter.clone().into_valid(),
484            filter_orig: filter.into_valid(),
485        }
486    }
487
488    /// ⚠️  - Bypass the schema state machine, allowing an invalid filter to be used in an impersonate request.
489    /// This is a TEST ONLY method and will never be exposed in production.
490    #[cfg(test)]
491    pub fn new_impersonate_identity(ident: Identity, filter: Filter<FilterInvalid>) -> Self {
492        DeleteEvent {
493            ident,
494            filter: filter.clone().into_valid(),
495            filter_orig: filter.into_valid(),
496        }
497    }
498
499    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
500    /// This is a TEST ONLY method and will never be exposed in production.
501    #[cfg(test)]
502    pub fn new_internal_invalid(filter: Filter<FilterInvalid>) -> Self {
503        DeleteEvent {
504            ident: Identity::from_internal(),
505            filter: filter.clone().into_valid(),
506            filter_orig: filter.into_valid(),
507        }
508    }
509
510    pub fn new_internal(filter: Filter<FilterValid>) -> Self {
511        DeleteEvent {
512            ident: Identity::from_internal(),
513            filter: filter.clone(),
514            filter_orig: filter,
515        }
516    }
517}
518
519#[derive(Debug)]
520pub struct ModifyEvent {
521    pub ident: Identity,
522    // This is the filter, as it will be processed.
523    pub filter: Filter<FilterValid>,
524    // This is the original filter, for the purpose of ACI checking.
525    pub filter_orig: Filter<FilterValid>,
526    pub modlist: ModifyList<ModifyValid>,
527}
528
529impl ModifyEvent {
530    pub fn from_message(
531        ident: Identity,
532        req: &ModifyRequest,
533        qs: &mut QueryServerWriteTransaction,
534    ) -> Result<Self, OperationError> {
535        let f = Filter::from_rw(&ident, &req.filter, qs)?;
536        let m = ModifyList::from(&req.modlist, qs)?;
537        let filter_orig = f
538            .validate(qs.get_schema())
539            .map_err(OperationError::SchemaViolation)?;
540        let filter = filter_orig.clone().into_ignore_hidden();
541        let modlist = m
542            .validate(qs.get_schema())
543            .map_err(OperationError::SchemaViolation)?;
544        Ok(ModifyEvent {
545            ident,
546            filter,
547            filter_orig,
548            modlist,
549        })
550    }
551
552    pub fn from_parts(
553        ident: Identity,
554        target_uuid: Uuid,
555        proto_ml: &ProtoModifyList,
556        filter: Filter<FilterInvalid>,
557        qs: &mut QueryServerWriteTransaction,
558    ) -> Result<Self, OperationError> {
559        let f_uuid = filter_all!(f_eq(Attribute::Uuid, PartialValue::Uuid(target_uuid)));
560        // Add any supplemental conditions we have.
561        let f = Filter::join_parts_and(f_uuid, filter);
562
563        let m = ModifyList::from(proto_ml, qs)?;
564        let filter_orig = f
565            .validate(qs.get_schema())
566            .map_err(OperationError::SchemaViolation)?;
567        let filter = filter_orig.clone().into_ignore_hidden();
568        let modlist = m
569            .validate(qs.get_schema())
570            .map_err(OperationError::SchemaViolation)?;
571
572        Ok(ModifyEvent {
573            ident,
574            filter,
575            filter_orig,
576            modlist,
577        })
578    }
579
580    pub fn from_internal_parts(
581        ident: Identity,
582        ml: &ModifyList<ModifyInvalid>,
583        filter: &Filter<FilterInvalid>,
584        qs: &QueryServerWriteTransaction,
585    ) -> Result<Self, OperationError> {
586        let filter_orig = filter
587            .validate(qs.get_schema())
588            .map_err(OperationError::SchemaViolation)?;
589        let filter = filter_orig.clone().into_ignore_hidden();
590        let modlist = ml
591            .validate(qs.get_schema())
592            .map_err(OperationError::SchemaViolation)?;
593
594        Ok(ModifyEvent {
595            ident,
596            filter,
597            filter_orig,
598            modlist,
599        })
600    }
601
602    pub fn from_target_uuid_attr_purge(
603        ident: Identity,
604        target_uuid: Uuid,
605        attr: Attribute,
606        filter: Filter<FilterInvalid>,
607        qs: &QueryServerWriteTransaction,
608    ) -> Result<Self, OperationError> {
609        let ml = ModifyList::new_purge(attr);
610        let f_uuid = filter_all!(f_eq(Attribute::Uuid, PartialValue::Uuid(target_uuid)));
611        // Add any supplemental conditions we have.
612        let f = Filter::join_parts_and(f_uuid, filter);
613
614        let filter_orig = f
615            .validate(qs.get_schema())
616            .map_err(OperationError::SchemaViolation)?;
617        let filter = filter_orig.clone().into_ignore_hidden();
618        let modlist = ml
619            .validate(qs.get_schema())
620            .map_err(OperationError::SchemaViolation)?;
621        Ok(ModifyEvent {
622            ident,
623            filter,
624            filter_orig,
625            modlist,
626        })
627    }
628
629    pub fn new_internal(filter: Filter<FilterValid>, modlist: ModifyList<ModifyValid>) -> Self {
630        ModifyEvent {
631            ident: Identity::from_internal(),
632            filter: filter.clone(),
633            filter_orig: filter,
634            modlist,
635        }
636    }
637
638    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
639    /// This is a TEST ONLY method and will never be exposed in production.
640    #[cfg(test)]
641    pub fn new_internal_invalid(
642        filter: Filter<FilterInvalid>,
643        modlist: ModifyList<ModifyInvalid>,
644    ) -> Self {
645        ModifyEvent {
646            ident: Identity::from_internal(),
647            filter: filter.clone().into_valid(),
648            filter_orig: filter.into_valid(),
649            modlist: modlist.into_valid(),
650        }
651    }
652
653    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
654    /// This is a TEST ONLY method and will never be exposed in production.
655    #[cfg(test)]
656    pub fn new_impersonate_identity(
657        ident: Identity,
658        filter: Filter<FilterInvalid>,
659        modlist: ModifyList<ModifyInvalid>,
660    ) -> Self {
661        ModifyEvent {
662            ident,
663            filter: filter.clone().into_valid(),
664            filter_orig: filter.into_valid(),
665            modlist: modlist.into_valid(),
666        }
667    }
668
669    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
670    /// This is a TEST ONLY method and will never be exposed in production.
671    #[cfg(test)]
672    pub fn new_impersonate_entry(
673        e: Arc<Entry<EntrySealed, EntryCommitted>>,
674        filter: Filter<FilterInvalid>,
675        modlist: ModifyList<ModifyInvalid>,
676    ) -> Self {
677        ModifyEvent {
678            ident: Identity::from_impersonate_entry_readwrite(e),
679            filter: filter.clone().into_valid(),
680            filter_orig: filter.into_valid(),
681            modlist: modlist.into_valid(),
682        }
683    }
684
685    pub fn new_impersonate(
686        ident: &Identity,
687        filter: Filter<FilterValid>,
688        filter_orig: Filter<FilterValid>,
689        modlist: ModifyList<ModifyValid>,
690    ) -> Self {
691        ModifyEvent {
692            ident: Identity::from_impersonate(ident),
693            filter,
694            filter_orig,
695            modlist,
696        }
697    }
698}
699
700pub struct WhoamiResult {
701    youare: ProtoEntry,
702}
703
704impl WhoamiResult {
705    pub fn new(
706        qs: &mut QueryServerReadTransaction,
707        e: &Entry<EntryReduced, EntryCommitted>,
708    ) -> Result<Self, OperationError> {
709        Ok(WhoamiResult {
710            youare: e.to_pe(qs)?,
711        })
712    }
713
714    pub fn response(self) -> WhoamiResponse {
715        WhoamiResponse {
716            youare: self.youare,
717        }
718    }
719}
720
721#[derive(Debug)]
722pub struct PurgeTombstoneEvent {
723    pub ident: Identity,
724    pub eventid: Uuid,
725}
726
727impl Default for PurgeTombstoneEvent {
728    fn default() -> Self {
729        Self::new()
730    }
731}
732
733impl PurgeTombstoneEvent {
734    pub fn new() -> Self {
735        PurgeTombstoneEvent {
736            ident: Identity::from_internal(),
737            eventid: Uuid::new_v4(),
738        }
739    }
740}
741
742#[derive(Debug)]
743pub struct PurgeRecycledEvent {
744    pub ident: Identity,
745    pub eventid: Uuid,
746}
747
748impl Default for PurgeRecycledEvent {
749    fn default() -> Self {
750        Self::new()
751    }
752}
753
754impl PurgeRecycledEvent {
755    pub fn new() -> Self {
756        PurgeRecycledEvent {
757            ident: Identity::from_internal(),
758            eventid: Uuid::new_v4(),
759        }
760    }
761}
762
763#[derive(Debug)]
764pub struct PurgeDeleteAfterEvent {
765    pub ident: Identity,
766    pub eventid: Uuid,
767}
768
769impl Default for PurgeDeleteAfterEvent {
770    fn default() -> Self {
771        Self::new()
772    }
773}
774
775impl PurgeDeleteAfterEvent {
776    pub fn new() -> Self {
777        PurgeDeleteAfterEvent {
778            ident: Identity::from_internal(),
779            eventid: Uuid::new_v4(),
780        }
781    }
782}
783
784#[derive(Debug)]
785pub struct OnlineBackupEvent {
786    pub ident: Identity,
787    pub eventid: Uuid,
788}
789
790impl Default for OnlineBackupEvent {
791    fn default() -> Self {
792        Self::new()
793    }
794}
795
796impl OnlineBackupEvent {
797    pub fn new() -> Self {
798        OnlineBackupEvent {
799            ident: Identity::from_internal(),
800            eventid: Uuid::new_v4(),
801        }
802    }
803}
804
805#[derive(Debug)]
806pub struct ReviveRecycledEvent {
807    pub ident: Identity,
808    // This is the filter, as it will be processed.
809    pub filter: Filter<FilterValid>,
810    // Unlike the others, because of how this works, we don't need the orig filter
811    // to be retained, because the filter is the orig filter for this check.
812    //
813    // It will be duplicated into the modify ident as it exists.
814}
815
816impl ReviveRecycledEvent {
817    pub fn from_parts(
818        ident: Identity,
819        filter: &Filter<FilterInvalid>,
820        qs: &QueryServerWriteTransaction,
821    ) -> Result<Self, OperationError> {
822        let filter = filter
823            .validate(qs.get_schema())
824            .map(|f| f.into_recycled())
825            .map_err(OperationError::SchemaViolation)?;
826        Ok(ReviveRecycledEvent { ident, filter })
827    }
828
829    /// ⚠️  - Bypass the schema state machine and force the filter to be considered valid.
830    /// This is a TEST ONLY method and will never be exposed in production.
831    #[cfg(test)]
832    pub fn new_impersonate_entry(
833        e: Arc<Entry<EntrySealed, EntryCommitted>>,
834        filter: Filter<FilterInvalid>,
835    ) -> Self {
836        ReviveRecycledEvent {
837            ident: Identity::from_impersonate_entry_readwrite(e),
838            filter: filter.into_valid(),
839        }
840    }
841
842    #[cfg(test)]
843    pub(crate) fn new_internal(filter: Filter<FilterValid>) -> Self {
844        ReviveRecycledEvent {
845            ident: Identity::from_internal(),
846            filter,
847        }
848    }
849}