From 5fe3cc30de0b35ed0dec4dd0fe9fd4e0084220da Mon Sep 17 00:00:00 2001 From: Andre D Date: Tue, 25 Sep 2012 04:36:28 -0500 Subject: [PATCH] subreddit: Error on invalid revision. --- r2/r2/controllers/api.py | 22 +++++++++------------- r2/r2/controllers/errors.py | 1 + r2/r2/templates/createsubreddit.html | 2 ++ r2/r2/templates/subredditstylesheet.html | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index b101147b5..5d8c6dff4 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1274,11 +1274,9 @@ class ApiController(RedditController, OAuth2ResourceController): form.set_html('#conflict_diff', e.htmldiff) form.find('.errors').show() return - except ValueError: - # Revision does not belong to page - return - except tdb_cassandra.NotFound: - # Previous revision not found + except (tdb_cassandra.NotFound, ValueError): + c.errors.add(errors.BAD_REVISION, field="prevstyle") + form.has_errors("prevstyle", errors.BAD_REVISION) return jquery.apply_stylesheet(stylesheet_contents_parsed) if op == 'preview': @@ -1478,6 +1476,7 @@ class ApiController(RedditController, OAuth2ResourceController): sponsor_text, sponsor_url, sponsor_name, **kw): def apply_wikid_field(sr, form, pagename, value, prev, field, error): + id_field_name = 'prev_%s_id' % field try: wikipage = wiki.WikiPage.get(sr, pagename) except tdb_cassandra.NotFound: @@ -1487,7 +1486,7 @@ class ApiController(RedditController, OAuth2ResourceController): setattr(sr, field, value) if not wr: return True - setattr(sr, "prev_" + field + "_id", str(wikipage.revision)) + setattr(sr, id_field_name, str(wikipage.revision)) ModAction.create(sr, c.user, 'wikirevise', details=wiki.modactions.get(pagename)) return True except ConflictException as e: @@ -1495,14 +1494,11 @@ class ApiController(RedditController, OAuth2ResourceController): form.has_errors(field, errors.CONFLICT) form.parent().set_html('.status', error) form.find('#%s_conflict_box' % field).show() - form.set_inputs(**{'prev_%s_id' % field: e.new_id, '%s_conflict_old' % field: e.your, field: e.new}) + form.set_inputs(**{id_field_name: e.new_id, '%s_conflict_old' % field: e.your, field: e.new}) form.set_html('#%s_conflict_diff' % field, e.htmldiff) - except ValueError: - # Revision does not belong to page - pass - except tdb_cassandra.NotFound: - # Previous revision not found - pass + except (tdb_cassandra.NotFound, ValueError): + c.errors.add(errors.BAD_REVISION, field=id_field_name) + form.has_errors(id_field_name, errors.BAD_REVISION) return False # the status button is outside the form -- have to reset by hand diff --git a/r2/r2/controllers/errors.py b/r2/r2/controllers/errors.py index c215ffb97..f0cea8448 100644 --- a/r2/r2/controllers/errors.py +++ b/r2/r2/controllers/errors.py @@ -92,6 +92,7 @@ error_list = dict(( ('NO_LINKS', _("that reddit only allows text posts")), ('TOO_OLD', _("that's a piece of history now; it's too late to reply to it")), ('BAD_CSS_NAME', _('invalid css name')), + ('BAD_REVISION', _('invalid revision ID')), ('TOO_MUCH_FLAIR_CSS', _('too many flair css classes')), ('BAD_FLAIR_TARGET', _('not a valid flair target')), ('OAUTH2_INVALID_CLIENT', _('invalid client id')), diff --git a/r2/r2/templates/createsubreddit.html b/r2/r2/templates/createsubreddit.html index d33c61914..f0946fae8 100644 --- a/r2/r2/templates/createsubreddit.html +++ b/r2/r2/templates/createsubreddit.html @@ -99,6 +99,8 @@ ${error_field("TOO_LONG", "prev_public_description_id")} ${error_field("TOO_LONG", "prev_description_id")} + ${error_field("BAD_REVISION", "prev_public_description_id")} + ${error_field("BAD_REVISION", "prev_description_id")} %endif <%utils:line_field title="${_('language')}"> diff --git a/r2/r2/templates/subredditstylesheet.html b/r2/r2/templates/subredditstylesheet.html index ff7f65a5a..d391b43aa 100644 --- a/r2/r2/templates/subredditstylesheet.html +++ b/r2/r2/templates/subredditstylesheet.html @@ -43,6 +43,7 @@

${_("stylesheet")}

${error_field("TOO_LONG", "prevstyle")} + ${error_field("BAD_REVISION", "prevstyle")}