mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 00:38:11 -05:00
When adding to multi check for special subreddits and bail out.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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')),
|
||||
))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user