2022-11-04 10:46:49 +00:00
|
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from rest_framework.generics import ListAPIView, get_object_or_404
|
|
|
|
|
2022-11-15 09:49:28 +00:00
|
|
|
from common.utils import get_logger, lazyproperty
|
2022-11-04 10:46:49 +00:00
|
|
|
from perms import serializers
|
2022-11-15 08:24:53 +00:00
|
|
|
from perms.hands import Asset
|
2022-11-04 10:46:49 +00:00
|
|
|
from perms.utils import PermAccountUtil
|
2022-11-15 08:24:53 +00:00
|
|
|
from .mixin import SelfOrPKUserMixin
|
2022-11-03 08:41:51 +00:00
|
|
|
|
2022-11-04 10:46:49 +00:00
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
__all__ = [
|
2022-11-16 03:29:02 +00:00
|
|
|
'UserPermedAssetAccountsApi',
|
2022-11-04 10:46:49 +00:00
|
|
|
]
|
2022-11-03 08:41:51 +00:00
|
|
|
|
|
|
|
|
2022-11-16 03:29:02 +00:00
|
|
|
class UserPermedAssetAccountsApi(SelfOrPKUserMixin, ListAPIView):
|
|
|
|
serializer_class = serializers.AccountsPermedSerializer
|
2022-11-04 10:46:49 +00:00
|
|
|
|
2022-11-15 09:49:28 +00:00
|
|
|
@lazyproperty
|
2022-11-04 10:46:49 +00:00
|
|
|
def asset(self):
|
|
|
|
asset_id = self.kwargs.get('asset_id')
|
|
|
|
kwargs = {'id': asset_id, 'is_active': True}
|
|
|
|
asset = get_object_or_404(Asset, **kwargs)
|
|
|
|
return asset
|
|
|
|
|
|
|
|
def get_queryset(self):
|
2022-11-15 02:43:21 +00:00
|
|
|
util = PermAccountUtil()
|
|
|
|
accounts = util.get_permed_accounts_for_user(self.user, self.asset)
|
2022-11-04 10:46:49 +00:00
|
|
|
return accounts
|