mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
OAuth2: Add personal "flair" scope
Allows token bearer to manipulate user flair, and the flair of his submitted links Give /api/setflairenabled "flair" scope Give /api/flairselector "flair" scope
This commit is contained in:
@@ -69,6 +69,7 @@ api('wikipagesettings', WikiSettingsJsonTemplate)
|
||||
|
||||
api('flairlist', FlairListJsonTemplate)
|
||||
api('flaircsv', FlairCsvJsonTemplate)
|
||||
api('flairselector', FlairSelectorJsonTemplate)
|
||||
|
||||
api('subredditstylesheet', StylesheetTemplate)
|
||||
api('subredditstylesheetsource', StylesheetTemplate)
|
||||
|
||||
@@ -3051,6 +3051,7 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
|
||||
return BoringPage(_("API"), content = results).render()
|
||||
|
||||
@require_oauth2_scope("flair")
|
||||
@validatedForm(VUser(),
|
||||
VModhash(),
|
||||
flair_enabled = VBoolean("flair_enabled"))
|
||||
@@ -3204,6 +3205,7 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
ModAction.create(c.site, c.user, action='editflair',
|
||||
details='flair_clear_template')
|
||||
|
||||
@require_oauth2_scope("flair")
|
||||
@validate(VUser(),
|
||||
user = VFlairAccount('name'),
|
||||
link = VFlairLink('link'))
|
||||
@@ -3220,6 +3222,7 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
user = None
|
||||
return FlairSelector(user=user).render()
|
||||
|
||||
@require_oauth2_scope("flair")
|
||||
@validatedForm(VUser(),
|
||||
VModhash(),
|
||||
user = VFlairAccount('name'),
|
||||
|
||||
@@ -819,6 +819,63 @@ class FlairCsvJsonTemplate(JsonTemplate):
|
||||
def render(self, thing, *a, **kw):
|
||||
return ObjectTemplate([l.__dict__ for l in thing.results_by_line])
|
||||
|
||||
|
||||
class FlairSelectorJsonTemplate(JsonTemplate):
|
||||
def _template_dict(self, flair):
|
||||
return {"flair_template_id": flair.flair_template_id,
|
||||
"flair_position": flair.flair_position,
|
||||
"flair_text": flair.flair_text,
|
||||
"flair_css_class": flair.flair_css_class,
|
||||
"flair_text_editable": flair.flair_text_editable}
|
||||
|
||||
def render(self, thing, *a, **kw):
|
||||
"""Render a list of flair choices into JSON
|
||||
|
||||
Sample output:
|
||||
{
|
||||
"choices": [
|
||||
{
|
||||
"flair_css_class": "flair-444",
|
||||
"flair_position": "right",
|
||||
"flair_template_id": "5668d204-9388-11e3-8109-080027a38559",
|
||||
"flair_text": "444",
|
||||
"flair_text_editable": true
|
||||
},
|
||||
{
|
||||
"flair_css_class": "flair-nouser",
|
||||
"flair_position": "right",
|
||||
"flair_template_id": "58e34d7a-9388-11e3-ab01-080027a38559",
|
||||
"flair_text": "nouser",
|
||||
"flair_text_editable": true
|
||||
},
|
||||
{
|
||||
"flair_css_class": "flair-bar",
|
||||
"flair_position": "right",
|
||||
"flair_template_id": "fb01cc04-9391-11e3-b1d6-080027a38559",
|
||||
"flair_text": "foooooo",
|
||||
"flair_text_editable": true
|
||||
}
|
||||
],
|
||||
"current": {
|
||||
"flair_css_class": "444",
|
||||
"flair_position": "right",
|
||||
"flair_template_id": "5668d204-9388-11e3-8109-080027a38559",
|
||||
"flair_text": "444"
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
choices = [self._template_dict(choice) for choice in thing.choices]
|
||||
|
||||
current_flair = {
|
||||
"flair_text": thing.text,
|
||||
"flair_css_class": thing.css_class,
|
||||
"flair_position": thing.position,
|
||||
"flair_template_id": thing.matching_template,
|
||||
}
|
||||
return ObjectTemplate({"current": current_flair, "choices": choices})
|
||||
|
||||
|
||||
class StylesheetTemplate(ThingJsonTemplate):
|
||||
_data_attrs_ = dict(
|
||||
images='_images',
|
||||
|
||||
@@ -3165,6 +3165,9 @@ class FlairSelector(CachedTemplate):
|
||||
matching_template=matching_template,
|
||||
target_name=target_name)
|
||||
|
||||
def render(self, *a, **kw):
|
||||
return responsive(CachedTemplate.render(self, *a, **kw), True)
|
||||
|
||||
def _get_templates(self, site, flair_type, text, css_class):
|
||||
ids = FlairTemplateBySubredditIndex.get_template_ids(
|
||||
site._id, flair_type)
|
||||
|
||||
@@ -105,6 +105,12 @@ class OAuth2Scope:
|
||||
"name": _("Edit Posts"),
|
||||
"description": _("Edit and delete my comments and submissions."),
|
||||
},
|
||||
"flair": {
|
||||
"id": "flair",
|
||||
"name": _("Manage My Flair"),
|
||||
"description": _("Select my subreddit flair. "
|
||||
"Change link flair on my submissions."),
|
||||
},
|
||||
"history": {
|
||||
"id": "history",
|
||||
"name": _("History"),
|
||||
|
||||
Reference in New Issue
Block a user