aboutsummaryrefslogtreecommitdiff
path: root/src/web/controllers/article.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/controllers/article.py')
-rw-r--r--src/web/controllers/article.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/web/controllers/article.py b/src/web/controllers/article.py
index bc9ef36e..8c6952cb 100644
--- a/src/web/controllers/article.py
+++ b/src/web/controllers/article.py
@@ -6,7 +6,7 @@ from collections import Counter
from bootstrap import db
from .abstract import AbstractController
-from web.controllers import FeedController
+from web.controllers import CategoryController, FeedController
from web.models import Article
logger = logging.getLogger(__name__)
@@ -35,11 +35,12 @@ class ArticleController(AbstractController):
def create(self, **attrs):
# handling special denorm for article rights
- assert 'feed_id' in attrs
+ assert 'feed_id' in attrs, "must provide feed_id when creating article"
feed = FeedController(
attrs.get('user_id', self.user_id)).get(id=attrs['feed_id'])
if 'user_id' in attrs:
- assert feed.user_id == attrs['user_id'] or self.user_id is None
+ assert feed.user_id == attrs['user_id'] or self.user_id is None, \
+ "no right on feed %r" % feed.id
attrs['user_id'], attrs['category_id'] = feed.user_id, feed.category_id
# handling feed's filters
@@ -66,6 +67,17 @@ class ArticleController(AbstractController):
return super().create(**attrs)
+ def update(self, filters, attrs):
+ user_id = attrs.get('user_id', self.user_id)
+ if 'feed_id' in attrs:
+ feed = FeedController().get(id=attrs['feed_id'])
+ assert feed.user_id == user_id, "no right on feed %r" % feed.id
+ attrs['category_id'] = feed.category_id
+ if attrs.get('category_id'):
+ cat = CategoryController().get(id=attrs['category_id'])
+ assert cat.user_id == user_id, "no right on cat %r" % cat.id
+ return super().update(filters, attrs)
+
def get_history(self, year=None, month=None):
"""
Sort articles by year and month.
bgstack15