Python flask_sqlalchemy.BaseQuery() Examples

The following are 6 code examples of flask_sqlalchemy.BaseQuery(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask_sqlalchemy , or try the search function .
Example #1
Source File: __init__.py    From timesketch with Apache License 2.0 6 votes vote down vote up
def get_with_acl(self, model_id, user=current_user):
        """Get a database object with permission check enforced.

        Args:
            model_id: The integer ID of the model to get.
            user: User (instance of timesketch.models.user.User)

        Returns:
            A BaseQuery instance.
        """
        result_obj = self.get(model_id)
        if not result_obj:
            abort(HTTP_STATUS_CODE_NOT_FOUND)
        try:
            if result_obj.get_status.status == 'deleted':
                abort(HTTP_STATUS_CODE_NOT_FOUND)
        except AttributeError:
            pass
        if result_obj.is_public:
            return result_obj
        if not result_obj.has_permission(user=user, permission='read'):
            abort(HTTP_STATUS_CODE_FORBIDDEN)
        return result_obj 
Example #2
Source File: __init__.py    From flask-restplus-server-example with MIT License 5 votes vote down vote up
def get_query_class(cls):
        """
        Returns extended BaseQuery class for flask_sqlalchemy model to provide get_or_403 method

        Example:
        >>> DataTransformation(db.Model):
        ...     query_class = OwnerRolePermission.get_query_class()
        """
        return lambda *args, **kwargs: PermissionExtendedQuery(cls, *args, **kwargs) 
Example #3
Source File: test_drop_point.py    From c3bottles with MIT License 5 votes vote down vote up
def test_reports_are_query(self):
        assert isinstance(self.dp.reports, BaseQuery) 
Example #4
Source File: test_drop_point.py    From c3bottles with MIT License 5 votes vote down vote up
def test_visits_are_query(self):
        assert isinstance(self.dp.visits, BaseQuery) 
Example #5
Source File: sql_lab.py    From incubator-superset with Apache License 2.0 5 votes vote down vote up
def apply(self, query: BaseQuery, value: Any) -> BaseQuery:
        """
        Filter queries to only those owned by current user. If
        can_access_all_queries permission is set a user can list all queries

        :returns: query
        """
        if not security_manager.can_access_all_queries():
            query = query.filter(Query.user_id == g.user.get_user_id())
        return query 
Example #6
Source File: filters.py    From incubator-superset with Apache License 2.0 5 votes vote down vote up
def apply(self, query: BaseQuery, value: Any) -> BaseQuery:
        """
        Filter queries to only those owned by current user. If
        can_access_all_queries permission is set a user can list all queries

        :returns: query
        """
        if not security_manager.can_access_all_queries():
            query = query.filter(Query.user_id == g.user.get_user_id())
        return query