aboutsummaryrefslogtreecommitdiffstats
path: root/bsfs/graph/ac/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'bsfs/graph/ac/base.py')
-rw-r--r--bsfs/graph/ac/base.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/bsfs/graph/ac/base.py b/bsfs/graph/ac/base.py
index 79b09e5..e85c1dd 100644
--- a/bsfs/graph/ac/base.py
+++ b/bsfs/graph/ac/base.py
@@ -1,9 +1,4 @@
-"""
-Part of the BlackStar filesystem (bsfs) module.
-A copy of the license is provided with the project.
-Author: Matthias Baumgartner, 2022
-"""
# imports
import abc
import typing
@@ -12,7 +7,7 @@ import typing
from bsfs import schema
from bsfs.query import ast
from bsfs.triple_store import TripleStoreBase
-from bsfs.utils import URI
+from bsfs.utils import URI, typename
# exports
__all__: typing.Sequence[str] = (
@@ -44,6 +39,20 @@ class AccessControlBase(abc.ABC):
self._backend = backend
self._user = URI(user)
+ def __str__(self) -> str:
+ return f'{typename(self)}({self._user})'
+
+ def __repr__(self) -> str:
+ return f'{typename(self)}({self._user})'
+
+ def __eq__(self, other: typing.Any) -> bool:
+ return isinstance(other, type(self)) \
+ and self._backend == other._backend \
+ and self._user == other._user
+
+ def __hash__(self) -> int:
+ return hash((type(self), self._backend, self._user))
+
@abc.abstractmethod
def is_protected_predicate(self, pred: schema.Predicate) -> bool:
"""Return True if a predicate cannot be modified manually."""
@@ -69,7 +78,11 @@ class AccessControlBase(abc.ABC):
"""Return nodes that are allowed to be created."""
@abc.abstractmethod
- def filter_read(self, node_type: schema.Node, query: ast.filter.FilterExpression) -> ast.filter.FilterExpression:
+ def filter_read(
+ self,
+ node_type: schema.Node,
+ query: typing.Optional[ast.filter.FilterExpression],
+ ) -> typing.Optional[ast.filter.FilterExpression]:
"""Re-write a filter *query* to get (i.e., read) *node_type* nodes."""
@abc.abstractmethod