move avail accounts mixin to account mixins file. Add avail accounts mixin to Connection viewsets

This commit is contained in:
DJ Gillespie 2024-07-31 19:21:08 -06:00
parent 1411fbdf53
commit 20aa85bf08

15
qrtr_account/mixins.py Normal file
View File

@ -0,0 +1,15 @@
from django.db.models import Q
from qrtr_account.models import Account
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
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