From ef5cc6091037b4a9231a90e4bdd52e262dc33286 Mon Sep 17 00:00:00 2001 From: bsimpson63 Date: Thu, 16 May 2013 09:15:29 -0400 Subject: [PATCH] When adding to multi check for special subreddits and bail out. --- r2/r2/controllers/multi.py | 14 ++++++++++++++ r2/r2/lib/errors.py | 1 + 2 files changed, 15 insertions(+) diff --git a/r2/r2/controllers/multi.py b/r2/r2/controllers/multi.py index 22daba0d4..594b93bfd 100644 --- a/r2/r2/controllers/multi.py +++ b/r2/r2/controllers/multi.py @@ -30,6 +30,7 @@ from r2.controllers.oauth2 import ( require_oauth2_scope, ) from r2.models.subreddit import ( + FakeSubreddit, Subreddit, LabeledMulti, TooManySubredditsException, @@ -115,6 +116,14 @@ class MultiApiController(RedditController, OAuth2ResourceController): if 'subreddits' in data: multi.clear_srs() srs = Subreddit._by_name(sr['name'] for sr in data['subreddits']) + + for sr in srs.itervalues(): + if isinstance(sr, FakeSubreddit): + multi._revert() + raise RedditError('MULTI_SPECIAL_SUBREDDIT', + msg_params={'path': sr.path}, + code=400) + sr_props = {} for sr_data in data['subreddits']: try: @@ -174,6 +183,11 @@ class MultiApiController(RedditController, OAuth2ResourceController): def PUT_multi_subreddit(self, multi, sr): """Add a subreddit to a multi.""" + if isinstance(sr, FakeSubreddit): + raise RedditError('MULTI_SPECIAL_SUBREDDIT', + msg_params={'path': sr.path}, + code=400) + try: multi.add_srs({sr: {}}) except TooManySubredditsException as e: diff --git a/r2/r2/lib/errors.py b/r2/r2/lib/errors.py index 5316cc0e8..14450b390 100644 --- a/r2/r2/lib/errors.py +++ b/r2/r2/lib/errors.py @@ -126,6 +126,7 @@ error_list = dict(( ('MULTI_NOT_FOUND', _('that multireddit doesn\'t exist')), ('MULTI_CANNOT_EDIT', _('you can\'t change that multireddit')), ('MULTI_TOO_MANY_SUBREDDITS', _('no more space for subreddits in that multireddit')), + ('MULTI_SPECIAL_SUBREDDIT', _("can't add special subreddit %(path)s")), ('BAD_JSON', _('unable to parse JSON data')), ))