This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Provide option to let users self-assign link flair.

  • Loading branch information...
Logan Hanks
Logan Hanks committed Apr 17, 2012
1 parent c570ec4 commit fbc4859634325e0a7fb970249fdff0eca12f69cd
View
@@ -2293,10 +2293,13 @@ def POST_setflairenabled(self, form, jquery, flair_enabled):
flair_position = VOneOf("flair_position", ("left", "right")),
link_flair_position = VOneOf("link_flair_position",
("", "left", "right")),
- flair_self_assign_enabled = VBoolean("flair_self_assign_enabled"))
+ flair_self_assign_enabled = VBoolean("flair_self_assign_enabled"),
+ link_flair_self_assign_enabled =
+ VBoolean("link_flair_self_assign_enabled"))
@api_doc(api_section.flair)
def POST_flairconfig(self, form, jquery, flair_enabled, flair_position,
- link_flair_position, flair_self_assign_enabled):
+ link_flair_position, flair_self_assign_enabled,
+ link_flair_self_assign_enabled):
if c.site.flair_enabled != flair_enabled:
c.site.flair_enabled = flair_enabled
ModAction.create(c.site, c.user, action='editflair',
@@ -2313,6 +2316,12 @@ def POST_flairconfig(self, form, jquery, flair_enabled, flair_position,
c.site.flair_self_assign_enabled = flair_self_assign_enabled
ModAction.create(c.site, c.user, action='editflair',
details='flair_self_enabled')
+ if (c.site.link_flair_self_assign_enabled
+ != link_flair_self_assign_enabled):
+ c.site.link_flair_self_assign_enabled = (
+ link_flair_self_assign_enabled)
+ ModAction.create(c.site, c.user, action='editflair',
+ details='link_flair_self_enabled')
c.site._commit()
jquery.refresh()
@@ -2444,9 +2453,11 @@ def POST_selectflair(self, form, jquery, user, link, flair_template_id,
site = c.site
else:
site = Subreddit._byID(link.sr_id, data=True)
+ self_assign_enabled = site.link_flair_self_assign_enabled
else:
flair_type = USER_FLAIR
site = c.site
+ self_assign_enabled = site.flair_self_assign_enabled
if flair_template_id:
try:
@@ -2461,7 +2472,7 @@ def POST_selectflair(self, form, jquery, user, link, flair_template_id,
text = None
if not site.is_moderator(c.user) and not c.user_is_admin:
- if not site.flair_self_assign_enabled:
+ if not self_assign_enabled:
# TODO: serve error to client
g.log.debug('flair self-assignment not permitted')
return
View
@@ -2519,7 +2519,9 @@ def __init__(self, num, after, reverse, name, user):
flair_enabled=c.site.flair_enabled,
flair_position=c.site.flair_position,
link_flair_position=c.site.link_flair_position,
- flair_self_assign_enabled=c.site.flair_self_assign_enabled)
+ flair_self_assign_enabled=c.site.flair_self_assign_enabled,
+ link_flair_self_assign_enabled=
+ c.site.link_flair_self_assign_enabled)
class FlairList(Templated):
"""List of users who are tagged with flair within a subreddit."""
@@ -2694,6 +2696,9 @@ def __init__(self, user=None, link=None, site=None):
target_wrapper = (
lambda flair_template: FlairSelectorLinkSample(
link, site, flair_template))
+ self_assign_enabled = (
+ c.user._id == link.author_id
+ and site.link_flair_self_assign_enabled)
else:
flair_type = USER_FLAIR
target = user
@@ -2705,14 +2710,17 @@ def __init__(self, user=None, link=None, site=None):
user, subreddit=site, force_show_flair=True,
flair_template=flair_template,
flair_text_editable=admin or template.text_editable))
+ self_assign_enabled = site.flair_self_assign_enabled
text = getattr(target, attr_pattern % 'text', '')
css_class = getattr(target, attr_pattern % 'css_class', '')
templates, matching_template = self._get_templates(
site, flair_type, text, css_class)
- if site.flair_self_assign_enabled or admin:
+ if self_assign_enabled or admin:
choices = [target_wrapper(template) for template in templates]
+ else:
+ choices = []
# If one of the templates is already selected, modify its text to match
# the user's current flair.
@@ -91,8 +91,7 @@ def __init__(self, thing, comments = True, delete = True, report = True):
else:
show_unmarknsfw = False
- # add "or is_author" to allow submitters to edit flair on their links
- show_flair = thing.can_ban
+ show_flair = thing.can_ban or is_author
# do we show the delete button?
show_delete = is_author and delete and not thing._deleted
@@ -93,6 +93,7 @@ class ModAction(tdb_cassandra.UuidThing, Printable):
'flair_position': _('toggle user flair position'),
'link_flair_position': _('toggle link flair position'),
'flair_self_enabled': _('toggle user assigned flair enabled'),
+ 'link_flair_self_enabled': _('toggle submitter assigned link flair enabled'),
'flair_template': _('add/edit flair templates'),
'flair_delete_template': _('delete flair template'),
'flair_clear_template': _('clear flair templates'),
@@ -77,6 +77,7 @@ class Subreddit(Thing, Printable):
flair_position = 'right', # one of ('left', 'right')
link_flair_position = '', # one of ('', 'left', 'right')
flair_self_assign_enabled = False,
+ link_flair_self_assign_enabled = False,
)
_essentials = ('type', 'name', 'lang')
_data_int_props = Thing._data_int_props + ('mod_actions', 'reported')
@@ -49,6 +49,17 @@ <h1>${_("flair settings")} | &#32;<strong>${c.site.name}</strong></h1>
<label for="sr_flair_self_assign_enabled">
${_("allow users to assign their own flair")}
</label>
+ <br>
+ <input type="checkbox"
+ id="sr_link_flair_self_assign_enabled"
+ name="link_flair_self_assign_enabled"
+ %if thing.link_flair_self_assign_enabled:
+ checked="checked"
+ %endif
+ />
+ <label for="sr_link_flair_self_assign_enabled">
+ ${_("allow submitters to assign their own link flair")}
+ </label>
</%utils:line_field>
<%utils:line_field title="${_('user flair position')}">
<table class="small-field">

0 comments on commit fbc4859

Please sign in to comment.