Comments (5)
Hi -- sorry about the delay in responding.
Here's an example below. It's a way to virtually segregate the database. For example, in a multi-tenant app, users of one tenant should have no awareness of another tenant's objects/rows. By having the scope_queryset
method on the access policy class, the idea is to centralize the access logic.
ViewSet:
@property
def access_policy(self):
return self.permission_classes[0]
def get_queryset(self):
qs = self.access_policy.scope_queryset(self.request, Task.objects.all())
AccessPolicy:
@classmethod
def scope_queryset(cls, request, qs):
return qs.filter(tenant_id=request.user.tenant_id, soft_delete=False)
from drf-access-policy.
ty, i will try. I think this isn't native solution and requires a description of this example in documentation. If possible, i will do it
from drf-access-policy.
Could you post the relevant parts of your code here?
from drf-access-policy.
Method scope_querset is unused and isn't called anywhere. How to use it? Maybe i should in ViewSet to assign queryset value from this method? Or, if possible, advise the correct use
from drf-access-policy.
what is self.request
for ViewSets in the following code you posted? Do they have such property or it should be defined and assigned?
def get_queryset(self):
qs = self.access_policy.scope_queryset(self.request, Task.objects.all())
I get:
File "/home/ahmad/jkar/karmodir/views.py", line 47, in get_queryset
self.request, self.queryset)
AttributeError: 'MemberViewSet' object has no attribute 'request'
from drf-access-policy.
Related Issues (20)
- Can I write all policies in one json file? HOT 1
- Inconsistent expression parsing
- ModuleNotFoundError: No module named 'pyparsing'
- Version 0.8.5 breaks conditions with `*` as params HOT 1
- Default value "effect": "allow"
- Introduction of support for condition expressions is a breaking change on existing condition strings HOT 2
- [BUG] bool type error HOT 6
- `view.get_object()` raises AssertionError inside condition method HOT 1
- Reusable conditions not working
- Why "principal: authenticated" is "not anonymous" instead of "is authenticated"? HOT 1
- [Question] Dealing with unnecessary repetition of DB hits... HOT 1
- [BUG] <lambda>() missing 1 required positional argument: 'token' HOT 3
- Support db statements
- How to implement field based access as mentioned in the docs? HOT 1
- Include additional information in permission denied response HOT 1
- Order of inheritance of AccessViewSetMixin in Viewset matters? HOT 1
- Enforce access policy through PrimaryKeyRelatedField HOT 3
- FieldAccessMixin with read_only=True serializer requires request attribute HOT 2
- Documentation webpage doesn't work HOT 1
- Documentation bug: reusable conditions method should not use "self". HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drf-access-policy.