mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Add opt out button for quarantined subreddits
This commit is contained in:
committed by
Florence Yeun
parent
a4e6172fc5
commit
38b3bf57aa
@@ -71,6 +71,7 @@ def make_map():
|
||||
|
||||
mc('/over18', controller='post', action='over18')
|
||||
mc('/quarantine', controller='post', action='quarantine')
|
||||
mc('/quarantine_optout', controller='api', action='quarantine_optout')
|
||||
|
||||
mc('/rules', controller='front', action='rules')
|
||||
mc('/sup', controller='front', action='sup')
|
||||
|
||||
@@ -3410,6 +3410,19 @@ class ApiController(RedditController):
|
||||
return abort(404, 'not found')
|
||||
sr.update_search_index(boost_only=True)
|
||||
|
||||
@noresponse(
|
||||
VUser(),
|
||||
VModhash(),
|
||||
sr=VSRByName('sr_name'),
|
||||
)
|
||||
def POST_quarantine_optout(self, sr):
|
||||
"""Opt out from a quarantined subreddit"""
|
||||
if not sr:
|
||||
return abort(404, 'not found')
|
||||
else:
|
||||
QuarantinedSubredditOptInsByAccount.opt_out(c.user, sr)
|
||||
return self.redirect('/')
|
||||
|
||||
@validatedForm(VAdmin(),
|
||||
VModhash(),
|
||||
hexkey=VLength("hexkey", max_length=32),
|
||||
|
||||
@@ -5114,6 +5114,15 @@ class SubscribeButton(Templated):
|
||||
self.data_attrs["bubble_class"] = bubble_class
|
||||
|
||||
|
||||
class QuarantineOptoutButton(Templated):
|
||||
def __init__(self, sr, bubble_class=None):
|
||||
Templated.__init__(self)
|
||||
self.sr = sr
|
||||
self.data_attrs = {"sr_name": sr.name}
|
||||
if bubble_class:
|
||||
self.data_attrs["bubble_class"] = bubble_class
|
||||
|
||||
|
||||
class SubredditSelector(Templated):
|
||||
def __init__(self, default_sr=None, extra_subreddits=None, required=False,
|
||||
include_searches=True, include_user_subscriptions=True, class_name=None,
|
||||
|
||||
@@ -824,9 +824,8 @@ class Subreddit(Thing, Printable, BaseSite):
|
||||
return True
|
||||
elif not self.quarantine:
|
||||
return True
|
||||
elif (c.user_is_loggedin and
|
||||
QuarantinedSubredditOptInsByAccount.is_opted_in(user, self) and
|
||||
c.user.email_verified):
|
||||
elif (c.user_is_loggedin and c.user.email_verified and
|
||||
QuarantinedSubredditOptInsByAccount.is_opted_in(user, self)):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -320,6 +320,15 @@ function unsubscribe(reddit_name) {
|
||||
};
|
||||
};
|
||||
|
||||
function quarantine_optout(subreddit_name) {
|
||||
return function() {
|
||||
if (reddit.logged) {
|
||||
$.request("quarantine_optout", {sr: subreddit_name});
|
||||
$.redirect("/");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function friend(user_name, container_name, type) {
|
||||
return function() {
|
||||
if (reddit.logged) {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<%!
|
||||
from r2.lib.filters import websafe
|
||||
from r2.lib.strings import strings, Score
|
||||
from r2.lib.pages import WrappedUser, SubscribeButton
|
||||
from r2.lib.pages import WrappedUser, QuarantineOptoutButton, SubscribeButton
|
||||
from r2.lib.template_helpers import _ws
|
||||
from r2.models.listing import ModListing
|
||||
%>
|
||||
@@ -37,6 +37,13 @@
|
||||
</h1>
|
||||
|
||||
${SubscribeButton(thing.sr)}
|
||||
%if thing.sr.quarantine:
|
||||
<form method='post' action='/api/quarantine_optout'>
|
||||
<input type="hidden" name="uh" value="${c.modhash}"/>
|
||||
<input type="hidden" name="sr_name" value="${thing.sr.name}"/>
|
||||
<button name="submit" value="submit" type="submit">opt out</button>
|
||||
</form>
|
||||
%endif
|
||||
<span class="subscribers">${unsafe(Score.readers(thing.subscribers))}</span>
|
||||
<p class="users-online ${'fuzzed' if thing.accounts_active_fuzzed else ''}" title="${_('logged-in users viewing this subreddit in the past 15 minutes')}">
|
||||
${unsafe(Score.users_here_now(thing.accounts_active, prepend='~' if thing.accounts_active_fuzzed else ''))}
|
||||
|
||||
Reference in New Issue
Block a user