From 7191d39b51220b2dc1e745eef8f325a6d176a1c9 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Fri, 3 Jan 2020 08:41:59 -0800 Subject: [PATCH] Fix multiple Needs on OctoPrintPermission fixes #3398 --- src/octoprint/access/permissions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/octoprint/access/permissions.py b/src/octoprint/access/permissions.py index e59531729..7f899c741 100644 --- a/src/octoprint/access/permissions.py +++ b/src/octoprint/access/permissions.py @@ -79,6 +79,22 @@ class OctoPrintPermission(Permission): def get_description(self): return self._description + def allows(self, identity): + """Whether the identity can access this permission. + Overridden from Permission.allows to make sure the Identity provides ALL + required needs instead of ANY required need. + + :param identity: The identity + """ + if self.needs and len(self.needs.intersection(identity.provides)) != len(self.needs): + return False + + if self.excludes and self.excludes.intersection(identity.provides): + return False + + return True + + def union(self, other): """Create a new OctoPrintPermission with the requirements of the union of this and other.