From 62b3afeeedfe054345f86093e2d243e956c1e3c9 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 26 Feb 2020 11:27:31 +0100 Subject: The project is now using Poetry. --- src/web/views/api/v3/__init__.py | 3 -- src/web/views/api/v3/article.py | 84 ------------------------------ src/web/views/api/v3/common.py | 109 --------------------------------------- src/web/views/api/v3/feed.py | 58 --------------------- 4 files changed, 254 deletions(-) delete mode 100644 src/web/views/api/v3/__init__.py delete mode 100644 src/web/views/api/v3/article.py delete mode 100644 src/web/views/api/v3/common.py delete mode 100644 src/web/views/api/v3/feed.py (limited to 'src/web/views/api/v3') diff --git a/src/web/views/api/v3/__init__.py b/src/web/views/api/v3/__init__.py deleted file mode 100644 index 76aa1f19..00000000 --- a/src/web/views/api/v3/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from web.views.api.v3 import article - -__all__ = ['article'] diff --git a/src/web/views/api/v3/article.py b/src/web/views/api/v3/article.py deleted file mode 100644 index 4cf35648..00000000 --- a/src/web/views/api/v3/article.py +++ /dev/null @@ -1,84 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Newspipe - A Web based news aggregator. -# Copyright (C) 2010-2018 Cédric Bonhomme - https://www.cedricbonhomme.org -# -# For more information : http://gitlab.com/newspipe/newspipe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see - -__author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.1 $" -__date__ = "$Date: 2016/04/29 $" -__revision__ = "$Date: 2016/04/29 $" -__copyright__ = "Copyright (c) Cedric Bonhomme" -__license__ = "GPLv3" - -from flask_login import current_user -from werkzeug.exceptions import NotFound -from flask_restless import ProcessingException -from web import models -from bootstrap import application, manager -from web.controllers import ArticleController, FeedController -from web.views.api.v3.common import AbstractProcessor -from web.views.api.v3.common import url_prefix, auth_func - -class ArticleProcessor(AbstractProcessor): - """Concrete processors for the Article Web service. - """ - - def get_single_preprocessor(self, instance_id=None, **kw): - try: - article = ArticleController(current_user.id).get(id=instance_id) - except NotFound: - raise ProcessingException(description='No such article.', code=404) - self.is_authorized(current_user, article) - - def post_preprocessor(self, data=None, **kw): - data["user_id"] = current_user.id - - try: - feed = FeedController(current_user.id).get(id=data["feed_id"]) - except NotFound: - raise ProcessingException(description='No such feed.', code=404) - self.is_authorized(current_user, feed) - - data["category_id"] = feed.category_id - - def delete_preprocessor(self, instance_id=None, **kw): - try: - article = ArticleController(current_user.id).get(id=instance_id) - except NotFound: - raise ProcessingException(description='No such article.', code=404) - self.is_authorized(current_user, article) - -article_processor = ArticleProcessor() - -blueprint_article = manager.create_api_blueprint(models.Article, - url_prefix=url_prefix, - methods=['GET', 'POST', 'PUT', 'DELETE'], - preprocessors=dict(GET_SINGLE=[auth_func, - article_processor.get_single_preprocessor], - GET_MANY=[auth_func, - article_processor.get_many_preprocessor], - POST=[auth_func, - article_processor.post_preprocessor], - PUT_SINGLE=[auth_func, - article_processor.put_single_preprocessor], - PUT_MANY=[auth_func, - article_processor.put_many_preprocessor], - DELETE=[auth_func, - article_processor.delete_preprocessor])) -application.register_blueprint(blueprint_article) diff --git a/src/web/views/api/v3/common.py b/src/web/views/api/v3/common.py deleted file mode 100644 index d5e94a3f..00000000 --- a/src/web/views/api/v3/common.py +++ /dev/null @@ -1,109 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Newspipe - A Web based news aggregator. -# Copyright (C) 2010-2018 Cédric Bonhomme - https://www.cedricbonhomme.org -# -# For more information : http://gitlab.com/newspipe/newspipe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see - -__author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.1 $" -__date__ = "$Date: 2016/04/29 $" -__revision__ = "$Date: 2016/04/29 $" -__copyright__ = "Copyright (c) Cedric Bonhomme" -__license__ = "GPLv3" - -from flask import request -from flask_login import current_user -from flask_restless import ProcessingException -from werkzeug.exceptions import NotFound -from web.controllers import ArticleController, UserController -from web.views.common import login_user_bundle - -url_prefix = '/api/v3' - -def auth_func(*args, **kw): - if request.authorization: - ucontr = UserController() - try: - user = ucontr.get(nickname=request.authorization.username) - except NotFound: - raise ProcessingException("Couldn't authenticate your user", - code=401) - if not ucontr.check_password(user, request.authorization.password): - raise ProcessingException("Couldn't authenticate your user", - code=401) - if not user.is_active: - raise ProcessingException("User is deactivated", code=401) - login_user_bundle(user) - if not current_user.is_authenticated: - raise ProcessingException(description='Not authenticated!', code=401) - -class AbstractProcessor(): - """Abstract processors for the Web services. - """ - - def is_authorized(self, user, obj): - if user.id != obj.user_id: - raise ProcessingException(description='Not Authorized', code=401) - - def get_single_preprocessor(self, instance_id=None, **kw): - # Check if the user is authorized to modify the specified - # instance of the model. - pass - - def get_many_preprocessor(self, search_params=None, **kw): - """Accepts a single argument, `search_params`, which is a dictionary - containing the search parameters for the request. - """ - filt = dict(name="user_id", - op="eq", - val=current_user.id) - - # Check if there are any filters there already. - if "filters" not in search_params: - search_params["filters"] = [] - - search_params["filters"].append(filt) - - def post_preprocessor(self, data=None, **kw): - pass - - def put_single_preprocessor(instance_id=None, data=None, **kw): - """Accepts two arguments, `instance_id`, the primary key of the - instance of the model to patch, and `data`, the dictionary of fields - to change on the instance. - """ - pass - - def put_many_preprocessor(search_params=None, data=None, **kw): - """Accepts two arguments: `search_params`, which is a dictionary - containing the search parameters for the request, and `data`, which - is a dictionary representing the fields to change on the matching - instances and the values to which they will be set. - """ - filt = dict(name="user_id", - op="eq", - val=current_user.id) - - # Check if there are any filters there already. - if "filters" not in search_params: - search_params["filters"] = [] - - search_params["filters"].append(filt) - - def delete_preprocessor(self, instance_id=None, **kw): - pass diff --git a/src/web/views/api/v3/feed.py b/src/web/views/api/v3/feed.py deleted file mode 100644 index 2cbbafd9..00000000 --- a/src/web/views/api/v3/feed.py +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -# Newspipe - A Web based news aggregator. -# Copyright (C) 2010-2018 Cédric Bonhomme - https://www.cedricbonhomme.org -# -# For more information : http://gitlab.com/newspipe/newspipe -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see - -__author__ = "Cedric Bonhomme" -__version__ = "$Revision: 0.1 $" -__date__ = "$Date: 2016/04/29 $" -__revision__ = "$Date: 2016/04/29 $" -__copyright__ = "Copyright (c) Cedric Bonhomme" -__license__ = "GPLv3" - -from flask_login import current_user -from web import models -from bootstrap import application, manager -from web.controllers import FeedController -from web.views.api.v3.common import AbstractProcessor -from web.views.api.v3.common import url_prefix, auth_func - -class FeedProcessor(AbstractProcessor): - """Concrete processors for the Feed Web service. - """ - - def get_single_preprocessor(self, instance_id=None, **kw): - # Check if the user is authorized to modify the specified - # instance of the model. - feed = FeedController(current_user.id).get(id=instance_id) - self.is_authorized(current_user, feed) - -feed_processor = FeedProcessor() - -blueprint_feed = manager.create_api_blueprint(models.Feed, - url_prefix=url_prefix, - methods=['GET', 'POST', 'PUT', 'DELETE'], - preprocessors=dict(GET_SINGLE=[auth_func, - feed_processor.get_single_preprocessor], - GET_MANY=[auth_func, - feed_processor.get_many_preprocessor], - PUT_SINGLE=[auth_func], - POST=[auth_func], - DELETE=[auth_func])) -application.register_blueprint(blueprint_feed) -- cgit