Skip to content

Commit

Permalink
Added Dashboard to User owned resources GET API (#128)
Browse files Browse the repository at this point in the history
* Added Dashboard on User OWNED resources GET API

* Increment version

* Update

* Update
  • Loading branch information
jinhyukchang authored Apr 16, 2020
1 parent 8bf5a0b commit f919fcd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions metadata_service/api/swagger_doc/user/own_get.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ responses:
type: array
items:
$ref: '#/components/schemas/PopularTables'
dashboard:
type: array
items:
$ref: '#/components/schemas/DashboardSummary'
404:
description: 'User not found'
content:
Expand Down
20 changes: 17 additions & 3 deletions metadata_service/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,25 @@ def get(self, user_id: str) -> Iterable[Union[Mapping, int, None]]:
:return:
"""
try:
table_key = ResourceType.Table.name.lower()
dashboard_key = ResourceType.Dashboard.name.lower()
result = {
table_key: [],
dashboard_key: []
} # type: Dict[str, List[Any]]

resources = self.client.get_table_by_user_relation(user_email=user_id,
relation_type=UserResourceRel.own)
if len(resources['table']) > 0:
return {'table': PopularTableSchema(many=True).dump(resources['table']).data}, HTTPStatus.OK
return {'table': []}, HTTPStatus.OK
if resources and table_key in resources and len(resources[table_key]) > 0:
result[table_key] = PopularTableSchema(many=True).dump(resources[table_key]).data

resources = self.client.get_dashboard_by_user_relation(user_email=user_id,
relation_type=UserResourceRel.own)

if resources and dashboard_key in resources and len(resources[dashboard_key]) > 0:
result[dashboard_key] = DashboardSummarySchema(many=True).dump(resources[dashboard_key]).data

return result, HTTPStatus.OK

except NotFoundException:
return {'message': 'user_id {} does not exist'.format(user_id)}, HTTPStatus.NOT_FOUND
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '2.4.3'
__version__ = '2.4.4'


requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/api/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ def setUp(self, mock_get_proxy_client: MagicMock) -> None:

def test_get(self) -> None:
self.mock_client.get_table_by_user_relation.return_value = {'table': []}
self.mock_client.get_dashboard_by_user_relation.return_value = {'dashboard': []}
response = self.api.get(user_id='username')
self.assertEqual(list(response)[1], HTTPStatus.OK)
self.mock_client.get_table_by_user_relation.assert_called_once()
self.mock_client.get_dashboard_by_user_relation.assert_called_once()


class UserOwnAPITest(unittest.TestCase):
Expand Down

0 comments on commit f919fcd

Please sign in to comment.