diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-02-26 15:20:54 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2020-02-26 15:20:54 +0100 |
commit | c0d48f8a060fa30107183ad024e8c03cfee0eb26 (patch) | |
tree | e1aab8c092be0c2bd1e51d6ac09187096490652f /newspipe/web/views/api/v3/common.py | |
parent | Removed sendgrid dependency. (diff) | |
download | newspipe-c0d48f8a060fa30107183ad024e8c03cfee0eb26.tar.gz newspipe-c0d48f8a060fa30107183ad024e8c03cfee0eb26.tar.bz2 newspipe-c0d48f8a060fa30107183ad024e8c03cfee0eb26.zip |
added a little black magic
Diffstat (limited to 'newspipe/web/views/api/v3/common.py')
-rw-r--r-- | newspipe/web/views/api/v3/common.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/newspipe/web/views/api/v3/common.py b/newspipe/web/views/api/v3/common.py index d5e94a3f..5467ee30 100644 --- a/newspipe/web/views/api/v3/common.py +++ b/newspipe/web/views/api/v3/common.py @@ -33,7 +33,8 @@ from werkzeug.exceptions import NotFound from web.controllers import ArticleController, UserController from web.views.common import login_user_bundle -url_prefix = '/api/v3' +url_prefix = "/api/v3" + def auth_func(*args, **kw): if request.authorization: @@ -41,24 +42,23 @@ def auth_func(*args, **kw): try: user = ucontr.get(nickname=request.authorization.username) except NotFound: - raise ProcessingException("Couldn't authenticate your user", - code=401) + 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) + 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) + raise ProcessingException(description="Not authenticated!", code=401) + -class AbstractProcessor(): +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) + 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 @@ -69,13 +69,11 @@ class AbstractProcessor(): """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) + 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"] = [] search_params["filters"].append(filt) @@ -95,13 +93,11 @@ class AbstractProcessor(): 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) + 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"] = [] search_params["filters"].append(filt) |