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 08:26:18 +00:00
|
|
|
<<<<<<< HEAD
|
2022-11-04 10:46:49 +00:00
|
|
|
from common.utils import get_logger, lazyproperty
|
2022-11-15 08:26:18 +00:00
|
|
|
=======
|
2022-11-15 08:07:42 +00:00
|
|
|
from common.exceptions import JMSObjectDoesNotExist
|
|
|
|
from common.utils import get_logger, lazyproperty, is_uuid
|
2022-11-15 08:26:18 +00:00
|
|
|
>>>>>>> 0d3c5dddf9c838c5dcd28c20b6a8498088e45ce2
|
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__ = [
|
|
|
|
'UserGrantedAssetAccountsApi',
|
|
|
|
]
|
2022-11-03 08:41:51 +00:00
|
|
|
|
|
|
|
|
2022-11-15 08:24:53 +00:00
|
|
|
class UserGrantedAssetAccountsApi(SelfOrPKUserMixin, ListAPIView):
|
2022-11-04 10:46:49 +00:00
|
|
|
serializer_class = serializers.AccountsGrantedSerializer
|
2022-11-15 07:26:31 +00:00
|
|
|
rbac_perms = (
|
2022-11-15 08:07:42 +00:00
|
|
|
('GET', 'perms.view_userassets'),
|
2022-11-15 07:26:31 +00:00
|
|
|
('list', 'perms.view_userassets'),
|
|
|
|
)
|
2022-11-04 10:46:49 +00:00
|
|
|
|
|
|
|
@lazyproperty
|
2022-11-15 08:26:18 +00:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
2022-11-04 10:46:49 +00:00
|
|
|
def user(self) -> User:
|
2022-11-15 08:07:42 +00:00
|
|
|
query_user = self.kwargs.get('user')
|
|
|
|
if is_uuid(query_user):
|
|
|
|
user = User.objects.get(id=query_user)
|
|
|
|
elif query_user == 'my':
|
|
|
|
user = self.request.user
|
|
|
|
else:
|
|
|
|
raise JMSObjectDoesNotExist(object_name=_('User'))
|
|
|
|
return user
|
2022-11-04 10:46:49 +00:00
|
|
|
|
|
|
|
@lazyproperty
|
2022-11-15 08:26:18 +00:00
|
|
|
>>>>>>> 0d3c5dddf9c838c5dcd28c20b6a8498088e45ce2
|
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
|