Skip to content

Commit

Permalink
Honor selftext-expunging in JSON API.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Jun 20, 2011
1 parent 8d7f4f2 commit d99dece
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
11 changes: 9 additions & 2 deletions r2/r2/lib/jsontemplates.py
Expand Up @@ -25,6 +25,7 @@
from r2.lib.filters import spaceCompress, safemarkdown
import time, pytz
from pylons import c, g
from pylons.i18n import _

def api_type(subtype = ''):
return 'api-' + subtype if subtype else 'api'
Expand Down Expand Up @@ -269,9 +270,15 @@ def thing_attr(self, thing, attr):
elif attr == 'subreddit_id':
return thing.subreddit._fullname
elif attr == 'selftext':
return thing.selftext
if not thing.expunged:
return thing.selftext
else:
return ''
elif attr == 'selftext_html':
return safemarkdown(thing.selftext)
if not thing.expunged:
return safemarkdown(thing.selftext)
else:
return safemarkdown(_("[deleted]"))
return ThingJsonTemplate.thing_attr(self, thing, attr)

def rendered_data(self, thing):
Expand Down
20 changes: 1 addition & 19 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -2672,29 +2672,11 @@ class MediaEmbed(Templated):
class SelfTextChild(LinkChild):
css_style = "selftext"

def _should_expunge_selftext(self):
verdict = getattr(self.link, "verdict", "")
if verdict not in ("admin-removed", "mod-removed"):
return False
if not c.user_is_loggedin:
return True
if c.user_is_admin:
return False
if c.user == self.link.author:
return False

sr = Subreddit._byID(self.link.sr_id, stale=True)
if sr.is_moderator(c.user):
return False

return True

def content(self):
expunged = self._should_expunge_selftext()
u = UserText(self.link, self.link.selftext,
editable = c.user == self.link.author,
nofollow = self.nofollow,
expunged=expunged)
expunged=self.link.expunged)
return u.render()

class UserText(CachedTemplate):
Expand Down
19 changes: 19 additions & 0 deletions r2/r2/models/link.py
Expand Up @@ -287,6 +287,21 @@ def make_permalink(self, sr, force_domain = False):
def make_permalink_slow(self, force_domain = False):
return self.make_permalink(self.subreddit_slow,
force_domain = force_domain)

@staticmethod
def _should_expunge_selftext(link):
verdict = getattr(link, "verdict", "")
if verdict not in ("admin-removed", "mod-removed"):
return False
if not c.user_is_loggedin:
return True
if c.user_is_admin:
return False
if c.user == link.author:
return False
if link.can_ban:
return False
return True

@classmethod
def add_props(cls, user, wrapped):
Expand Down Expand Up @@ -500,6 +515,10 @@ def add_props(cls, user, wrapped):
item.reveal_trial_info = True
item.use_big_modbuttons = True

item.expunged = False
if item.is_self:
item.expunged = Link._should_expunge_selftext(item)

if user_is_loggedin:
incr_counts(wrapped)

Expand Down

0 comments on commit d99dece

Please sign in to comment.