Skip to content

Conversation

@Watchful1
Copy link
Contributor

@Watchful1 Watchful1 commented Aug 2, 2021

Currently there's no way for a non-moderator to get a list of available flair templates without an existing submission.

https://praw.readthedocs.io/en/latest/code_overview/models/submission.html#praw.models.Submission.flair

only works if you have a submission to call it on.

https://praw.readthedocs.io/en/latest/code_overview/other/subredditflair.html#praw.models.reddit.subreddit.SubredditFlair.link_templates

only works if you're a moderator.

Sometime reddit added a is_newlink parameter to the flairselector endpoint so you can call it without a submission.

Starting point for discussion, I'm not quite sure where this function should live or what it should be called. From a users perspective, it functions very similarly to the moderator endpoint, but it returns slightly different fields, and only the flairs the user has access to.

link_flair endpoint (mod only)

[
   {'type': 'richtext', 'text_editable': True, 'allowable_content': 'text', 'text': 'test 1', 'max_emojis': 10, 'text_color': 'light', 'mod_only': False, 'css_class': 'test 1', 'richtext': [{'e': 'text', 't': 'test 1'}], 'background_color': '#ffb000', 'id': 'ca999154-c1b0-11e7-b30b-0eb8423d5ed8'}, 
   {'type': 'richtext', 'text_editable': False, 'allowable_content': 'all', 'text': 'test 2', 'max_emojis': 10, 'text_color': 'dark', 'mod_only': False, 'css_class': 'test 2', 'richtext': [{'e': 'text', 't': 'test 2'}], 'background_color': '#d3d6da', 'id': '865ba524-692d-11e9-9811-0e2f1d7746a8'}, 
   {'type': 'richtext', 'text_editable': False, 'allowable_content': 'all', 'text': 'test 3', 'max_emojis': 10, 'text_color': 'dark', 'mod_only': True, 'css_class': 'test 3', 'richtext': [{'e': 'text', 't': 'test 3'}], 'background_color': '#d3d6da', 'id': 'a3a58892-f32e-11eb-8417-ca14b6cf40a6'}
]

flairselector endpoint

[
    {'flair_css_class': 'test 1', 'flair_template_id': 'ca999154-c1b0-11e7-b30b-0eb8423d5ed8', 'flair_text_editable': True, 'flair_position': 'right', 'flair_text': 'test 1'}, 
    {'flair_css_class': 'test 2', 'flair_template_id': '865ba524-692d-11e9-9811-0e2f1d7746a8', 'flair_text_editable': True, 'flair_position': 'right', 'flair_text': 'test 2'}
]

Copy link
Member

@LilSpazJoekp LilSpazJoekp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start!

We'll need some tests for this and it appears that pre_push.py still needs to be ran.

Does running the mod only endpoint cause an error if the authenticated user is not a mod? If so maybe we could have the mod endpoint fallback on the new one.

@Watchful1
Copy link
Contributor Author

Does running the mod only endpoint cause an error if the authenticated user is not a mod? If so maybe we could have the mod endpoint fallback on the new one.

The field names are different. For example in link_flair it's text while in flairselector it's flair_text. So I guess they aren't completely interchangeable. Otherwise just falling back would be really intuitive.

Calling it user_selectable makes sense. I'll change it to that and get everything cleaned up.

@LilSpazJoekp
Copy link
Member

The field names are different. For example in link_flair it's text while in flairselector it's flair_text. So I guess they aren't completely interchangeable.

Ah okay, I missed that.

Copy link
Member

@LilSpazJoekp LilSpazJoekp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! I just have two tiny suggestions.

@LilSpazJoekp LilSpazJoekp merged commit d697ef6 into praw-dev:master Aug 4, 2021
@LilSpazJoekp
Copy link
Member

Thank you! 🎇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants