From bc52dd33698b1121b57c5a7955b8fa4d998025b7 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 8 Mar 2024 15:37:36 -0500 Subject: [PATCH] Add permissions-based `visible` method to LinksCardDashboardFragment --- dashboard/__init__.py | 7 +++++++ membershipworks/dashboard.py | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dashboard/__init__.py b/dashboard/__init__.py index 3f5a70a..cdeb545 100644 --- a/dashboard/__init__.py +++ b/dashboard/__init__.py @@ -38,3 +38,10 @@ class LinksCardDashboardFragment(DashboardFragment): @property def context(self): return {"links": self.links} + + @property + def visible(self) -> bool: + return any( + link.permission is None or self.request.user.has_perm(link.permission) + for link in self.links + ) diff --git a/membershipworks/dashboard.py b/membershipworks/dashboard.py index 2c5e346..fba4810 100644 --- a/membershipworks/dashboard.py +++ b/membershipworks/dashboard.py @@ -31,7 +31,3 @@ class MembershipworksDashboardFragment(dashboard.LinksCardDashboardFragment): permission="membershipworks.view_member", ), ] - - @property - def visible(self) -> bool: - return self.request.user.has_perm("doorcontrol.view_hidevent")