You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extending/visibilities.md
+25-5Lines changed: 25 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Visibilities
2
2
3
-
The visibility part defines what you can see at all. Anything you cannot see, you're implicitly also not allowed to modify. The visibility classes define what you see depending on your roles, permissions, etc. Building on top of this follow the permission classes (see below) that define what you can do with the data you see.
3
+
With the help of custom visibilities you can define which objects users can see on the Caluma GraphQL API. A typical implementation of a custom visibility is based on user's roles, permissions, etc. Objects that a user cannot see are also not allowed to be modified. If an object is visible, you can define under which circumstances changes to that object are allowed using custom permissions (which are explained in the next chapter).
4
4
5
5
Visibility classes are configured using the environment variable `VISIBILITY_CLASSES`.
6
6
@@ -12,9 +12,7 @@ The following pre-defined classes are available:
12
12
*`caluma.caluma_user.visibilities.CreatedByGroup`: Only show data that belongs to the same group as the current user
13
13
*`caluma.caluma_workflow.visibilities.AddressedGroups`: Only show case, work item and document to addressed users through group
14
14
15
-
In case this default classes do not cover your use case, it is also possible to create your custom visibility class defining per node how to filter.
16
-
17
-
Example:
15
+
In case these default classes do not cover your use case, you can create your own custom visibility class. Here is a basic example:
18
16
19
17
```python
20
18
from caluma.caluma_core.visibilities import BaseVisibility, filter_queryset_for
@@ -32,7 +30,7 @@ class CustomVisibility(BaseVisibility):
32
30
return queryset.exclude(slug='protected-form')
33
31
```
34
32
35
-
Arguments:
33
+
Each method decorated by `filter_queryset_for` receives three arguments (excluding `self`):
36
34
37
35
*`node`: GraphQL node filtering queryset for
38
36
*`queryset`: [Queryset](https://docs.djangoproject.com/en/2.1/ref/models/querysets/) of specific node type
@@ -41,3 +39,25 @@ Arguments:
41
39
Save your visibility module as `visibilities.py` and inject it as Docker volume to path `/app/caluma/extensions/visibilities.py`, see [docker-compose.yml](https://github.com/projectcaluma/caluma/blob/main/docker-compose.yml) for an example.
42
40
43
41
Afterwards you can configure it in `VISIBILITY_CLASSES` as `caluma.extensions.visibilities.CustomVisibility`.
42
+
43
+
### Performance considerations
44
+
45
+
Visibilities are checked for every relationship, which means that for a single GraphQL query, the visibility layer might run many times. For this reason, complex visibilities can cause performance issues. If you run into such problems, try profiling the query (e.g. using Django Silk) to identify the bottleneck.
46
+
47
+
#### Suppressable visibilities
48
+
49
+
Since Caluma v10, visibilities are also checked on foreign key relationships (e.g. the relationship between a `Question` and its `Form`). In practice, the visibility of such relationships is often not limited (since typically it does not make sense to see a `Question`, but not it's `Form`). In order to suppress visibility checks for specific foreign key relationships, you can set the `suppress_visibilities` property in your visibility class. For example:
# this method will not be executed when resolving a workitems' child case
61
+
```
62
+
63
+
The supported keys for the `suppress_visibilites` property can be identified by checking the [callsites of `suppressable_visibility_resolver`](https://github.com/search?q=repo%3Aprojectcaluma%2Fcaluma%20suppressable_visibility_resolver\&type=code).
0 commit comments