aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/api
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-04-21 14:32:05 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-04-22 10:51:12 +0200
commit2531887d45e5469fec6171fbd0c63058ded33136 (patch)
treed70ef91ffeb819a9dde302c06a98596f9e88ad52 /pyaggr3g470r/views/api
parentbetter title handling (diff)
downloadnewspipe-2531887d45e5469fec6171fbd0c63058ded33136.tar.gz
newspipe-2531887d45e5469fec6171fbd0c63058ded33136.tar.bz2
newspipe-2531887d45e5469fec6171fbd0c63058ded33136.zip
making admin able to update all other users feed
Diffstat (limited to 'pyaggr3g470r/views/api')
-rw-r--r--pyaggr3g470r/views/api/article.py3
-rw-r--r--pyaggr3g470r/views/api/common.py7
-rw-r--r--pyaggr3g470r/views/api/feed.py21
3 files changed, 23 insertions, 8 deletions
diff --git a/pyaggr3g470r/views/api/article.py b/pyaggr3g470r/views/api/article.py
index c3ec2d34..516eef8f 100644
--- a/pyaggr3g470r/views/api/article.py
+++ b/pyaggr3g470r/views/api/article.py
@@ -11,7 +11,8 @@ from pyaggr3g470r.views.api.common import PyAggAbstractResource,\
PyAggResourceMulti
-ARTICLE_ATTRS = {'feed_id': {'type': str},
+ARTICLE_ATTRS = {'user_id': {'type': int},
+ 'feed_id': {'type': int},
'entry_id': {'type': str},
'link': {'type': str},
'title': {'type': str},
diff --git a/pyaggr3g470r/views/api/common.py b/pyaggr3g470r/views/api/common.py
index b8477d4b..ca344c04 100644
--- a/pyaggr3g470r/views/api/common.py
+++ b/pyaggr3g470r/views/api/common.py
@@ -51,7 +51,8 @@ def authenticate(func):
# authentication via HTTP only
auth = request.authorization
if auth is not None:
- user = User.query.filter(User.nickname == auth.username).first()
+ user = User.query.filter(
+ User.nickname == auth.username).first()
if user and user.check_password(auth.password) \
and user.activation_key == "":
g.user = user
@@ -61,6 +62,7 @@ def authenticate(func):
raise Unauthorized({'WWWAuthenticate': 'Basic realm="Login Required"'})
return wrapper
+
def to_response(func):
"""Will cast results of func as a result, and try to extract
a status_code for the Response object"""
@@ -158,7 +160,8 @@ class PyAggResourceMulti(PyAggAbstractResource):
return [res for res in self.controller.read().limit(limit)]
if not limit:
return [res for res in self.controller.read(**request.json).all()]
- return [res for res in self.controller.read(**request.json).limit(limit)]
+ return [res
+ for res in self.controller.read(**request.json).limit(limit)]
def post(self):
"""creating several objects. payload should be a list of dict.
diff --git a/pyaggr3g470r/views/api/feed.py b/pyaggr3g470r/views/api/feed.py
index 7d0e2862..ad185de9 100644
--- a/pyaggr3g470r/views/api/feed.py
+++ b/pyaggr3g470r/views/api/feed.py
@@ -3,8 +3,10 @@
from flask import g
-from pyaggr3g470r.controllers.feed import FeedController, \
- DEFAULT_MAX_ERROR, DEFAULT_LIMIT
+from pyaggr3g470r.controllers.feed import (FeedController,
+ DEFAULT_MAX_ERROR,
+ DEFAULT_LIMIT,
+ DEFAULT_REFRESH_RATE)
from pyaggr3g470r.views.api.common import PyAggAbstractResource, \
PyAggResourceNew, \
@@ -41,11 +43,20 @@ class FetchableFeedAPI(PyAggAbstractResource):
controller_cls = FeedController
to_date = ['date', 'last_retrieved']
attrs = {'max_error': {'type': int, 'default': DEFAULT_MAX_ERROR},
- 'limit': {'type': int, 'default': DEFAULT_LIMIT}}
+ 'limit': {'type': int, 'default': DEFAULT_LIMIT},
+ 'refresh_rate': {'type': int, 'default': DEFAULT_REFRESH_RATE},
+ 'retreive_all': {'type': bool, 'default': False}}
def get(self):
- return [feed for feed in self.controller.list_fetchable(
- **self.reqparse_args())]
+ args = self.reqparse_args()
+ if g.user.refresh_rate:
+ args['refresh_rate'] = g.user.refresh_rate
+
+ dont_filter_by_user = args.pop('retreive_all') and g.user.is_admin()
+
+ contr = self.controller_cls() if dont_filter_by_user \
+ else self.controller
+ return [feed for feed in contr.list_fetchable(**args)]
g.api.add_resource(FeedNewAPI, '/feed', endpoint='feed_new.json')
g.api.add_resource(FeedAPI, '/feed/<int:obj_id>', endpoint='feed.json')
bgstack15