diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 1e3e557b9..17c79c375 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -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)) diff --git a/r2/r2/controllers/errors.py b/r2/r2/controllers/errors.py index 3064ee7ae..f360afef4 100644 --- a/r2/r2/controllers/errors.py +++ b/r2/r2/controllers/errors.py @@ -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?'), diff --git a/r2/r2/controllers/validator/validator.py b/r2/r2/controllers/validator/validator.py index 978778c2a..adc0594de 100644 --- a/r2/r2/controllers/validator/validator.py +++ b/r2/r2/controllers/validator/validator.py @@ -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...! diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 20daf4146..4c9e5cf52 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -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: diff --git a/r2/r2/templates/createsubreddit.html b/r2/r2/templates/createsubreddit.html index 292fbef54..38b20ea4f 100644 --- a/r2/r2/templates/createsubreddit.html +++ b/r2/r2/templates/createsubreddit.html @@ -131,79 +131,6 @@ function update_title() { ${error_field("DESC_TOO_LONG", "span")} - - %if c.user_is_admin: -