Skip to content

Commit

Permalink
add view affected by access filter method
Browse files Browse the repository at this point in the history
  • Loading branch information
pblankley committed Sep 2, 2024
1 parent a187854 commit 1cb6e88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion metrics_layer/core/model/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ def printable_attributes(self):
attributes["number_of_fields"] = f'{len(attributes.get("fields", []))}'
return {key: attributes.get(key) for key in to_print if attributes.get(key) is not None}

def is_affected_by_access_filters(self):
"""This method checks if the view is affected by any access filters
the current user (set in the Project object) has on him/herself.
"""
if self.access_filters:
for condition_set in self.access_filters:
user_attribute_value = condition_set["user_attribute"]
if self.project._user and self.project._user.get(user_attribute_value):
return True
return False

@property
def primary_key(self):
return next((f for f in self.fields() if f.primary_key), None)
Expand Down Expand Up @@ -461,7 +472,7 @@ def collect_errors(self):
errors.append(
self._error(
self._definition["access_filters"],
f"Access filter in view {self.name} is missing the required field property",
f"Access filter in view {self.name} is missing the required property: 'field'",
)
)
elif "field" in f:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metrics_layer"
version = "0.12.35"
version = "0.12.36"
description = "The open source metrics layer."
authors = ["Paul Blankley <[email protected]>"]
keywords = ["Metrics Layer", "Business Intelligence", "Analytics"]
Expand Down

0 comments on commit 1cb6e88

Please sign in to comment.