Permalink
...
Comparing changes
Open a pull request
- 4 commits
- 7 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
23 additions
and 45 deletions.
- +0 −40 r2/r2/controllers/api.py
- +7 −2 r2/r2/controllers/front.py
- +4 −3 r2/r2/controllers/validator/validator.py
- +1 −0 r2/r2/lib/app_globals.py
- +3 −0 r2/r2/lib/pages/pages.py
- +2 −0 r2/r2/models/subreddit.py
- +6 −0 r2/r2/templates/notenoughkarmatopost.html
View
40
r2/r2/controllers/api.py
| @@ -180,46 +180,6 @@ def POST_compose(self, res, to, subject, body, ip): | ||
| else: | ||
| res._update('success', innerHTML='') | ||
| - | ||
| - @validate(VUser(), | ||
| - VSRSubmitPage(), | ||
| - url = VRequired('url', None), | ||
| - title = VRequired('title', None)) | ||
| - def GET_submit(self, url, title): | ||
| - if url and not request.get.get('resubmit'): | ||
| - listing = link_listing_by_url(url) | ||
| - redirect_link = None | ||
| - if listing.things: | ||
| - if len(listing.things) == 1: | ||
| - redirect_link = listing.things[0] | ||
| - else: | ||
| - subscribed = [l for l in listing.things | ||
| - if c.user_is_loggedin | ||
| - and l.subreddit.is_subscriber_defaults(c.user)] | ||
| - | ||
| - #if there is only 1 link to be displayed, just go there | ||
| - if len(subscribed) == 1: | ||
| - redirect_link = subscribed[0] | ||
| - else: | ||
| - infotext = strings.multiple_submitted % \ | ||
| - listing.things[0].resubmit_link() | ||
| - res = BoringPage(_("Seen it"), | ||
| - content = listing, | ||
| - infotext = infotext).render() | ||
| - return res | ||
| - | ||
| - if redirect_link: | ||
| - return self.redirect(redirect_link.already_submitted_link) | ||
| - | ||
| - captcha = Captcha() if c.user.needs_captcha() else None | ||
| - srs = Subreddit.submit_sr(c.user) if c.default_sr else () | ||
| - | ||
| - return FormPage(_("Submit"), | ||
| - content=NewLink(url=url or '', | ||
| - title=title or '', | ||
| - subreddits = srs, | ||
| - captcha=captcha)).render() | ||
| - | ||
| @Json | ||
| @validate(VAdmin(), | ||
| link = VByName('id')) | ||
View
9
r2/r2/controllers/front.py
| @@ -479,12 +479,17 @@ def GET_validuser(self): | ||
| @validate(VUser(), | ||
| - VSRSubmitPage(), | ||
| + can_submit = VSRSubmitPage(), | ||
| url = VRequired('url', None), | ||
| title = VRequired('title', None), | ||
| tags = VTags('tags')) | ||
| - def GET_submit(self, url, title, tags): | ||
| + def GET_submit(self, can_submit, url, title, tags): | ||
| """Submit form.""" | ||
| + if not can_submit: | ||
| + return BoringPage(_("Not Enough Karma"), | ||
| + infotext="You do not have enough karma to post.", | ||
| + content=NotEnoughKarmaToPost()).render() | ||
| + | ||
| if url and not request.get.get('resubmit'): | ||
| # check to see if the url has already been submitted | ||
| listing = link_listing_by_url(url) | ||
View
7
r2/r2/controllers/validator/validator.py
| @@ -397,9 +397,10 @@ def run(self, thing_name): | ||
| class VSRSubmitPage(Validator): | ||
| def run(self): | ||
| - if not (c.default_sr or c.user_is_loggedin and | ||
| - c.site.can_submit(c.user)): | ||
| - abort(403, "forbidden") | ||
| + if not (c.default_sr or c.user_is_loggedin and c.site.can_submit(c.user)): | ||
| + return False | ||
| + else: | ||
| + return True | ||
| class VSubmitParent(Validator): | ||
| def run(self, fullname): | ||
View
1
r2/r2/lib/app_globals.py
| @@ -45,6 +45,7 @@ class Globals(object): | ||
| 'num_query_queue_workers', | ||
| 'max_sr_images', | ||
| 'karma_to_post', | ||
| + 'discussion_karma_to_post', | ||
| 'side_comments_max_age', | ||
| 'side_posts_max_age', | ||
| 'side_tags_max_age', | ||
View
3
r2/r2/lib/pages/pages.py
| @@ -1340,3 +1340,6 @@ class SiteMeter(Wrapped): | ||
| def __init__(self, codename, *a, **kw): | ||
| self.codename = codename | ||
| Wrapped.__init__(self, *a, **kw) | ||
| + | ||
| +class NotEnoughKarmaToPost(Wrapped): | ||
| + pass | ||
View
2
r2/r2/models/subreddit.py
| @@ -173,6 +173,8 @@ def can_submit(self, user): | ||
| return True | ||
| elif self.is_banned(user): | ||
| return False | ||
| + elif self == Subreddit._by_name('discussion') and user.safe_karma < g.discussion_karma_to_post: | ||
| + return False | ||
| elif self.type == 'public': | ||
| return True | ||
| elif self.is_moderator(user) or self.is_contributor(user): | ||
View
6
r2/r2/templates/notenoughkarmatopost.html
| @@ -0,0 +1,6 @@ | ||
| +<div class="md"> | ||
| +To post new articles to the the main Less Wrong site you must have at least | ||
| +${g.karma_to_post} karma points. To post to the Discussion area you must have | ||
| +at least ${g.discussion_karma_to_post} points. For more information about how | ||
| +karma is used on Less Wrong see, <a href="/about-less-wrong">About Less Wrong</a>. | ||
| +</div> |