Start tracking authors and IPs of whoever created a subreddit

Also adds some UI to ban a spammy reddit from its front page instead
of hunting for it in the listing
This commit is contained in:
ketralnis
2009-02-20 10:40:08 -08:00
parent b604758984
commit 4541f868d2
6 changed files with 39 additions and 20 deletions

View File

@@ -923,9 +923,10 @@ class ApiController(RedditController):
lang = VLang("lang"),
over_18 = VBoolean('over_18'),
show_media = VBoolean('show_media'),
type = VOneOf('type', ('public', 'private', 'restricted'))
type = VOneOf('type', ('public', 'private', 'restricted')),
ip = ValidIP(),
)
def POST_site_admin(self, form, jquery, name ='', sr = None, **kw):
def POST_site_admin(self, form, jquery, name ='', ip = None, sr = None, **kw):
# the status button is outside the form -- have to reset by hand
form.parent().set_html('.status', "")
@@ -959,7 +960,8 @@ class ApiController(RedditController):
#creating a new reddit
elif not sr:
#sending kw is ok because it was sanitized above
sr = Subreddit._new(name = name, **kw)
sr = Subreddit._new(name = name, author_id = c.user._id, ip = ip,
**kw)
Subreddit.subscribe_defaults(c.user)
# make sure this user is on the admin list of that site!
if sr.add_subscriber(c.user):

View File

@@ -248,10 +248,6 @@ def set_subreddit():
if isinstance(c.site, FakeSubreddit):
c.default_sr = True
# check that the site is available:
if c.site._spam and not c.user_is_admin and not c.error_page:
abort(404, "not found")
def set_content_type():
e = request.environ
c.render_style = e['render_style']
@@ -482,6 +478,10 @@ class RedditController(BaseController):
if not isinstance(c.site, FakeSubreddit):
request.environ['REDDIT_NAME'] = c.site.name
# check that the site is available:
if c.site._spam and not c.user_is_admin and not c.error_page:
abort(404, "not found")
# check if the user has access to this subreddit
if not c.site.can_view(c.user) and not c.error_page:
abort(403, "forbidden")

View File

@@ -26,9 +26,13 @@ import random
def populate(sr_name = 'reddit.com', sr_title = "reddit.com: what's new online",
num = 100):
sr = Subreddit._new(name= sr_name, title = sr_title)
sr._commit()
create_accounts(num)
a = Author._query(limit = 1)
sr = Subreddit._new(name = sr_name, title = sr_title,
ip = '0.0.0.0', author_id = a._id)
sr._commit()
create_links(num)
def create_accounts(num):

View File

@@ -389,14 +389,11 @@ def unreport(things, correct=False, auto = False, banned_by = ''):
things = tup(things)
# load authors (to set the spammer flag)
try:
aids = set(t.author_id for t in things)
except AttributeError:
aids = None
aids = set(t.author_id for t in things
if hasattr(t, 'author_id'))
authors = Account._byID(tuple(aids), data=True) if aids else {}
# load all reports (to set their amount to be +/-1)
reports = Report.reported(things=things, amount = 0)

View File

@@ -56,7 +56,7 @@ class Subreddit(Thing, Printable):
sr_limit = 50
@classmethod
def _new(self, name, title, lang = 'en', type = 'public',
def _new(self, name, title, author_id, ip, lang = 'en', type = 'public',
over_18 = False, **kw):
try:
sr = Subreddit._by_name(name)
@@ -67,6 +67,8 @@ class Subreddit(Thing, Printable):
lang = lang,
type = type,
over_18 = over_18,
author_id = author_id,
ip = ip,
**kw)
sr._commit()
clear_memo('subreddit._by_name', Subreddit, name.lower())

View File

@@ -25,9 +25,11 @@
from r2.lib.utils import timesince
from r2.lib.strings import strings
%>
<%namespace file="printable.html" import="ynbutton, toggle_button"/>
<%namespace file="printable.html" import="ynbutton, toggle_button, state_button"/>
<%namespace file="printable.html" import="thing_css_class" />
%if not isinstance(c.site, FakeSubreddit):
<div class="raisedbox subreddit-info">
<div class="raisedbox subreddit-info ${thing_css_class(c.site)}">
<h3>${c.site.name}</h3>
%if c.user_is_loggedin:
${toggle_button("subscribe-button",
@@ -51,16 +53,28 @@
_("you are a contributor of this reddit. (%(leave)s)"),
_("stop being a contributor?"),
_("you are no longer a contributor"))}
%endif
%endif
%if c.user_is_loggedin and c.site.is_moderator(c.user):
%if c.user_is_loggedin and c.site.is_moderator(c.user):
${moderate_button("leave_moderator",
_("you are a moderator of this reddit. (%(leave)s)"),
_("stop being a moderator?"),
_("you are no longer a moderator"))}
%endif
%endif
</div>
%if c.user_is_admin:
%if c.site._spam:
${state_button("unban", _("unban"),
"return change_state(this, 'unban');", _("unbanned"))}
%if hasattr(c.site, 'banner'):
<div>${strings.banned_by % c.site.banner}</div>
%endif
%else:
${state_button("ban", _("ban"),
"return change_state(this, 'ban');", _("banned"))}
%endif
%endif
<div class="spacer">
%for n in thing.nav():
${n.render()}