Skip to content

Commit

Permalink
Subreddit: check for is_banned in add_props.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsimpson63 committed May 20, 2015
1 parent 0b7cb58 commit 6c09a27
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion r2/r2/lib/jsontemplates.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def thing_attr(self, thing, attr):
return None
elif attr == 'is_banned':
if c.user_is_loggedin:
return bool(thing.is_banned(c.user))
return thing.banned
return None
elif attr == 'submit_text_html':
return safemarkdown(thing.submit_text)
Expand Down
6 changes: 5 additions & 1 deletion r2/r2/models/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ def add_props(cls, user, wrapped):
subscriber_srids = set()
moderator_srids = set()
contributor_srids = set()
banned_srids = set()
srmembers_to_fetch = []

if not user or not c.user_is_loggedin or not user.has_subscribed:
Expand All @@ -845,7 +846,7 @@ def add_props(cls, user, wrapped):
srmembers_to_fetch.append('subscriber')

if user and c.user_is_loggedin:
srmembers_to_fetch.extend(['moderator', 'contributor'])
srmembers_to_fetch.extend(['moderator', 'contributor', 'banned'])

if srmembers_to_fetch:
rels = SRMember._fast_query(wrapped, [user], srmembers_to_fetch)
Expand All @@ -858,12 +859,15 @@ def add_props(cls, user, wrapped):
moderator_srids.add(item._id)
elif rel_name == 'contributor':
contributor_srids.add(item._id)
elif rel_name == 'banned':
banned_srids.add(item._id)

target = "_top" if c.cname else None
for item in wrapped:
item.subscriber = item._id in subscriber_srids
item.moderator = item._id in moderator_srids
item.contributor = item._id in contributor_srids
item.banned = item._id in banned_srids

if item.hide_subscribers and not c.user_is_admin:
item._ups = 0
Expand Down

0 comments on commit 6c09a27

Please sign in to comment.