Commit 3639b190 authored by ibuler's avatar ibuler

Update perm api

parent 034f0a02
......@@ -89,9 +89,8 @@ class Asset(models.Model):
date_created = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name=_('Date created'))
comment = models.TextField(max_length=128, default='', blank=True, verbose_name=_('Comment'))
def __unicode__(self):
def __str__(self):
return '%s <%s: %s>' % (self.hostname, self.ip, self.port)
__str__ = __unicode__
@property
def is_valid(self):
......
......@@ -140,11 +140,25 @@ class UserGrantedAssetGroupsApi(ListAPIView):
def get_queryset(self):
user_id = self.kwargs.get('pk', '')
if user_id:
user = get_object_or_404(User, id=user_id)
queryset = get_user_granted_asset_groups(user)
else:
queryset = []
if not user_id:
return []
user = get_object_or_404(User, id=user_id)
if user:
asset_groups = {}
for asset, system_ in get_user_granted_assets(user).items():
for asset_group in asset.groups.all():
if asset_group.id in asset_groups:
asset_groups[asset_group.id]['assets_amount'] += 1
else:
asset_groups[asset_group.id] = {
'id': asset_group.id,
'name': asset_group.name,
'comment': asset_group.comment,
'assets_amount': 1
}
asset_groups_json = asset_groups.values()
return queryset
......@@ -166,10 +180,11 @@ class MyGrantedAssetsApi(ListAPIView):
return queryset
class MyGrantedAssetsGroupsApi(APIView):
"""授权给用户的资产组列表, 非直接通过授权规则授权的资产组列表, 而是授权资产的所有
资产组之和"""
"""
授权给用户的资产组列表, 非直接通过授权规则授权的资产组列表, 而是授权资产的所有
资产组之和
"""
permission_classes = (IsValidUser,)
def get(self, request, *args, **kwargs):
......@@ -201,13 +216,6 @@ class MyAssetGroupAssetsApi(ListAPIView):
asset_groups[0] = {
'id': 0, 'name': 'ungrouped', 'assets': []
}
# asset_group = {
# 1: {'id': 1, 'name': 'hello',
# 'assets': [{
# 'id': 'asset_id',
# 'system_users': [{'id': 'system_user_id',...},]
# }],
# 'assets_id': set()}, 2: {}}
user = request.user
if user:
......
......@@ -190,6 +190,11 @@ def get_user_granted_assets(user):
return assets
def get_user_granted_asset_groups(user):
pass
def get_user_group_asset_permissions(user_group):
permissions = user_group.asset_permissions.all()
return permissions
......
......@@ -167,7 +167,6 @@ def generate_token(request, user):
token = cache.get('%s_%s' % (user.id, remote_addr))
if not token:
token = uuid.uuid4().hex
print('Set cache: %s' % token)
cache.set(token, user.id, expiration)
cache.set('%s_%s' % (user.id, remote_addr), token, expiration)
return token
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment