예제 #1
0
def marshall_dashboard_partial(dashboard_dict: Dict) -> Dict:
    """
    Forms a short version of dashboard metadata, with selected fields and an added 'key'
    and 'type'
    :param dashboard_dict: Dict of partial dashboard metadata
    :return: partial dashboard Dict
    """
    schema = DashboardSummarySchema(strict=True)
    dashboard: DashboardSummary = schema.load(dashboard_dict).data
    results = schema.dump(dashboard).data
    results['type'] = 'dashboard'
    # TODO: Bookmark logic relies on key, opting to add this here to avoid messy logic in
    # React app and we have to clean up later.
    results['key'] = results.get('uri', '')
    return results
예제 #2
0
    def get(self, user_id: str) -> Iterable[Union[Mapping, int, None]]:
        """
        Return a list of resources that user has followed

        :param user_id:
        :return:
        """
        try:
            resources = self.client.get_table_by_user_relation(user_email=user_id,
                                                               relation_type=UserResourceRel.follow)

            table_key = ResourceType.Table.name.lower()
            dashboard_key = ResourceType.Dashboard.name.lower()
            result = {
                table_key: [],
                dashboard_key: []
            }  # type: Dict[str, List[Any]]

            if resources and table_key in resources and len(resources[table_key]) > 0:
                result[table_key] = PopularTableSchema().dump(resources[table_key], many=True)

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

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

            return result, HTTPStatus.OK

        except NotFoundException:
            return {'message': 'user_id {} does not exist'.format(user_id)}, HTTPStatus.NOT_FOUND

        except Exception:
            LOGGER.exception('UserFollowAPI GET Failed')
            return {'message': 'Internal server error!'}, HTTPStatus.INTERNAL_SERVER_ERROR
예제 #3
0
    def get(self,
            user_id: Optional[str] = None
            ) -> Iterable[Union[Mapping, int, None]]:
        limit = request.args.get('limit', 10, type=int)
        resource_types = request.args.get('types', 'table', type=str)
        resource_types = resource_types.split(',')
        popular_resources: Dict = {}
        try:
            popular_resources = self.client.get_popular_resources(
                num_entries=limit,
                resource_types=resource_types,
                user_id=user_id)
        except NotImplementedError:
            print_deprecation_warning(
                '"/popular_tables/" endpoint and "get_popular_tables()" proxy method '
                'have been deprecated since version (3.6.0),'
                'and will be removed in version 4. '
                'Please use /popular_resources/ endpoint instead.')
            popular_resources[
                ResourceType.Table.name] = self.client.get_popular_tables(
                    num_entries=limit, user_id=user_id)

        response: dict = dict()
        response[ResourceType.Table.name] = TableSummarySchema().dump(
            popular_resources.get(ResourceType.Table.name), many=True)
        response[ResourceType.Dashboard.name] = DashboardSummarySchema().dump(
            popular_resources.get(ResourceType.Dashboard.name), many=True)
        return response, HTTPStatus.OK