diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index 75ee80017..2f8335ce7 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -80,6 +80,7 @@ from r2.lib.validator import ( VOneOf, VPromoCampaign, VRatelimit, + VSelfText, VShamedDomain, VSponsor, VSponsorAdmin, @@ -391,6 +392,8 @@ class PromoteController(ListingController): l=VLink('link_id'), title=VTitle('title'), url=VUrl('url', allow_self=False, lookup=False), + selftext=VSelfText('text'), + kind=VOneOf('kind', ['link', 'self']), ip=ValidIP(), disable_comments=VBoolean("disable_comments"), media_width=VInt("media-width", min=0), @@ -399,7 +402,7 @@ class PromoteController(ListingController): media_override=VBoolean("media-override"), domain_override=VLength("domain", 100) ) - def POST_edit_promo(self, form, jquery, ip, l, title, url, + def POST_edit_promo(self, form, jquery, ip, l, title, url, selftext, kind, disable_comments, media_height, media_width, media_embed, media_override, domain_override): @@ -426,17 +429,29 @@ class PromoteController(ListingController): # want the URL url = url[0].url + if kind == 'link': + if form.has_errors('url', errors.NO_URL, errors.BAD_URL): + return + # users can change the disable_comments on promoted links if ((not l or not promote.is_promoted(l)) and - (form.has_errors('title', errors.NO_TEXT, - errors.TOO_LONG) or - form.has_errors('url', errors.NO_URL, errors.BAD_URL) or - jquery.has_errors('ratelimit', errors.RATELIMIT))): + (form.has_errors('title', errors.NO_TEXT, errors.TOO_LONG) or + jquery.has_errors('ratelimit', errors.RATELIMIT))): return if not l: - l = promote.new_promotion(title, url, c.user, ip) + l = promote.new_promotion(title, url if kind == 'link' else 'self', + selftext if kind == 'self' else '', + c.user, ip) + elif promote.is_promo(l): + # changing link type is not allowed + if ((l.is_self and kind == 'link') or + (not l.is_self and kind == 'self')): + c.errors.add(errors.NO_CHANGE_KIND, field="kind") + form.set_error(errors.NO_CHANGE_KIND, "kind") + return + changed = False # live items can only be changed by a sponsor, and also # pay the cost of de-approving the link @@ -445,7 +460,8 @@ class PromoteController(ListingController): if title and title != l.title: l.title = title changed = not trusted - if url and url != l.url: + + if kind == 'link' and url and url != l.url: l.url = url changed = not trusted @@ -455,6 +471,10 @@ class PromoteController(ListingController): if trusted and promote.is_unapproved(l): promote.accept_promotion(l) + # selftext can be changed at any time + if kind == 'self': + l.selftext = selftext + # comment disabling is free to be changed any time. l.disable_comments = disable_comments if c.user_is_sponsor or c.user.trusted_sponsor: diff --git a/r2/r2/lib/errors.py b/r2/r2/lib/errors.py index 067657d1f..4caa3b939 100644 --- a/r2/r2/lib/errors.py +++ b/r2/r2/lib/errors.py @@ -131,6 +131,7 @@ error_list = dict(( ('JSON_PARSE_ERROR', _('unable to parse JSON data')), ('JSON_INVALID', _('unexpected JSON structure')), ('JSON_MISSING_KEY', _('JSON missing key: "%(key)s"')), + ('NO_CHANGE_KIND', _("can't change post type")), )) errors = Storage([(e, e) for e in error_list.keys()]) diff --git a/r2/r2/lib/promote.py b/r2/r2/lib/promote.py index df4ed5cdc..e54a2755f 100644 --- a/r2/r2/lib/promote.py +++ b/r2/r2/lib/promote.py @@ -290,7 +290,7 @@ def traffic_totals(): traffic_data = traffic.zip_timeseries(impressions, clicks) return [(d.date(), v) for d, v in traffic_data] -def new_promotion(title, url, user, ip): +def new_promotion(title, url, selftext, user, ip): """ Creates a new promotion with the provided title, etc, and sets it status to be 'unpaid'. @@ -300,6 +300,12 @@ def new_promotion(title, url, user, ip): l.promoted = True l.disable_comments = False PromotionLog.add(l, 'promotion created') + + if url == 'self': + l.url = l.make_permalink_slow() + l.is_self = True + l.selftext = selftext + l._commit() # set the status of the link, populating the query queue diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index c44975cf5..13c7e70f1 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -4274,6 +4274,10 @@ ul.tabmenu.formtab { width: 100%; } +#kind-selector label { + padding-right: 20px; +} + .campaign { border: 1px solid #336699; background-color: #EFF7FF; diff --git a/r2/r2/templates/promotedlink.html b/r2/r2/templates/promotedlink.html index 0ca1da4d9..5c1c47e4f 100644 --- a/r2/r2/templates/promotedlink.html +++ b/r2/r2/templates/promotedlink.html @@ -52,6 +52,12 @@ ${unsafe(taglinetext % dict(date = thing._date.strftime("%Y-%m-%d"), report = report)} +<%def name="domain()"> + %if not thing.is_self: + ${parent.domain()} + %endif + + <%def name="entry()"> ${parent.entry()}
+ + + + +
+ + + <%def name="url_field(link, editable=False, enable_override=False)"> <%utils:line_field title="${_('url')}" id="url-field" css_class="rounded"> - +<%def name="text_field(text='', visible=True)"> + <%utils:line_field title="${_('text')}" id="text-field" css_class="rounded" + style="${('' if visible else 'display:none')}"> + ${UserText(None, text=text, have_form=False, creating=True)} + + + <%def name="image_field(link)"> <%utils:line_field title="${_('look and feel')}" description="${_('images will be resized if larger than 70 x 70 pixels')}" diff --git a/r2/r2/templates/promotelinknew.html b/r2/r2/templates/promotelinknew.html index fd392572c..212ccd2e1 100644 --- a/r2/r2/templates/promotelinknew.html +++ b/r2/r2/templates/promotelinknew.html @@ -20,7 +20,7 @@ ## reddit Inc. All Rights Reserved. ############################################################################### -<%namespace file="promotelinkform.html" import="title_field, url_field" /> +<%namespace file="promotelinkform.html" import="title_field, url_field, text_field, kind_selector" /> <%namespace file="utils.html" import="error_field" /> <%namespace name="utils" file="utils.html"/> @@ -33,7 +33,9 @@
${title_field(None, editable=True)} + ${kind_selector()} ${url_field(None, editable=True, enable_override=c.user_is_sponsor)} + ${text_field(visible=False)}
By clicking "next" you agree to the Self Serve Advertising Rules.