Send ban message from SR, not mod

This commit is contained in:
Keith Mitchell
2011-10-13 10:32:15 -07:00
parent 3dce43b09a
commit d3f8fdbda2
6 changed files with 50 additions and 19 deletions

View File

@@ -565,8 +565,14 @@ class ApiController(RedditController):
title = container.title)
msg = msg % d
subj = subj % d
item, inbox_rel = Message._new(c.user, friend,
subj, msg, ip)
if type == 'banned':
from_sr = True
sr = container
else:
from_sr = False
sr = None
item, inbox_rel = Message._new(c.user, friend, subj, msg,
ip, from_sr=from_sr, sr=sr)
queries.new_message(item, inbox_rel)

View File

@@ -415,6 +415,8 @@ class MessageJsonTemplate(ThingJsonTemplate):
return None
elif attr == "body_html":
return safemarkdown(thing.body)
elif attr == "author" and getattr(thing, "hide_author", False):
return None
return ThingJsonTemplate.thing_attr(self, thing, attr)
def rendered_data(self, wrapped):

View File

@@ -930,16 +930,16 @@ class Message(Thing, Printable):
cache_ignore = set(["to", "subreddit"]).union(Printable.cache_ignore)
@classmethod
def _new(cls, author, to, subject, body, ip, parent = None, sr = None):
m = Message(subject = subject,
body = body,
author_id = author._id,
new = True,
ip = ip)
def _new(cls, author, to, subject, body, ip, parent=None, sr=None,
from_sr=False):
m = Message(subject=subject, body=body, author_id=author._id, new=True,
ip=ip, from_sr=from_sr)
m._spam = author._spam
sr_id = None
# check to see if the recipient is a subreddit and swap args accordingly
if to and isinstance(to, Subreddit):
if from_sr:
raise CreationError("Cannot send from SR to SR")
to_subreddit = True
to, sr = None, to
else:
@@ -957,7 +957,9 @@ class Message(Thing, Printable):
sr_id = parent.sr_id
if not to and not sr_id:
raise CreationError, "Message created with neither to nor sr_id"
raise CreationError("Message created with neither to nor sr_id")
if from_sr and not sr_id:
raise CreationError("Message sent from_sr without setting sr")
m.to_id = to._id if to else None
if sr_id is not None:
@@ -965,7 +967,6 @@ class Message(Thing, Printable):
m._commit()
inbox_rel = None
if sr_id and not sr:
sr = Subreddit._byID(sr_id)
@@ -974,7 +975,7 @@ class Message(Thing, Printable):
# if there is a subreddit id, and it's either a reply or
# an initial message to an SR, add to the moderator inbox
# (i.e., don't do it for automated messages from the SR)
if parent or to_subreddit:
if parent or to_subreddit and not from_sr:
inbox_rel.append(ModeratorInbox._add(sr, m, 'inbox'))
if author.name in g.admins:
m.distinguished = 'admin'
@@ -1074,7 +1075,7 @@ class Message(Thing, Printable):
item.recipient = (item.author_id != c.user._id)
else:
item.recipient = (item.to_id == c.user._id)
# new-ness is stored on the relation
if item.author_id == c.user._id:
item.new = False
@@ -1112,6 +1113,13 @@ class Message(Thing, Printable):
item.message_style = "post-reply"
elif item.sr_id is not None:
item.subreddit = m_subreddits[item.sr_id]
item.hide_author = False
if getattr(item, "from_sr", False):
if not (item.subreddit.is_moderator(c.user) or
c.user_is_admin):
item.author = item.subreddit
item.hide_author = True
item.is_collapsed = None
if not item.new:

View File

@@ -55,7 +55,9 @@
<div class="entry">
<%
taglinetext = ''
if thing.to_id == c.user._id or thing.to_id is None:
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
@@ -65,7 +67,10 @@
taglinetext = taglinetext.replace(' ', '&nbsp;')
author = WrappedUser(thing.author, thing.attribs, thing).render()
if thing.sr_id:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
subreddit = '<a href="%s.compact">%s</a>' % (thing.subreddit.path,
thing.subreddit.name)
author = updated_author % dict(author = author, subreddit = subreddit)
@@ -80,7 +85,7 @@
${unsafe(safemarkdown(thing.body))}
<div class="clear options_expando hidden">
<%
is_author = (c.user_is_loggedin and thing.author and c.user.name == thing.author.name)
is_author = (c.user_is_loggedin and thing.author and c.user._fullname == thing.author._fullname)
%>
%if c.user_is_loggedin:
${icon_button("Reply", "reply-icon", outer_class="reply-button", onclick="return reply(this)")}

View File

@@ -52,7 +52,9 @@ ${parent.thing_css_class(what)} ${"new" if thing.new else ""} ${"was-comment" if
<span class="head">
<%
taglinetext = ''
if thing.to_id == c.user._id or thing.to_id is None:
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
@@ -62,7 +64,10 @@ ${parent.thing_css_class(what)} ${"new" if thing.new else ""} ${"was-comment" if
taglinetext = taglinetext.replace(' ', '&nbsp;')
author = WrappedUser(thing.author, thing.attribs, thing).render()
if thing.sr_id:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
subreddit = '<a href="%s">%s</a>' % (thing.subreddit.path,
thing.subreddit.name)
author = updated_author % dict(author = author, subreddit = subreddit)

View File

@@ -34,7 +34,9 @@
<title>
<%
taglinetext = ''
if thing.to_id == c.user._id or thing.to_id is None:
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
@@ -44,7 +46,10 @@
author = thing.author.name
if thing.sr_id and not (getattr(thing, "is_child", False) or
getattr(thing, "is_parent", False)):
updated_author = _("%(author)s via %(subreddit)s")
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s")
subreddit = thing.subreddit.name
author = updated_author % dict(author = author, subreddit = subreddit)
%>