web permissions2
This commit is contained in:
@@ -16,19 +16,22 @@ pub(crate) struct Nav {
|
||||
pub authenticated: bool,
|
||||
pub role: String,
|
||||
pub can_admin: bool,
|
||||
pub can_permissions: bool,
|
||||
pub can_import: bool,
|
||||
pub can_export: bool,
|
||||
pub active: &'static str,
|
||||
}
|
||||
|
||||
impl Nav {
|
||||
/// `active` is the nav link to highlight: `"admin"`, `"analytics"`,
|
||||
/// `"login"`, or `""` for pages that are not themselves nav entries.
|
||||
/// `active` is the nav link to highlight: `"admin"`, `"permissions"`,
|
||||
/// `"analytics"`, `"login"`, or `""` for pages that are not themselves nav
|
||||
/// entries.
|
||||
pub(crate) fn new(headers: &HeaderMap, active: &'static str) -> Self {
|
||||
Self {
|
||||
authenticated: crate::cookie_value(headers, SESSION_COOKIE).is_some(),
|
||||
role: String::new(),
|
||||
can_admin: false,
|
||||
can_permissions: false,
|
||||
can_import: false,
|
||||
can_export: false,
|
||||
active,
|
||||
@@ -41,6 +44,10 @@ impl Nav {
|
||||
) -> Self {
|
||||
self.role = authorization.role.clone();
|
||||
self.can_admin = crate::authz::can_open_admin(authorization);
|
||||
// Permissions is its own nav section, so it is not gated on the admin
|
||||
// panel: managing either roles or users is enough to open it.
|
||||
self.can_permissions = crate::authz::can_manage(authorization, crate::authz::STRUCT_ROLE)
|
||||
|| crate::authz::can_manage(authorization, crate::authz::STRUCT_USER);
|
||||
self.can_import = authorization.permissions.iter().any(|permission| {
|
||||
permission.action == "insert" && permission.object.starts_with("data:")
|
||||
});
|
||||
@@ -57,6 +64,7 @@ impl Default for Nav {
|
||||
authenticated: false,
|
||||
role: String::new(),
|
||||
can_admin: false,
|
||||
can_permissions: false,
|
||||
can_import: false,
|
||||
can_export: false,
|
||||
active: "",
|
||||
|
||||
Reference in New Issue
Block a user