diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index f1968b5f8..b35fb8702 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -1704,7 +1704,7 @@ class ApiController(RedditController, OAuth2ResourceController): show_media = VBoolean('show_media'), exclude_banned_modqueue = VBoolean('exclude_banned_modqueue'), show_cname_sidebar = VBoolean('show_cname_sidebar'), - type = VOneOf('type', ('public', 'private', 'restricted', 'archived')), + type = VOneOf('type', ('public', 'private', 'restricted', 'gold_restricted', 'archived')), link_type = VOneOf('link_type', ('any', 'link', 'self')), submit_link_label=VLength('submit_link_label', max_length=60), submit_text_label=VLength('submit_text_label', max_length=60), @@ -1803,6 +1803,10 @@ class ApiController(RedditController, OAuth2ResourceController): if kw['type'] == 'archived' and not can_set_archived: c.errors.add(errors.INVALID_OPTION, field='type') + can_set_gold_restricted = c.user_is_admin or (sr and sr.type == 'gold_restricted') + if kw['type'] == 'gold_restricted' and not can_set_gold_restricted: + c.errors.add(errors.INVALID_OPTION, field='type') + if not sr and form.has_errors("ratelimit", errors.RATELIMIT): pass elif not sr and form.has_errors("name", errors.SUBREDDIT_EXISTS, diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index c3d098a96..62fbb14a0 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -353,7 +353,9 @@ class Reddit(Templated): and (c.user_is_loggedin or not g.read_only_mode) and not user_banned): if (not isinstance(c.site, FakeSubreddit) - and c.site.type in ("archived", "restricted") + and c.site.type in ("archived", + "restricted", + "gold_restricted") and not (c.user_is_loggedin and c.site.can_submit(c.user))): if c.site.type == "archived": @@ -365,8 +367,12 @@ class Reddit(Templated): subtitles=[subtitle], show_icon=False)) else: - subtitle = _('submission in this subreddit ' - 'is restricted to approved submitters.') + if c.site.type == 'restricted': + subtitle = _('submission in this subreddit ' + 'is restricted to approved submitters.') + elif c.site.type == 'gold_restricted': + subtitle = _('submission in this subreddit ' + 'is restricted to reddit gold members.') ps.append(SideBox(title=_('Submissions restricted'), css_class="submit", disabled=True, diff --git a/r2/r2/lib/sr_pops.py b/r2/r2/lib/sr_pops.py index c1bf2cbb7..896a50792 100644 --- a/r2/r2/lib/sr_pops.py +++ b/r2/r2/lib/sr_pops.py @@ -57,7 +57,7 @@ def cache_lists(): continue type = getattr(sr, 'type', 'private') - if type not in ('public', 'restricted'): + if type not in ('public', 'restricted', 'gold_restricted'): # skips reddits that can't appear in the default list # because of permissions continue diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index b4ef81776..0445627c2 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -336,6 +336,8 @@ class Subreddit(Thing, Printable): return True elif self.is_banned(user): return False + elif self.type == 'gold_restricted' and user.gold: + return True elif self.type in ('public','restricted'): return True elif self.is_moderator(user) or self.is_contributor(user): @@ -356,6 +358,8 @@ class Subreddit(Thing, Printable): elif self.is_moderator(user) or self.is_contributor(user): #restricted/private require contributorship return True + elif self.type == 'gold_restricted' and user.gold: + return True else: return False @@ -453,7 +457,8 @@ class Subreddit(Thing, Printable): if self.spammy(): return False - elif self.type in ('public', 'restricted', 'archived'): + elif self.type in ('public', 'restricted', + 'gold_restricted', 'archived'): return True elif c.user_is_loggedin: return (self.is_contributor(user) or diff --git a/r2/r2/templates/createsubreddit.html b/r2/r2/templates/createsubreddit.html index 0cc996847..a6f1079be 100644 --- a/r2/r2/templates/createsubreddit.html +++ b/r2/r2/templates/createsubreddit.html @@ -133,6 +133,13 @@ _("anyone can view, but submissions are no longer accepted"), is_archived)} %endif + + <% is_gold_restricted = thing.site and thing.site.type == 'gold_restricted' %> + %if c.user_is_admin or is_gold_restricted: + ${utils.radio_type('type', "gold_restricted", _("gold restricted"), + _("anyone can view, but only reddit gold members can submit or comment"), + is_gold_restricted)} + %endif ${error_field("INVALID_OPTION", "type")}