mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Send quarantined subreddit actions to event-collector
The available event_types are:
quarantine_interstitial_view, quarantine_interstitial_dismiss,
quarantine_opt_in, quarantine_opt_out
This commit is contained in:
committed by
Florence Yeun
parent
a8cab6f148
commit
cf9a9781cc
@@ -811,6 +811,8 @@ events_collector_sample_rate = 0.0
|
||||
events_collector_submit_sample_rate = 0.0
|
||||
# Event-collector sample rate for moderator events
|
||||
events_collector_mod_sample_rate = 0.0
|
||||
# Event-collector sample rate for quarantine events
|
||||
events_collector_quarantine_sample_rate = 0.0
|
||||
# Pages that are not yet supported by mobile web, and therefore should not
|
||||
# receive the switch-to-mobile banner
|
||||
mweb_blacklist_expressions = ^/prefs/?, ^/live/?, /message/, /wiki/?, /m/, ^/subreddits/create, /submit, ^/r/[^/]+/about/, ^/gold, ^/advertising, ^/promoted, ^/rules, ^/buttons
|
||||
|
||||
@@ -3438,6 +3438,8 @@ class ApiController(RedditController):
|
||||
if not sr:
|
||||
return abort(404, 'not found')
|
||||
else:
|
||||
g.events.quarantine_event('quarantine_opt_out', sr,
|
||||
request=request, context=c)
|
||||
QuarantinedSubredditOptInsByAccount.opt_out(c.user, sr)
|
||||
return self.redirect('/')
|
||||
|
||||
|
||||
@@ -140,14 +140,17 @@ class PostController(ApiController):
|
||||
def POST_quarantine(self, sr, accept, dest):
|
||||
if not feature.is_enabled('quarantine'):
|
||||
return self.abort404()
|
||||
if not c.user_is_loggedin:
|
||||
if not c.user_is_loggedin or not c.user.email_verified:
|
||||
return self.redirect(dest)
|
||||
|
||||
if accept:
|
||||
g.events.quarantine_event('quarantine_opt_in', sr,
|
||||
request=request, context=c)
|
||||
QuarantinedSubredditOptInsByAccount.opt_in(c.user, sr)
|
||||
return self.redirect(dest)
|
||||
else:
|
||||
QuarantinedSubredditOptInsByAccount.opt_out(c.user, sr)
|
||||
g.events.quarantine_event('quarantine_interstitial_dismiss', sr,
|
||||
request=request, context=c)
|
||||
return self.redirect('/')
|
||||
|
||||
@csrf_exempt
|
||||
|
||||
@@ -1691,6 +1691,8 @@ class RedditController(OAuth2ResourceController):
|
||||
request.environ['usable_error_content'] = errpage.render()
|
||||
self.abort403()
|
||||
else:
|
||||
g.events.quarantine_event('quarantine_interstitial_view', c.site,
|
||||
request=request, context=c)
|
||||
return self.intermediate_redirect("/quarantine", sr_path=False)
|
||||
|
||||
#check over 18
|
||||
|
||||
@@ -341,6 +341,7 @@ class Globals(object):
|
||||
'invalid_key_sample_rate',
|
||||
'events_collector_sample_rate',
|
||||
'events_collector_mod_sample_rate',
|
||||
'events_collector_quarantine_sample_rate',
|
||||
],
|
||||
ConfigValue.tuple: [
|
||||
'fastlane_links',
|
||||
|
||||
@@ -29,10 +29,11 @@ import uuid
|
||||
|
||||
import pytz
|
||||
import requests
|
||||
from pylons import g
|
||||
from wsgiref.handlers import format_date_time
|
||||
|
||||
import r2.lib.amqp
|
||||
from r2.lib.utils import epoch_timestamp, sampled, squelch_exceptions
|
||||
from r2.lib.utils import domain, epoch_timestamp, sampled, squelch_exceptions
|
||||
|
||||
|
||||
MAX_EVENT_SIZE = 4096
|
||||
@@ -191,6 +192,59 @@ class EventQueue(object):
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
@sampled("events_collector_quarantine_sample_rate")
|
||||
def quarantine_event(self, event_type, subreddit,
|
||||
request=None, context=None):
|
||||
"""Create a 'quarantine' event for event-collector.
|
||||
|
||||
event_type: quarantine_interstitial_view, quarantine_opt_in,
|
||||
quarantine_opt_out, quarantine_interstitial_dismiss
|
||||
subreddit: The quarantined subreddit
|
||||
request, context: Should be pylons.request & pylons.c respectively;
|
||||
used to build the base Event
|
||||
|
||||
"""
|
||||
event = EventV2(
|
||||
topic="quarantine",
|
||||
event_type=event_type,
|
||||
request=request,
|
||||
context=context,
|
||||
)
|
||||
|
||||
if context:
|
||||
if context.user_is_loggedin:
|
||||
event.add("verified_email", context.user.email_verified)
|
||||
else:
|
||||
event.add("verified_email", False)
|
||||
|
||||
event.add("sr_id", subreddit._id)
|
||||
event.add("sr_name", subreddit.name)
|
||||
|
||||
# Due to the redirect, the request object being sent isn't the
|
||||
# original, so referrer and action data is missing for certain events
|
||||
if request and (event_type == "quarantine_interstitial_view" or
|
||||
event_type == "quarantine_opt_out"):
|
||||
request_vars = request.environ["pylons.routes_dict"]
|
||||
event.add("sr_action", request_vars.get("action", None))
|
||||
|
||||
# The thing_id the user is trying to view is a comment
|
||||
if request.environ["pylons.routes_dict"].get("comment", None):
|
||||
thing_id36 = request_vars.get("comment", None)
|
||||
# The thing_id is a link
|
||||
else:
|
||||
thing_id36 = request_vars.get("article", None)
|
||||
|
||||
if thing_id36:
|
||||
event.add("thing_id", int(thing_id36, 36))
|
||||
|
||||
referrer_url = request.headers.get('Referer', None)
|
||||
if referrer_url:
|
||||
event.add("referrer_url", referrer_url)
|
||||
event.add("referrer_domain", domain(referrer_url))
|
||||
|
||||
self.save_event(event)
|
||||
|
||||
@squelch_exceptions
|
||||
def event_base(self, request, context):
|
||||
return Event.base_from_request(request, context)
|
||||
|
||||
@@ -42,25 +42,25 @@
|
||||
%endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
%if thing.logged_in and thing.email_verified:
|
||||
|
||||
<form method="post" action=""
|
||||
${"target='_top'" if c.cname else ""}>
|
||||
<input type="hidden" name="uh" value="${c.modhash}" />
|
||||
<input type="hidden" name="sr_name" value="${thing.sr_name}" />
|
||||
<div class="buttons">
|
||||
<button class="c-btn c-btn-primary" type="submit" name="accept" value="no">
|
||||
${_("no thank you")}
|
||||
</button>
|
||||
<button class="c-btn c-btn-primary" type="submit" name="accept" value="yes">
|
||||
${_("continue")}
|
||||
</button>
|
||||
%if thing.logged_in and thing.email_verified:
|
||||
<button class="c-btn c-btn-primary" type="submit" name="accept" value="no">
|
||||
${_("no thank you")}
|
||||
</button>
|
||||
<button class="c-btn c-btn-primary" type="submit" name="accept" value="yes">
|
||||
${_("continue")}
|
||||
</button>
|
||||
%else:
|
||||
<button class="c-btn c-btn-primary" type="submit" name="accept" value="no">
|
||||
${_("back to reddit")}
|
||||
</button>
|
||||
%endif
|
||||
</div>
|
||||
</form>
|
||||
%else:
|
||||
<div class="buttons">
|
||||
<a href="/" class="c-btn c-btn-primary">${_("back to reddit")}</a>
|
||||
</div>
|
||||
%endif
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user