diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 585950f13..4a30d5e4e 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -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): diff --git a/r2/r2/controllers/reddit_base.py b/r2/r2/controllers/reddit_base.py index 70e44977f..378a708fa 100644 --- a/r2/r2/controllers/reddit_base.py +++ b/r2/r2/controllers/reddit_base.py @@ -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") diff --git a/r2/r2/models/populatedb.py b/r2/r2/models/populatedb.py index d4c454287..ec0d2fa8a 100644 --- a/r2/r2/models/populatedb.py +++ b/r2/r2/models/populatedb.py @@ -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): diff --git a/r2/r2/models/report.py b/r2/r2/models/report.py index d6af31990..978ebd01d 100644 --- a/r2/r2/models/report.py +++ b/r2/r2/models/report.py @@ -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) diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 51d9b8b65..2792ac578 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -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()) diff --git a/r2/r2/templates/subredditinfobar.html b/r2/r2/templates/subredditinfobar.html index 2d267a461..eca007b19 100644 --- a/r2/r2/templates/subredditinfobar.html +++ b/r2/r2/templates/subredditinfobar.html @@ -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): -
+

${c.site.name}

%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
+ %if c.user_is_admin: + %if c.site._spam: + ${state_button("unban", _("unban"), + "return change_state(this, 'unban');", _("unbanned"))} + %if hasattr(c.site, 'banner'): +
${strings.banned_by % c.site.banner}
+ %endif + %else: + ${state_button("ban", _("ban"), + "return change_state(this, 'ban');", _("banned"))} + %endif + %endif
%for n in thing.nav(): ${n.render()}