Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Provide option to let users self-assign link flair.
Browse files Browse the repository at this point in the history
  • Loading branch information
Logan Hanks committed Apr 17, 2012
1 parent c570ec4 commit fbc4859
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
17 changes: 14 additions & 3 deletions r2/r2/controllers/api.py
Expand Up @@ -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',
Expand All @@ -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()

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions r2/r2/lib/pages/things.py
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions r2/r2/models/modaction.py
Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions r2/r2/models/subreddit.py
Expand Up @@ -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')
Expand Down
11 changes: 11 additions & 0 deletions r2/r2/templates/flairpane.html
Expand Up @@ -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">
Expand Down

0 comments on commit fbc4859

Please sign in to comment.