change accessible_accounts to not use unions to allow for all queryset operations to be performed.
This commit is contained in:
parent
8d15f325bb
commit
0d150971f7
@ -1,4 +1,5 @@
|
||||
from django.shortcuts import render
|
||||
from django.db.models import Q
|
||||
from rest_framework import viewsets, mixins
|
||||
from .models import Account, BankAccount, Institution, Transaction, Slice, Rule, SubscriptionPlan
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
@ -18,13 +19,19 @@ from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
||||
from dj_rest_auth.social_serializers import TwitterLoginSerializer
|
||||
from api.mixins import ReadWriteSerializerMixin
|
||||
|
||||
|
||||
class OwnedAccountsMixin():
|
||||
"""Mixin to help getting a list of accounts
|
||||
the given user is authorized to see
|
||||
"""
|
||||
|
||||
def accessible_accounts(self):
|
||||
usr = self.request.user
|
||||
return usr.owned_accounts.all()\
|
||||
.union(usr.admin_accounts.all())\
|
||||
.union(usr.view_accounts.all())
|
||||
accs = Account.objects.filter(Q(owner=usr) |
|
||||
Q(id__in=usr.admin_accounts.all().values_list('id')) |
|
||||
Q(id__in=usr.view_accounts.all().values_list('id')))
|
||||
return accs
|
||||
|
||||
|
||||
class TwitterLogin(SocialLoginView):
|
||||
serializer_class = TwitterLoginSerializer
|
||||
|
||||
Loading…
Reference in New Issue
Block a user