Permalink
Browse files

wiki: Assume force if previous value is None.

This allows clients that don't send the previous IDs to skip conflict detection and update the wikified text fields.
This allows for backwards compatibility, as well as making stylesheet updating not require an extra lookup.
  • Loading branch information...
andre-d committed Sep 20, 2012
1 parent c0ceeda commit bc91f312468ba1c655a713c1d0f09f8fa11a0096
Showing with 21 additions and 8 deletions.
  1. +15 −7 r2/r2/controllers/api.py
  2. +5 −1 r2/r2/controllers/wiki.py
  3. +1 −0 r2/r2/models/wiki.py
View
@@ -1227,7 +1227,12 @@ def POST_subreddit_stylesheet(self, form, jquery,
stylesheet_contents = '', prevstyle='', op='save'):
report, parsed = c.site.parse_css(stylesheet_contents)
-
+
+ # Use the raw POST value as we need to tell the difference between
+ # None/Undefined and an empty string. The validators use a default
+ # value with both of those cases and would need to be changed.
+ # In order to avoid breaking functionality, this was done instead.
+ prevstyle = request.post.get('prevstyle')
if not report:
return self.abort(403,'forbidden')
@@ -1502,17 +1507,20 @@ def apply_wikid_field(sr, form, pagename, value, prev, field, error):
redir = False
kw = dict((k, v) for k, v in kw.iteritems()
if k in ('name', 'title', 'domain', 'description',
- 'prev_description_id', 'prev_public_description_id',
'show_media', 'show_cname_sidebar', 'type', 'link_type', 'lang',
'css_on_cname', 'header_title', 'over_18',
'wikimode', 'wiki_edit_karma', 'wiki_edit_age',
'allow_top', 'public_description'))
-
- description = kw.pop('description')
- prev_desc = kw.pop('prev_description_id')
-
+
public_description = kw.pop('public_description')
- prev_pubdesc = kw.pop('prev_public_description_id')
+ description = kw.pop('description')
+
+ # Use the raw POST value as we need to tell the difference between
+ # None/Undefined and an empty string. The validators use a default
+ # value with both of those cases and would need to be changed.
+ # In order to avoid breaking functionality, this was done instead.
+ prev_desc = request.post.get('prev_description_id')
+ prev_pubdesc = request.post.get('prev_public_description_id')
def update_wiki_text(sr):
apply_wikid_field(sr,
@@ -235,7 +235,11 @@ class WikiApiController(WikiController):
content=VMarkdown(('content')))
def POST_wiki_edit(self, pageandprevious, content):
page, previous = pageandprevious
- previous = previous._id if previous else None
+ # Use the raw POST value as we need to tell the difference between
+ # None/Undefined and an empty string. The validators use a default
+ # value with both of those cases and would need to be changed.
+ # In order to avoid breaking functionality, this was done instead.
+ previous = previous._id if previous else request.post.get('previous')
try:
if page.name == 'config/stylesheet':
report, parsed = c.site.parse_css(content, verify=False)
View
@@ -272,6 +272,7 @@ def has_editor(self, editor):
def revise(self, content, previous = None, author=None, force=False, reason=None):
if self.content == content:
return
+ force = True if previous is None else force
max_length = special_length_restrictions_bytes.get(self.name, MAX_PAGE_LENGTH_BYTES)
if len(content) > max_length:
raise ContentLengthError(max_length)

0 comments on commit bc91f31

Please sign in to comment.