use actionable::{Action, Identifier};
use crate::connection::Session;
use crate::Error;
pub trait HasSession {
fn session(&self) -> Option<&Session>;
fn allowed_to<'a, R: AsRef<[Identifier<'a>]>, P: Action>(
&self,
resource_name: R,
action: &P,
) -> bool {
self.session()
.map_or(true, |session| session.allowed_to(resource_name, action))
}
fn check_permission<'a, R: AsRef<[Identifier<'a>]>, P: Action>(
&self,
resource_name: R,
action: &P,
) -> Result<(), Error> {
self.session().map_or_else(
|| Ok(()),
|session| session.check_permission(resource_name, action),
)
}
}