fix way more sr creation bugs than should have existed

This commit is contained in:
spez
2008-09-17 17:56:05 -07:00
parent 1bcac35d06
commit 3b1bcee47b
5 changed files with 24 additions and 98 deletions

View File

@@ -947,17 +947,12 @@ class ApiController(RedditController):
VRatelimit(rate_user = True,
rate_ip = True,
prefix = 'create_reddit_'),
sr = VByName('sr'),
name = VSubredditName("name"),
title = VSubredditTitle("title"),
domain = VCnameDomain("domain"),
description = VSubredditDesc("description"),
firsttext = nop("firsttext"),
header = nop("headerfile"),
lang = VLang("lang"),
stylesheet = nop("stylesheet"),
static_path = nop("staticdir"),
ad_file = nop("ad_file"),
sr = VByName('sr'),
over_18 = VBoolean('over_18'),
show_media = VBoolean('show_media'),
type = VOneOf('type', ('public', 'private', 'restricted'))
@@ -965,10 +960,8 @@ class ApiController(RedditController):
def POST_site_admin(self, res, name ='', sr = None, **kw):
redir = False
kw = dict((k, v) for k, v in kw.iteritems()
if v is not None
and k in ('name', 'title', 'domain', 'description', 'firsttext',
'static_path', 'ad_file', 'over_18', 'show_media',
'type', 'header', 'lang', 'stylesheet'))
if k in ('name', 'title', 'domain', 'description', 'over_18',
'show_media', 'type', 'lang',))
#if a user is banned, return rate-limit errors
if c.user._spam:
@@ -978,7 +971,6 @@ class ApiController(RedditController):
domain = kw['domain']
cname_sr = domain and Subreddit._by_domain(domain)
if cname_sr and (not sr or sr != cname_sr):
kw['domain'] = None
c.errors.add(errors.USED_CNAME)
if not sr and res._chk_error(errors.RATELIMIT):
@@ -998,7 +990,13 @@ class ApiController(RedditController):
elif res._chk_error(errors.DESC_TOO_LONG):
res._focus('description')
if not sr and not res.error:
res._update('status', innerHTML = '')
if res.error:
pass
#creating a new reddit
elif not sr:
#sending kw is ok because it was sanitized above
sr = Subreddit._new(name = name, **kw)
Subreddit.subscribe_defaults(c.user)
@@ -1013,7 +1011,8 @@ class ApiController(RedditController):
rate_ip = True,
prefix = "create_reddit_")
if not res.error:
#editting an existing reddit
elif sr.is_moderator(c.user) or c.user_is_admin:
#assume sr existed, or was just built
clear_memo('subreddit._by_domain',
Subreddit, _force_unicode(sr.domain))

View File

@@ -58,7 +58,7 @@ error_list = dict((
('BANNED_IP', "IP banned"),
('BANNED_DOMAIN', "Domain banned"),
('BAD_CNAME', "that domain isn't going to work"),
('USED_CNAME', "that cname is already in use"),
('USED_CNAME', "that domain is already in use"),
('INVALID_OPTION', _('that option is not valid')),
('DESC_TOO_LONG', _('description is too long')),
('CHEATER', 'what do you think you\'re doing there?'),

View File

@@ -709,18 +709,19 @@ class ValidEmails(Validator):
class VCnameDomain(Validator):
domain_re = re.compile(r'.+\..+')
domain_re = re.compile(r'^([\w]+\.)+[\w]+$')
def run(self, domain):
if (domain
and (not self.domain_re.match(domain)
or domain.endswith('.reddit.com'))):
or domain.endswith('.reddit.com')
or len(domain) > 300)):
c.errors.add(errors.BAD_CNAME)
try:
return str(domain) or ''
except UnicodeEncodeError:
c.errors.add(errors.BAD_CNAME)
return ""
elif domain:
try:
return str(domain).lower()
except UnicodeEncodeError:
c.errors.add(errors.BAD_CNAME)
# NOTE: make sure *never* to have res check these are present
# otherwise, the response could contain reference to these errors...!

View File

@@ -40,10 +40,9 @@ class Subreddit(Thing, Printable):
stylesheet_rtl = None,
stylesheet_contents = '',
stylesheet_hash = '0',
description = None,
firsttext = strings.firsttext,
header = os.path.join(g.static_path,
'base.reddit.com.header.png'),
header = None,
description = '',
images = {},
ad_file = os.path.join(g.static_path, 'ad_default.html'),
reported = 0,
@@ -109,7 +108,7 @@ class Subreddit(Thing, Printable):
@classmethod
def _by_domain(cls, domain):
sr_id = cls._by_domain_cache(_force_unicode(domain))
sr_id = cls._by_domain_cache(_force_unicode(domain).lower())
if sr_id:
return cls._byID(sr_id, True)
else:

View File

@@ -131,79 +131,6 @@ function update_title() {
${error_field("DESC_TOO_LONG", "span")}
</td>
</tr>
%if c.user_is_admin:
<tr>
<th>
<label for="firsttext">${_("first text")}</label>
</th>
<td class="prefright">
<textarea name="firsttext" rows="5" cols="30" class="text">
%if thing.site:
${thing.site.firsttext or ''}
%endif
</textarea>
</td>
<td class="note" id="note_firsttext">
</td>
</tr>
<tr>
<th>
<label for="staticdir">${_("static directory")}</label>
</th>
<td class="prefright">
%if thing.site:
<input type="text" name="staticdir" class="text"
value="${thing.site.static_path or ''}"/>
%else:
<input type="text" name="staticdir" class="text" />
%endif
</td>
<td class="note" id="note_staticdirfile"></td>
</tr>
<tr>
<th>
<label for="headerfile">${_("headerfile")}</label>
</th>
<td class="prefright">
%if thing.site:
<input type="text" name="headerfile" class="text"
value="${thing.site.header or ''}"/>
%else:
<input type="text" name="headerfile" class="text" />
%endif
</td>
<td class="note" id="note_headerfile"></td>
</tr>
<tr>
<th>
<label for="stylesheet">${_("style sheet")}</label>
</th>
<td class="prefright">
%if thing.site:
<input type="text" name="stylesheet" class="text"
value="${thing.site.stylesheet or ''}"/>
%else:
<input type="text" name="stylesheet" class="text" />
%endif
</td>
<td class="note" id="note_stylesheetfile"></td>
</tr>
<tr>
<th>
<label for="adfile">${_("ad file")}</label>
</th>
<td class="prefright">
%if thing.site:
<input type="text" name="ad_file" class="text"
value="${thing.site.ad_file or ''}"/>
%else:
<input type="text" name="ad_file" class="text" />
%endif
</td>
<td class="note" id="note_ad_file"></td>
</tr>
%endif
<tr>
<th>
<label for="lang">${_("language")}</label>