Commit 66a2262e authored by ibuler's avatar ibuler

[Fixture] 增加 asset groups assets api

parent 067426d5
......@@ -198,22 +198,35 @@ class MyAssetGroupAssetsApi(ListAPIView):
def get(self, request, *args, **kwargs):
asset_groups = {}
# asset_group = {1: {'id': 1, 'name': 'hello', 'assets': set(),
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:
assets = get_user_granted_assets(user)
for asset in assets:
for asset, system_users in assets.items():
asset_json = asset.to_json()
asset_json['system_users'] = [su.to_json() for su in system_users]
if not asset.groups.all():
asset_groups[0][assets].append(asset_json)
continue
for asset_group in asset.groups.all():
if asset_group.id in asset_groups:
asset_groups[asset_group.id]['assets'].add(asset.to_json())
asset_groups[asset_group.id]['assets'].append(asset_json)
else:
asset_groups[asset_group.id] = {
'id': asset_group.id,
'name': asset_group.name,
'comment': asset_group.comment,
'assets': {asset.to_json()},
'assets': [asset_json],
}
asset_groups_json = asset_groups.values()
return Response(asset_groups_json, status=200)
......
......@@ -19,12 +19,12 @@ urlpatterns = [
url(r'^v1/user/my/asset-groups/$',
api.MyGrantedAssetsGroupsApi.as_view(),
name='my-asset-groups'),
url(r'^v1/user/my/asset-groups-assets/$',
api.MyAssetGroupAssetsApi.as_view(),
name='my-asset-group-assets'),
url(r'^v1/user/my/asset-group/(?P<pk>[0-9]+)/assets/$',
api.MyAssetGroupOfAssetsApi.as_view(),
name='my-asset-group-of-assets'),
url(r'^v1/user/my/asset-group-assets/$',
api.MyAssetGroupAssetsApi.as_view(),
name='my-asset-group-assets'),
# 查询某个用户授权的资产和资产组
url(r'^v1/user/(?P<pk>[0-9]+)/assets/$',
......
......@@ -28,7 +28,7 @@
<div class="ibox-content">
<div class="alert alert-success" id="messages">
{% trans 'Welcome to use jumpserver, visit ' %}
<a href="{{ user_guide_url }}">{% trans 'Use guide' %}</a> {% trans ' for more information' %}
<a href="{{ user_guide_url }}" target="_blank">{% trans 'Use guide' %}</a> {% trans ' for more information' %}
</div>
</div>
</div>
......
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