Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

subreddit: Error on invalid revision.

  • Loading branch information...
commit 809b2e62d2984d521f8d2941bdd7a4872a9e0f28 1 parent 441ee6c
@andre-d authored
View
22 r2/r2/controllers/api.py
@@ -1274,11 +1274,9 @@ def POST_subreddit_stylesheet(self, form, jquery,
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 @@ def POST_site_admin(self, form, jquery, name, ip, sr,
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 @@ def apply_wikid_field(sr, form, pagename, value, prev, field, error):
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 @@ def apply_wikid_field(sr, form, pagename, value, prev, field, error):
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
View
1  r2/r2/controllers/errors.py
@@ -92,6 +92,7 @@
('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')),
View
2  r2/r2/templates/createsubreddit.html
@@ -99,6 +99,8 @@
<input type="hidden" name="prev_description_id" value="${thing.site.prev_description_id}"/>
${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')}">
View
1  r2/r2/templates/subredditstylesheet.html
@@ -43,6 +43,7 @@
<h2>${_("stylesheet")}</h2>
<input type="hidden" name="prevstyle" value="${thing.site.prev_stylesheet}"/>
${error_field("TOO_LONG", "prevstyle")}
+ ${error_field("BAD_REVISION", "prevstyle")}
<div class="sheets">
<div style="width: 100%" class="col">
<div>
Please sign in to comment.
Something went wrong with that request. Please try again.