From 1dc135f8f9b4eed3f650f7390d0985c53b6c1933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Bouzour=C3=A8ne?= Date: Fri, 17 Jan 2025 16:21:16 +0100 Subject: [PATCH] Add permissions to menus --- middlewares/templates.go | 40 ++++++++++++++++++++++++++++++-------- views/admin.html | 10 +++++----- views/index.html | 12 +++++++++--- views/partials/header.html | 6 ++++++ 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/middlewares/templates.go b/middlewares/templates.go index cfef2e5..6d15e15 100644 --- a/middlewares/templates.go +++ b/middlewares/templates.go @@ -10,14 +10,16 @@ import ( ) type TemplatesGlobals struct { - LoggedIn bool - TotpVerified bool - UserID uint - UserEmail string - UserFullname string - UserIsAdmin bool - TimeStart time.Time - ColorMode string + LoggedIn bool + TotpVerified bool + UserID uint + UserEmail string + UserFullname string + UserIsAdmin bool + TimeStart time.Time + ColorMode string + AllowMembersPage bool + AllowContactsPage bool } func TemplatesMiddleware(c *fiber.Ctx) error { @@ -59,6 +61,28 @@ func TemplatesMiddleware(c *fiber.Ctx) error { globals.UserFullname = user.Name globals.UserIsAdmin = user.IsAdmin } + + showMember, _ := helpers.PermissionsGetSections( + userid.(uint), "show_member", + ) + showArchivedMember, _ := helpers.PermissionsGetSections( + userid.(uint), "show_archived_member", + ) + + if len(showMember) > 0 || len(showArchivedMember) > 0 { + globals.AllowMembersPage = true + } + + showContact, _ := helpers.PermissionsGetSections( + userid.(uint), "show_contact", + ) + showArchivedContact, _ := helpers.PermissionsGetSections( + userid.(uint), "show_archived_contact", + ) + + if len(showContact) > 0 || len(showArchivedContact) > 0 { + globals.AllowContactsPage = true + } } totpVerified := sess.Get("totp-verified") diff --git a/views/admin.html b/views/admin.html index 2af40cf..f2d653d 100644 --- a/views/admin.html +++ b/views/admin.html @@ -17,7 +17,7 @@
- Gestion des sections + Gestion des sections
@@ -25,7 +25,7 @@
- Gestion des listes + Gestion des listes
@@ -33,7 +33,7 @@
- Gestion des champs supplémentaires + Gestion des champs supplémentaires
@@ -41,7 +41,7 @@
- Gestion des utilisateurs + Gestion des utilisateurs
@@ -49,7 +49,7 @@
- Gestion des utilisateurs + Gestion des utilisateurs
diff --git a/views/index.html b/views/index.html index f7baa25..a728de4 100644 --- a/views/index.html +++ b/views/index.html @@ -12,29 +12,35 @@
+ + {% if Globals.AllowMembersPage %} + {% endif %} + + {% if Globals.AllowContactsPage %} + {% endif %} {% if Globals.UserIsAdmin %} diff --git a/views/partials/header.html b/views/partials/header.html index 6a1b28a..1229c01 100644 --- a/views/partials/header.html +++ b/views/partials/header.html @@ -22,16 +22,22 @@