def spam(self, things, auto, moderator_banned, banner, date = None, **kw): from r2.lib.db import queries things = [x for x in tup(things) if not x._spam] Report.accept(things, True) for t in things: t._spam = True ban_info = copy(getattr(t, 'ban_info', {})) ban_info.update(auto = auto, moderator_banned = moderator_banned, banned_at = date or datetime.now(g.tz), **kw) if isinstance(banner, dict): ban_info['banner'] = banner[t._fullname] else: ban_info['banner'] = banner t.ban_info = ban_info t._commit() changed(t) if not auto: self.author_spammer(things, True) self.set_last_sr_ban(things) queries.ban(things)
def POST_comment(self, res, parent, comment, ip): res._update('status_' + parent._fullname, innerHTML = '') should_ratelimit = True #check the parent type here cause we need that for the #ratelimit checks if isinstance(parent, Message): is_message = True should_ratelimit = False else: is_message = False is_comment = True if isinstance(parent, Link): link = parent parent_comment = None else: link = Link._byID(parent.link_id, data = True) parent_comment = parent sr = parent.subreddit_slow if not sr.should_ratelimit(c.user, 'comment'): should_ratelimit = False #remove the ratelimit error if the user's karma is high if not should_ratelimit: c.errors.remove(errors.RATELIMIT) if res._chk_error(errors.BAD_COMMENT, parent._fullname) or \ res._chk_error(errors.COMMENT_TOO_LONG, parent._fullname) or \ res._chk_error(errors.RATELIMIT, parent._fullname): res._focus("comment_reply_" + parent._fullname) return res._show('reply_' + parent._fullname) res._update("comment_reply_" + parent._fullname, rows = 2) spam = (c.user._spam or errors.BANNED_IP in c.errors) if is_message: to = Account._byID(parent.author_id) subject = parent.subject re = "re: " if not subject.startswith(re): subject = re + subject item = Message._new(c.user, to, subject, comment, ip, spam) item.parent_id = parent._id res._send_things(item) else: item = Comment._new(c.user, link, parent_comment, comment, ip, spam) Vote.vote(c.user, item, True, ip) res._update("comment_reply_" + parent._fullname, innerHTML='', value='') res._send_things(item) res._hide('noresults') # flag search indexer that something has changed tc.changed(item) #set the ratelimiter if should_ratelimit: VRatelimit.ratelimit(rate_user=True, rate_ip = True, prefix = "rate_comment_")
def _subscribe(self, sr, sub): Subreddit.subscribe_defaults(c.user) if sub: if sr.add_subscriber(c.user): sr._incr('_ups', 1) else: if sr.remove_subscriber(c.user): sr._incr('_ups', -1) tc.changed(sr)
def POST_site_admin(self, res, name ='', sr = None, **kw): res._update('status', innerHTML = '') redir = False kw = dict((k, v) for k, v in kw.iteritems() if v is not None and k in ('name', 'title', 'description', 'firsttext', 'static_path', 'ad_file', 'over_18', 'type', 'header', 'lang', 'stylesheet')) #if a user is banned, return rate-limit errors if c.user._spam: time = timeuntil(datetime.now(g.tz) + timedelta(seconds=600)) c.errors.add(errors.RATELIMIT, {'time': time}) if not sr and res._chk_error(errors.RATELIMIT): pass elif not sr and res._chk_errors((errors.SUBREDDIT_EXISTS, errors.BAD_SR_NAME)): res._hide('example_name') res._focus('name') elif res._chk_errors((errors.NO_TITLE, errors.TITLE_TOO_LONG)): res._hide('example_title') res._focus('title') elif res._chk_error(errors.INVALID_SUBREDDIT_TYPE): pass elif res._chk_error(errors.DESC_TOO_LONG): res._focus('description') if not sr and not res.error: #sending kw is ok because it was sanitized above sr = Subreddit._new(name = name, **kw) Subreddit.subscribe_defaults(c.user) # make sure this user is on the admin list of that site! if sr.add_subscriber(c.user): sr._incr('_ups', 1) sr.add_moderator(c.user) sr.add_contributor(c.user) redir = sr.path + "about/edit/" if not c.user_is_admin: VRatelimit.ratelimit(rate_user=True, rate_ip = True, prefix = "create_reddit_") if not res.error: #assume sr existed, or was just built for k, v in kw.iteritems(): setattr(sr, k, v) sr._commit() # flag search indexer that something has changed tc.changed(sr) if redir: res._redirect(redir)
def POST_editcomment(self, res, comment, body): res._update('status_' + comment._fullname, innerHTML = '') if (not res._chk_error(errors.BAD_COMMENT, comment._fullname) and not res._chk_error(errors.NOT_AUTHOR, comment._fullname)): comment.body = body if not c.user_is_admin: comment.editted = True comment._commit() res._send_things(comment) # flag search indexer that something has changed tc.changed(comment)
def POST_del(self, res, thing): '''for deleting all sorts of things''' thing._deleted = True thing._commit() # flag search indexer that something has changed tc.changed(thing) #expire the item from the sr cache if isinstance(thing, Link): sr = thing.subreddit_slow expire_hot(sr)
def unspam(self, things, unbanner = None): Report.accept(things, False) things = [ x for x in tup(things) if x._spam ] for t in things: ban_info = copy(getattr(t, 'ban_info', {})) ban_info['unbanned_at'] = datetime.now(g.tz) if unbanner: ban_info['unbanner'] = unbanner t.ban_info = ban_info t._spam = False t._commit() changed(t) self.author_spammer(things, False) queries.unban(things)
def POST_vote(self, res, dir, thing, ip, vote_type): ip = request.ip user = c.user spam = (c.user._spam or errors.BANNED_IP in c.errors or errors.CHEATER in c.errors) if thing: dir = (True if dir > 0 else False if dir < 0 else None) organic = vote_type == 'organic' Vote.vote(user, thing, dir, ip, spam, organic) # flag search indexer that something has changed tc.changed(thing)
def spam(self, things, auto, moderator_banned, banner, date = None, **kw): Report.accept(things, True) things = [ x for x in tup(things) if not x._spam ] for t in things: t._spam = True ban_info = copy(getattr(t, 'ban_info', {})) ban_info.update(auto = auto, moderator_banned = moderator_banned, banner = banner, banned_at = date or datetime.now(g.tz), **kw) t.ban_info = ban_info t._commit() changed(t) self.author_spammer(things, True) queries.ban(things)
def unspam(self, things, unbanner = None): from r2.lib.db import queries things = [x for x in tup(things) if x._spam] Report.accept(things, False) for t in things: ban_info = copy(getattr(t, 'ban_info', {})) ban_info['unbanned_at'] = datetime.now(g.tz) if unbanner: ban_info['unbanner'] = unbanner t.ban_info = ban_info t._spam = False t._commit() changed(t) # auto is always False for unbans self.author_spammer(things, False) self.set_last_sr_ban(things) queries.unban(things)
def POST_submit(self, res, url, title, save, sr, ip): res._update('status', innerHTML = '') if url: res._update('url', value=url) should_ratelimit = sr.should_ratelimit(c.user, 'link') #remove the ratelimit error if the user's karma is high if not should_ratelimit: c.errors.remove(errors.RATELIMIT) # check for no url, or clear that error field on return if res._chk_errors((errors.NO_URL, errors.BAD_URL)): res._focus('url') elif res._chk_error(errors.ALREADY_SUB): link = Link._by_url(url, sr) res._redirect(link.already_submitted_link) #ratelimiter elif res._chk_error(errors.RATELIMIT): pass # check for title, otherwise look it up and return it elif res._chk_error(errors.NO_TITLE): # clear out this error res._chk_error(errors.TITLE_TOO_LONG) # try to fetch the title title = get_title(url) if title: res._update('title', value = title) res._focus('title') res._clear_error(errors.NO_TITLE) c.errors.remove(errors.NO_TITLE) return res._focus('title') elif res._chk_error(errors.TITLE_TOO_LONG): res._focus('title') elif res._chk_captcha(errors.BAD_CAPTCHA): pass if res.error or not title: return # check whether this is spam: spam = (c.user._spam or errors.BANNED_IP in c.errors or errors.BANNED_DOMAIN in c.errors) # well, nothing left to do but submit it l = Link._submit(request.post.title, url, c.user, sr, ip, spam) if url.lower() == 'self': l.url = l.permalink l.is_self = True l._commit() Vote.vote(c.user, l, True, ip, spam) if save == 'on': l._save(c.user) #set the ratelimiter if should_ratelimit: VRatelimit.ratelimit(rate_user=True, rate_ip = True) # flag search indexer that something has changed tc.changed(l) res._redirect(l.permalink)