summaryrefslogtreecommitdiff
path: root/src/login/history.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-09 00:57:31 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-09 11:45:31 -0400
commitba96974bdebd6d4ec345907d49944b5ee644ed47 (patch)
tree8811ef8981a915a8cc17d8a1e576750b31cbdd0b /src/login/history.rs
parentda1810afc5a627a518131cfb0af0996c5ec60bcf (diff)
Provide a view of logins to clients.
Diffstat (limited to 'src/login/history.rs')
-rw-r--r--src/login/history.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/login/history.rs b/src/login/history.rs
new file mode 100644
index 0000000..add7d1e
--- /dev/null
+++ b/src/login/history.rs
@@ -0,0 +1,47 @@
+use super::{
+ event::{Created, Event},
+ Id, Login,
+};
+use crate::event::{Instant, ResumePoint, Sequence};
+
+#[derive(Clone, Debug, Eq, PartialEq)]
+pub struct History {
+ pub login: Login,
+ pub created: Instant,
+}
+
+// State interface
+impl History {
+ pub fn id(&self) -> &Id {
+ &self.login.id
+ }
+
+ // Snapshot of this login as it was when created. (Note to the future: it's okay
+ // if this returns a redacted or modified version of the login. If we implement
+ // renames by redacting the original name, then this should return the edited login, not the original, even if that's not how it was "as created.")
+ #[cfg(test)]
+ pub fn as_created(&self) -> Login {
+ self.login.clone()
+ }
+
+ pub fn as_of(&self, resume_point: impl Into<ResumePoint>) -> Option<Login> {
+ self.events()
+ .filter(Sequence::up_to(resume_point.into()))
+ .collect()
+ }
+}
+
+// Events interface
+impl History {
+ fn created(&self) -> Event {
+ Created {
+ instant: self.created,
+ login: self.login.clone(),
+ }
+ .into()
+ }
+
+ pub fn events(&self) -> impl Iterator<Item = Event> {
+ [self.created()].into_iter()
+ }
+}