From 8f4418c2b0b1027032594bf8d02e68bcc0ad6316 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 19 Apr 2016 22:10:52 +0200 Subject: Added a blueprint for the Flask-Restless feed api. --- src/web/views/api/v3/common.py | 52 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'src/web/views/api/v3/common.py') diff --git a/src/web/views/api/v3/common.py b/src/web/views/api/v3/common.py index 84e1f104..9ff7d96e 100644 --- a/src/web/views/api/v3/common.py +++ b/src/web/views/api/v3/common.py @@ -1,38 +1,32 @@ from flask.ext.login import current_user from flask.ext.restless import ProcessingException -from web.controllers import ArticleController - url_prefix = '/api/v3' - -def is_authorized_to_modify(user, obj): - return user.id == obj.user_id - def auth_func(*args, **kw): if not current_user.is_authenticated: raise ProcessingException(description='Not authenticated!', code=401) -def get_single_preprocessor(instance_id=None, **kw): - # Check if the user is authorized to modify the specified - # instance of the model. - contr = ArticleController(current_user.id) - article = contr.get(id=instance_id) - if not is_authorized_to_modify(current_user, article): - raise ProcessingException(description='Not Authorized', - code=401) - -def get_many_preprocessor(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) +class AbstractProcessor(): + + def is_authorized_to_modify(self, user, obj): + return user.id == obj.user_id + + 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) -- cgit