Add quarantine and message ability for admins

This commit is contained in:
MelissaCole
2015-09-22 18:17:54 -07:00
parent c7bd6e84dc
commit fe515c4e35
5 changed files with 103 additions and 3 deletions

View File

@@ -3573,6 +3573,40 @@ class ApiController(RedditController):
return abort(404, 'not found')
sr.update_search_index(boost_only=True)
@validatedForm(
VAdmin(),
VModhash(),
subreddit=VByName('subreddit'),
quarantine=VBoolean('quarantine'),
subject=VLength('subject', 1000),
body=VMarkdownLength('body', max_length=10000),
)
def POST_quarantine(self, form, jquery, subreddit, quarantine, subject, body):
if subreddit.quarantine == quarantine:
return
subreddit.quarantine = quarantine
subreddit._commit()
system_user = Account.system_user()
kw = dict(
sr_id36=subreddit._id36,
mod_id36=system_user._id36,
action="editsettings",
details="quarantine",
)
ma = ModAction(**kw)
ma._commit()
if body.strip():
send_system_message(subreddit, subject, body,
distinguished='admin', repliable=False)
# Refresh the CSS since images aren't allowed
stylesheet_contents = subreddit.fetch_stylesheet_source()
css_errors, parsed = subreddit.parse_css(stylesheet_contents)
subreddit.change_css(stylesheet_contents, parsed, author=system_user)
jquery.refresh()
@require_oauth2_scope("subscribe")
@noresponse(
VUser(),

View File

@@ -793,14 +793,16 @@ class Subreddit(Thing, Printable, BaseSite):
from r2.models import ModAction
from r2.lib.media import upload_stylesheet
author = author if author else c.user._id36
if not author:
author = c.user
if content is None:
content = ''
try:
wiki = WikiPage.get(self, 'config/stylesheet')
except tdb_cassandra.NotFound:
wiki = WikiPage.create(self, 'config/stylesheet')
wr = wiki.revise(content, previous=prev, author=author, reason=reason, force=force)
wr = wiki.revise(content, previous=prev, author=author._id36, reason=reason, force=force)
if parsed:
self.stylesheet_url = upload_stylesheet(parsed)
@@ -812,7 +814,7 @@ class Subreddit(Thing, Printable, BaseSite):
self.stylesheet_url_https = ""
self._commit()
ModAction.create(self, c.user, action='wikirevise', details='Updated subreddit stylesheet')
ModAction.create(self, author, action='wikirevise', details='Updated subreddit stylesheet')
return wr
def is_special(self, user):

View File

@@ -2137,6 +2137,17 @@ a.star { text-decoration: none; color: #ff8b60 }
}
}
.quarantine-tool.noncollapsed {
.quarantine-info {
display: block;
}
}
.quarantine-tool.collapsed {
.quarantine-info {
display: none;
}
}
/* comments */

View File

@@ -434,6 +434,19 @@ function togglecomment(elem) {
}
}
function toggleSrQuarantine(elem) {
var $toolbox = $(".quarantine-tool");
var $expander = $toolbox.find(".expand:first");
var isCollapsed = $toolbox.hasClass("collapsed");
$toolbox.toggleClass("collapsed noncollapsed");
if (!isCollapsed) {
$expander.text('[+]');
} else {
$expander.text('[]');
}
}
function togglemessage(elem) {
var message = $(elem).thing()
var expander = message.find(".expand:first")

View File

@@ -164,6 +164,46 @@
%endif
%endif
</div>
<div class="clear"></div>
<div class="quarantine-tool raisedbox spacer collapsed">
<div name="expander">
<a href="javascript:void(0)" class="expand" onclick="return toggleSrQuarantine(this)">
${"[%s]" % "+"}
</a>
${"Show unquarantine tool" if thing.sr.quarantine else "Show quarantine tool"}
</div>
<div class="quarantine-info">
%if not thing.sr.quarantine:
<%
subject = "ATTN: Your subreddit has been quarantined"
body = "Your subreddit has been [quarantined](https://reddit.zendesk.com/hc/en-us/articles/205701245) due to offensive content."
button_label = "Quarantine and send modmail"
%>
%else:
<%
subject = "ATTN: Your subreddit is no longer quarantined"
body = "Your subreddit has been unquarantined."
button_label = "Unquarantine and send modmail"
%>
%endif
<form id="quarantinemessage-form" method="post" onsubmit="return post_form(this, 'quarantine')">
<input type="hidden" name="subreddit" value="${thing.sr._fullname}">
<input type="hidden" name="quarantine" value="${not thing.sr.quarantine}">
<label for="subject">Subject:</label>
<br>
<textarea name="subject">${subject}</textarea>
<br>
<label for="body">Body:</label>
<br>
<textarea name="body" rows=4>${body}</textarea>
<br>
<input type="submit" class="notes-button" value="${button_label}">
<br>
<label>Message will be sent by u/reddit and won't send if left blank</label>
</form>
</div>
</div>
%endif
<div class="clear"> </div>