started hooks

master
Avril 4 years ago
parent f4bd13b74a
commit d2bf263533
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -92,9 +92,11 @@ bitflags! {
const NONE = 0;
/// This value should be cloned on write unless specified elsewhere.
const COW = 1<<0;
/// This should not show up in searches
/// This should not show up in searches.
const HIDDEN = 1<<1;
/// Versioning is enabled for this value
/// Versioning is enabled for this value.
///
/// When it is deleted, it should instead be moved away into a sperate entry.
const VERSIONED = 1<<2;
}
}
@ -110,13 +112,15 @@ pub struct Info
tags: Tags,
hooks: event::Hooks,
owner: Option<Vec<user::EntityID>>, //starts as the user that created (i.e. same as `created_by`), or `None` if ownership is disabled
signed: Option<Vec<Signature>>,
perms: user::Permissions,
created_by: user::UserID,
log: Vec<event::Event>,
log: Vec<event::InBandEvent>,
}
/// The root data containing map

@ -1,9 +1,10 @@
//! When events happen to datamaps
use super::*;
use bitflags::bitflags;
/// What happened in the event
/// What happened in the in-band event
#[derive(Debug, Serialize, Deserialize)]
pub enum EventKind
pub enum InBandEventKind
{
Created,
Modified,
@ -16,13 +17,84 @@ pub enum EventKind
Comment(String),
}
/// An event that happened to a data entry
/// An event that happened to a data entry that is then stored in its metadata.
///
/// # Note
/// Not to be confused with `HookEvent`s
#[derive(Debug, Serialize, Deserialize)]
pub struct Event
pub struct InBandEvent
{
who: Option<user::UserID>,
what: EventKind,
what: InBandEventKind,
when: u64,
signed: Option<cryptohelpers::rsa::Signature>,
}
bitflags! {
/// Kind of events that should emmit for a hook
#[derive(Serialize, Deserialize)]
struct HookMask: u16
{
/// Filter all events. None are emiited.
const NONE = 0;
/// Mask any event, any kind is emitted.
const ANY = !0;
/// Emmit read events.
const READ = 1<<0;
/// Emmit write events.
const WRITE = 1<<1;
/// Emmit delete events.
const DELETE = 1<<2;
/// Propagate events from children of `Map` datas
const CHILD = 1<<3;
/// Poke events are opaque events that are fired manually.
const POKE = 1<<4;
}
}
impl Default for HookMask
{
#[inline(always)]
fn default() -> Self
{
Self::NONE
}
}
/// Fire events when something happens to this value.
#[derive(Debug, Serialize, Deserialize)]
pub struct Hooks
{
filter: HookMask,
}
/// An event emitted from a matched `Hook`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub enum HookEvent
{
/// An opaque event type
Poke,
Read,
Write,
Delete,
Child(Box<HookEvent>),
}
impl Default for HookEvent
{
#[inline]
fn default() -> Self
{
Self::Poke
}
}

@ -262,6 +262,15 @@ bitflags! {
}
}
impl Default for Permission
{
#[inline(always)]
fn default() -> Self
{
Self::READ
}
}
/// A set of permissions informations for users and/or groups
#[derive(Debug, Serialize, Deserialize)]

Loading…
Cancel
Save