#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Level {
Public,
Authenticated,
Internal,
Owners,
Platform,
Group,
}
#[derive(Clone, Copy, Debug)]
pub struct Rule {
pub level: Level,
pub itself: bool,
}
use Level::*;
const fn r(level: Level) -> Rule {
Rule {
level,
itself: false,
}
}
const fn me(level: Level) -> Rule {
Rule {
level,
itself: true,
}
}
pub const RULES: &[(&str, Rule)] = &[
("tenancy.CreateTenant", r(Authenticated)), ("tenancy.ActivateTenant", r(Platform)),
("tenancy.SuspendTenant", r(Platform)), ("tenancy.ReactivateTenant", r(Platform)), ("tenancy.DeleteTenant", r(Platform)),
("tenancy.ChangeSignUpPolicy", r(Platform)),
("tenancy.AddOwner", r(Owners)),
("tenancy.RemoveOwner", r(Owners)),
("tenancy.RequireMfa", r(Owners)),
("tenancy.ListTenants", r(Platform)),
("account.RegisterAccount", r(Public)), ("account.VerifyEmail", r(Public)),
("account.SignIn", r(Public)),
("account.RefreshSession", r(Public)),
("account.ProveSecondFactor", r(Public)),
("account.ResetPassword", r(Public)),
("account.ConfirmEmailChange", r(Public)),
("account.OpenSession", r(Internal)),
("account.AddSessionFactor", r(Internal)),
("account.SuspendAccount", r(Platform)), ("account.ReactivateAccount", r(Platform)),
("account.DeleteAccount", r(Platform)),
("account.EndSession", me(Group)),
("account.ChangePassword", me(Group)),
("account.RequestEmailChange", me(Group)),
("account.StartTotp", me(Group)),
("account.ConfirmTotp", me(Group)),
("account.DisableTotp", me(Group)),
("account.RegenerateRecoveryCodes", me(Group)),
("account.AddPasskey", me(Group)),
("account.RemovePasskey", me(Group)),
("account.UnlinkProvider", me(Group)),
("account.CreateSso", r(Owners)),
("account.UpdateSso", r(Owners)),
("account.AddSsoDomain", r(Owners)),
("account.RemoveSsoDomain", r(Owners)),
("account.EnforceSso", r(Owners)),
("account.DisableSso", r(Owners)),
("account.EnableSso", r(Owners)),
("account.DeleteSso", r(Owners)),
("account.GetSso", r(Owners)),
("account.GetAccount", me(Group)),
("account.ListSessions", me(Group)),
("identity.CreateIdentity", r(Internal)),
("identity.CreateProcessIdentity", r(Internal)),
("identity.UpdateProfile", me(Group)),
("identity.GetIdentity", me(Group)),
("identity.DeleteIdentity", me(Group)),
("identity.ListMyIdentities", me(Authenticated)),
("group.Explain", me(Group)),
("invitation.DeclineInvitation", r(Public)),
("invitation.RecordInvitationMailSent", r(Internal)),
("invitation.EraseInvitation", r(Platform)),
];
pub const ESCALATION: &[&str] = &[
"identity.GrantMembership",
"invitation.CreateInvitation",
"invitation.CreateInvitationLink",
"group.CreateGroup",
"group.SetPermissions",
];
pub fn rule_of(r#type: &str) -> Rule {
RULES
.iter()
.find(|(t, _)| *t == r#type)
.map_or(r(Group), |(_, rule)| *rule)
}