diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index 0d7dfb072..748e7f3b3 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -2006,13 +2006,17 @@ class ApiController(RedditController): c.user._commit() jquery.refresh() - @validatedForm(VFlairManager(), - VModhash(), - flair_enabled = VBoolean("flair_enabled"), - flair_position = VOneOf("flair_position", ("left", "right"))) - def POST_flairconfig(self, form, jquery, flair_enabled, flair_position): + @validatedForm( + VFlairManager(), + VModhash(), + flair_enabled = VBoolean("flair_enabled"), + flair_position = VOneOf("flair_position", ("left", "right")), + flair_self_assign_enabled = VBoolean("flair_self_assign_enabled")) + def POST_flairconfig(self, form, jquery, flair_enabled, flair_position, + flair_self_assign_enabled): c.site.flair_enabled = flair_enabled c.site.flair_position = flair_position + c.site.flair_self_assign_enabled = flair_self_assign_enabled c.site._commit() jquery.refresh() @@ -2083,6 +2087,11 @@ class ApiController(RedditController): flair_template_id, c.site._id) return + if not c.site.flair_self_assign_enabled: + # TODO: serve error to client + g.log.debug('flair self-assignment not permitted') + return + text = flair_template.text css_class = flair_template.css_class diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index 0099b3e60..8e3da9964 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -2421,7 +2421,8 @@ class FlairPane(Templated): self, tabs=TabbedPane(tabs), flair_enabled=c.site.flair_enabled, - flair_position=c.site.flair_position) + flair_position=c.site.flair_position, + flair_self_assign_enabled=c.site.flair_self_assign_enabled) class FlairList(Templated): """List of users who are tagged with flair within a subreddit.""" @@ -2541,11 +2542,16 @@ class FlairPrefs(CachedTemplate): sr_flair_enabled = getattr(c.site, 'flair_enabled', True) user_flair_enabled = getattr(c.user, 'flair_%s_enabled' % c.site._id, True) + sr_flair_self_assign_enabled = getattr( + c.site, 'flair_self_assign_enabled', True) wrapped_user = WrappedUser(c.user, subreddit=c.site, force_show_flair=True) - CachedTemplate.__init__(self, sr_flair_enabled=sr_flair_enabled, - user_flair_enabled=user_flair_enabled, - wrapped_user=wrapped_user) + CachedTemplate.__init__( + self, + sr_flair_enabled=sr_flair_enabled, + sr_flair_self_assign_enabled=sr_flair_self_assign_enabled, + user_flair_enabled=user_flair_enabled, + wrapped_user=wrapped_user) class FlairSelector(CachedTemplate): """Provide user with flair options according to subreddit settings.""" diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 4643a071a..6ed5ca791 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -75,6 +75,7 @@ class Subreddit(Thing, Printable): link_type = 'any', # one of ('link', 'self', 'any') flair_enabled = True, flair_position = 'right', # one of ('left', 'right') + flair_self_assign_enabled = False, ) _essentials = ('type', 'name', 'lang') _data_int_props = Thing._data_int_props + ('mod_actions', 'reported') diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index 1a2d727dc..62056441c 100644 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -688,6 +688,13 @@ ul.flat-vert {text-align: left;} .flairselector { font-size: x-small; position: absolute; width: 400px; } +.flairselector h2 { + background: #cee3f8; + padding-bottom: 2px; + margin-bottom: 3px; + text-align: center; +} + .flairselector.drop-choices.active { border: 1px solid gray; display: block; diff --git a/r2/r2/public/static/js/flair.js b/r2/r2/public/static/js/flair.js index a002e3ed0..7302f1aef 100644 --- a/r2/r2/public/static/js/flair.js +++ b/r2/r2/public/static/js/flair.js @@ -67,7 +67,7 @@ $(function() { .css("left", ($(button).position().left + $(button).width() - width) + "px"); - $(".flairselector li").click(postFlairSelection); + $(".flairselector li:not(.error)").click(postFlairSelection); } $(".flairselector").html(''); diff --git a/r2/r2/templates/flairpane.html b/r2/r2/templates/flairpane.html index ba37b52c8..27a164134 100644 --- a/r2/r2/templates/flairpane.html +++ b/r2/r2/templates/flairpane.html @@ -35,7 +35,20 @@ checked="checked" %endif /> - + +
+ + <%utils:line_field title="${_('flair position')}"> diff --git a/r2/r2/templates/flairprefs.html b/r2/r2/templates/flairprefs.html index 71df07072..18ed1bb0a 100644 --- a/r2/r2/templates/flairprefs.html +++ b/r2/r2/templates/flairprefs.html @@ -30,8 +30,10 @@ > ${_("Show my flair on this reddit. It looks like:")}
${thing.wrapped_user}
- select -
+ %if thing.sr_flair_self_assign_enabled: + select +
+ %endif %endif diff --git a/r2/r2/templates/flairselector.html b/r2/r2/templates/flairselector.html index 4764e7c33..8721d2e73 100644 --- a/r2/r2/templates/flairselector.html +++ b/r2/r2/templates/flairselector.html @@ -20,15 +20,22 @@ ## CondeNet, Inc. All Rights Reserved. ################################################################################ +

${_("select flair")}