Skip to content
This repository has been archived by the owner. It is now read-only.

Include user's index preference in account API #1164

Closed
wants to merge 3 commits into from

Conversation

@lightswitch05
Copy link
Contributor

lightswitch05 commented Oct 31, 2014

3rd party sites allow indexing of user profiles. Perhaps they will implement noindex if the user's preference is easily accessible. This is an implementation of this request.. I've added hide_from_robots value to the response as well as x-robots-tag: noindex to the header if noindex is enabled.

Example response before the change:

GET http://reddit.local/user/test123/about.json

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.7.3
Date: Sat, 01 Nov 2014 02:39:04 GMT
content-type: application/json; charset=UTF-8
x-ua-compatible: IE=edge
content-length: 257
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-reddit-pagecache: miss
x-ratelimit-remaining: 297
x-ratelimit-used: 3
x-ratelimit-reset: 56

{
  "kind": "t2",
  "data": {
    "name": "test123",
    "is_friend": false,
    "created": 1414750716,
    "created_utc": 1414721916,
    "link_karma": 1,
    "comment_karma": 0,
    "is_gold": false,
    "is_mod": false,
    "has_verified_email": false,
    "id": "pc"
  }
}

Example Response after the change:

GET http://reddit.local/user/test123/about.json

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.7.3
Date: Sat, 01 Nov 2014 02:41:17 GMT
content-type: application/json; charset=UTF-8
x-ua-compatible: IE=edge
x-robots-tag: noindex, nofollow
content-length: 256
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-reddit-pagecache: miss
x-ratelimit-remaining: 298
x-ratelimit-used: 2
x-ratelimit-reset: 523

{
  "kind": "t2",
  "data": {
    "name": "test123",
    "is_friend": false,
    "created": 1414750716,
    "hide_from_robots": true,
    "created_utc": 1414721916,
    "link_karma": 1,
    "comment_karma": 0,
    "is_gold": false,
    "is_mod": false,
    "has_verified_email": false,
    "id": "pc"
  }
}
3rd party sites allow indexing of user profiles. Perhaps they will
implement noindex if the user's preference is easily accessible. This is
an implementation of this request:
https://www.reddit.com/r/ideasfortheadmins/comments/2ktryi/allow_reddit_clients_to_respect_users_noindex/
For the account API, if the user prefers not to be indexed, set the HTTP
response header `X-Robots-Tag` to noindex. If the user has no preference
on indexing, then the header is never set.
@xiongchiamiov

This comment has been minimized.

Copy link
Contributor

xiongchiamiov commented Nov 3, 2014

The approach seems reasonable to me.

If we're adding another field to the response data, that should probably be included in the documentation, although I'm not really sure where that lives. Actually from glancing at it, I think we don't currently document responses? This is very unfamiliar territory for me.

👓 @kemitche

@kemitche

This comment has been minimized.

Copy link
Contributor

kemitche commented Nov 3, 2014

Responses aren't currently documented.

@@ -33,6 +33,7 @@
import time, pytz
from pylons import c, g
from pylons.i18n import _
from pylons import response

This comment has been minimized.

Copy link
@kemitche

kemitche Nov 3, 2014

Contributor

This should be merged with the pylons imports on line 34

@@ -345,6 +347,8 @@ def raw_data(self, thing):
attrs = self._data_attrs_.copy()
if c.user_is_loggedin and thing._id == c.user._id:
attrs.update(self._private_data_attrs)
if thing.pref_hide_from_robots:
response.headers['X-Robots-Tag'] = 'noindex'

This comment has been minimized.

Copy link
@kemitche

kemitche Nov 3, 2014

Contributor

The HTML version of the page will have noindex, nofollow. This should match.

@lightswitch05

This comment has been minimized.

Copy link
Contributor Author

lightswitch05 commented Nov 4, 2014

Committed requested changes from @kemitche

@xiongchiamiov

This comment has been minimized.

Copy link
Contributor

xiongchiamiov commented Nov 4, 2014

(BTW, if you use the appropriate emoji, a bot in irc will ping us.)

💇

@kemitche

This comment has been minimized.

Copy link
Contributor

kemitche commented Nov 4, 2014

🐟

@kemitche kemitche self-assigned this Nov 4, 2014
@kemitche

This comment has been minimized.

Copy link
Contributor

kemitche commented Nov 5, 2014

Merged as 7a7210b and 0d6535e

@lightswitch05 Let me know your reddit username

@kemitche kemitche closed this Nov 5, 2014
@lightswitch05

This comment has been minimized.

Copy link
Contributor Author

lightswitch05 commented Nov 5, 2014

@kemitche my reddit name is lightswitch05. Thanks for getting this merged! 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.