{"action":"created","comment":{"url":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments/40729145","id":40729145,"diff_hunk":"@@ -35,6 +36,22 @@ function dosomething_global_init() {\n       drupal_goto($new_url);\n     }\n   }\n+\n+  // Handle translation redirects for authenticated and anonymous users when\n+  // they request bare (Global English) URLs.\n+  //\n+  // Passing 'noredirect=1' will defeat the redirect.\n+  if (arg(0) == 'node' && is_numeric(arg(1)) && '' == arg(2) &&\n+      !dosomething_global_is_translation_request() &&\n+      empty($_GET['noredirect'])) {\n+\n+    if ($user->uid) {","path":"lib/modules/dosomething/dosomething_global/dosomething_global.module","position":28,"original_position":28,"commit_id":"9f795838146b86e4d968c167f3b383d5e71934d9","original_commit_id":"9f795838146b86e4d968c167f3b383d5e71934d9","user":{"login":"deadlybutter","id":897368,"avatar_url":"https://avatars.githubusercontent.com/u/897368?v=3","gravatar_id":"","url":"https://api.github.com/users/deadlybutter","html_url":"https://github.com/deadlybutter","followers_url":"https://api.github.com/users/deadlybutter/followers","following_url":"https://api.github.com/users/deadlybutter/following{/other_user}","gists_url":"https://api.github.com/users/deadlybutter/gists{/gist_id}","starred_url":"https://api.github.com/users/deadlybutter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deadlybutter/subscriptions","organizations_url":"https://api.github.com/users/deadlybutter/orgs","repos_url":"https://api.github.com/users/deadlybutter/repos","events_url":"https://api.github.com/users/deadlybutter/events{/privacy}","received_events_url":"https://api.github.com/users/deadlybutter/received_events","type":"User","site_admin":false},"body":"ooo thats useful to know","created_at":"2015-09-29T21:02:29Z","updated_at":"2015-09-29T21:02:29Z","html_url":"https://github.com/DoSomething/phoenix/pull/5313#discussion_r40729145","pull_request_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313","_links":{"self":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments/40729145"},"html":{"href":"https://github.com/DoSomething/phoenix/pull/5313#discussion_r40729145"},"pull_request":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313"}}},"pull_request":{"url":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313","id":46316429,"html_url":"https://github.com/DoSomething/phoenix/pull/5313","diff_url":"https://github.com/DoSomething/phoenix/pull/5313.diff","patch_url":"https://github.com/DoSomething/phoenix/pull/5313.patch","issue_url":"https://api.github.com/repos/DoSomething/phoenix/issues/5313","number":5313,"state":"open","locked":false,"title":"Fixes #5183: Redirect requests based on user/GeoIP info","user":{"login":"mshmsh5000","id":149811,"avatar_url":"https://avatars.githubusercontent.com/u/149811?v=3","gravatar_id":"","url":"https://api.github.com/users/mshmsh5000","html_url":"https://github.com/mshmsh5000","followers_url":"https://api.github.com/users/mshmsh5000/followers","following_url":"https://api.github.com/users/mshmsh5000/following{/other_user}","gists_url":"https://api.github.com/users/mshmsh5000/gists{/gist_id}","starred_url":"https://api.github.com/users/mshmsh5000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshmsh5000/subscriptions","organizations_url":"https://api.github.com/users/mshmsh5000/orgs","repos_url":"https://api.github.com/users/mshmsh5000/repos","events_url":"https://api.github.com/users/mshmsh5000/events{/privacy}","received_events_url":"https://api.github.com/users/mshmsh5000/received_events","type":"User","site_admin":false},"body":"#### What's this PR do?\r\n\r\nAddresses the two use cases in #5183, specifically when and how to redirect anonymous and authenticated user requests to node URLs.\r\n\r\n#### Where should the reviewer start?\r\n\r\nAll of the work is in `dosomething_global.module`. Start at this comment in `dosomething_global_init()`:\r\n\r\n```\r\n  // Handle translation redirects for authenticated and anonymous users when  \r\n  // they request bare (Global English) URLs.\r\n```\r\n\r\nThe code below calls a different function depending on whether the user is authenticated: `dosomething_global_redirect_node_auth()` or `dosomething_global_redirect_node_anon()`. The rest of the logic is in those two functions.\r\n\r\nBoth functions end with calling the helper function `dosomething_global_redirect_node_language()`, which is also part of this PR.\r\n\r\n#### How should this be manually tested?\r\n\r\n*As an anonymous user:* Use Chrome's [ModHeaders](https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en) extension, or something similar, to fake requests from different locations to node content. The header is\r\n\r\n`X-Fastly-Country-Code: US | BR | MX | etc.`\r\n\r\n1. Request a bare URL (e.g., `/campaigns/test`) from a supported country (e.g., `BR`) where the node has a translated, published version. You should get redirected.\r\n2. Request a bare URL (e.g., `/campaigns/test`) from a supported country (e.g., `BR`) where the node has a translated, unpublished version. You should not get redirected.\r\n3. Request a bare URL (e.g., `/campaigns/test`) from an unsupported country (e.g., `IN`). You should not get redirected.\r\n\r\n*As an authenticated user:* Update the user profile to test with different language settings.\r\n\r\n*N.b. If you are a privileged user, you will not get redirected.*\r\n\r\nWe base \"privileged\" on whether you can access the admin area (permission: `access administration menu`).\r\n\r\n1. Request a bare URL where the node has a published version in your language. You should get redirected.\r\n2. Request a bare URL where the node has an unpublished version in your language. You should not get redirected.\r\n\r\n#### Any background context you want to provide?\r\n\r\nThis gets hella bejesus confusing, so the goal in the code is to make the logic as simple as possible.\r\n\r\n#### What are the relevant tickets?\r\n\r\n#5183 \r\n\r\n#### Screenshots (if appropriate)\r\n\r\nN/A\r\n\r\n#### Questions:\r\n- Does the knowledge base need an update? *Probably*\r\n","created_at":"2015-09-29T18:50:03Z","updated_at":"2015-09-29T21:02:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"760016d85ec42988696772b55d937ee98f9bd2e7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313/commits","review_comments_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313/comments","review_comment_url":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DoSomething/phoenix/issues/5313/comments","statuses_url":"https://api.github.com/repos/DoSomething/phoenix/statuses/9f795838146b86e4d968c167f3b383d5e71934d9","head":{"label":"mshmsh5000:5183_url_translate_redirect","ref":"5183_url_translate_redirect","sha":"9f795838146b86e4d968c167f3b383d5e71934d9","user":{"login":"mshmsh5000","id":149811,"avatar_url":"https://avatars.githubusercontent.com/u/149811?v=3","gravatar_id":"","url":"https://api.github.com/users/mshmsh5000","html_url":"https://github.com/mshmsh5000","followers_url":"https://api.github.com/users/mshmsh5000/followers","following_url":"https://api.github.com/users/mshmsh5000/following{/other_user}","gists_url":"https://api.github.com/users/mshmsh5000/gists{/gist_id}","starred_url":"https://api.github.com/users/mshmsh5000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshmsh5000/subscriptions","organizations_url":"https://api.github.com/users/mshmsh5000/orgs","repos_url":"https://api.github.com/users/mshmsh5000/repos","events_url":"https://api.github.com/users/mshmsh5000/events{/privacy}","received_events_url":"https://api.github.com/users/mshmsh5000/received_events","type":"User","site_admin":false},"repo":{"id":24105474,"name":"dosomething-1","full_name":"mshmsh5000/dosomething-1","owner":{"login":"mshmsh5000","id":149811,"avatar_url":"https://avatars.githubusercontent.com/u/149811?v=3","gravatar_id":"","url":"https://api.github.com/users/mshmsh5000","html_url":"https://github.com/mshmsh5000","followers_url":"https://api.github.com/users/mshmsh5000/followers","following_url":"https://api.github.com/users/mshmsh5000/following{/other_user}","gists_url":"https://api.github.com/users/mshmsh5000/gists{/gist_id}","starred_url":"https://api.github.com/users/mshmsh5000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshmsh5000/subscriptions","organizations_url":"https://api.github.com/users/mshmsh5000/orgs","repos_url":"https://api.github.com/users/mshmsh5000/repos","events_url":"https://api.github.com/users/mshmsh5000/events{/privacy}","received_events_url":"https://api.github.com/users/mshmsh5000/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mshmsh5000/dosomething-1","description":"A Drupal 7 distribution that powers the DoSomething.org web platform.","fork":true,"url":"https://api.github.com/repos/mshmsh5000/dosomething-1","forks_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/forks","keys_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/teams","hooks_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/hooks","issue_events_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/issues/events{/number}","events_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/events","assignees_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/assignees{/user}","branches_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/branches{/branch}","tags_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/tags","blobs_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/statuses/{sha}","languages_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/languages","stargazers_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/stargazers","contributors_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/contributors","subscribers_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/subscribers","subscription_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/subscription","commits_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/contents/{+path}","compare_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/merges","archive_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/downloads","issues_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/issues{/number}","pulls_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/pulls{/number}","milestones_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/milestones{/number}","notifications_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/labels{/name}","releases_url":"https://api.github.com/repos/mshmsh5000/dosomething-1/releases{/id}","created_at":"2014-09-16T15:30:02Z","updated_at":"2015-01-09T20:41:09Z","pushed_at":"2015-09-29T18:32:23Z","git_url":"git://github.com/mshmsh5000/dosomething-1.git","ssh_url":"git@github.com:mshmsh5000/dosomething-1.git","clone_url":"https://github.com/mshmsh5000/dosomething-1.git","svn_url":"https://github.com/mshmsh5000/dosomething-1","homepage":"http://www.dosomething.org/","size":14556,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"DoSomething:global","ref":"global","sha":"39bd17f921e7cf7cc870db70550be717afb9e67e","user":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"repo":{"id":13592927,"name":"phoenix","full_name":"DoSomething/phoenix","owner":{"login":"DoSomething","id":731685,"avatar_url":"https://avatars.githubusercontent.com/u/731685?v=3","gravatar_id":"","url":"https://api.github.com/users/DoSomething","html_url":"https://github.com/DoSomething","followers_url":"https://api.github.com/users/DoSomething/followers","following_url":"https://api.github.com/users/DoSomething/following{/other_user}","gists_url":"https://api.github.com/users/DoSomething/gists{/gist_id}","starred_url":"https://api.github.com/users/DoSomething/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoSomething/subscriptions","organizations_url":"https://api.github.com/users/DoSomething/orgs","repos_url":"https://api.github.com/users/DoSomething/repos","events_url":"https://api.github.com/users/DoSomething/events{/privacy}","received_events_url":"https://api.github.com/users/DoSomething/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DoSomething/phoenix","description":"A Drupal 7 distribution that powers the DoSomething.org web platform.","fork":false,"url":"https://api.github.com/repos/DoSomething/phoenix","forks_url":"https://api.github.com/repos/DoSomething/phoenix/forks","keys_url":"https://api.github.com/repos/DoSomething/phoenix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DoSomething/phoenix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DoSomething/phoenix/teams","hooks_url":"https://api.github.com/repos/DoSomething/phoenix/hooks","issue_events_url":"https://api.github.com/repos/DoSomething/phoenix/issues/events{/number}","events_url":"https://api.github.com/repos/DoSomething/phoenix/events","assignees_url":"https://api.github.com/repos/DoSomething/phoenix/assignees{/user}","branches_url":"https://api.github.com/repos/DoSomething/phoenix/branches{/branch}","tags_url":"https://api.github.com/repos/DoSomething/phoenix/tags","blobs_url":"https://api.github.com/repos/DoSomething/phoenix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DoSomething/phoenix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DoSomething/phoenix/git/refs{/sha}","trees_url":"https://api.github.com/repos/DoSomething/phoenix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DoSomething/phoenix/statuses/{sha}","languages_url":"https://api.github.com/repos/DoSomething/phoenix/languages","stargazers_url":"https://api.github.com/repos/DoSomething/phoenix/stargazers","contributors_url":"https://api.github.com/repos/DoSomething/phoenix/contributors","subscribers_url":"https://api.github.com/repos/DoSomething/phoenix/subscribers","subscription_url":"https://api.github.com/repos/DoSomething/phoenix/subscription","commits_url":"https://api.github.com/repos/DoSomething/phoenix/commits{/sha}","git_commits_url":"https://api.github.com/repos/DoSomething/phoenix/git/commits{/sha}","comments_url":"https://api.github.com/repos/DoSomething/phoenix/comments{/number}","issue_comment_url":"https://api.github.com/repos/DoSomething/phoenix/issues/comments{/number}","contents_url":"https://api.github.com/repos/DoSomething/phoenix/contents/{+path}","compare_url":"https://api.github.com/repos/DoSomething/phoenix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DoSomething/phoenix/merges","archive_url":"https://api.github.com/repos/DoSomething/phoenix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DoSomething/phoenix/downloads","issues_url":"https://api.github.com/repos/DoSomething/phoenix/issues{/number}","pulls_url":"https://api.github.com/repos/DoSomething/phoenix/pulls{/number}","milestones_url":"https://api.github.com/repos/DoSomething/phoenix/milestones{/number}","notifications_url":"https://api.github.com/repos/DoSomething/phoenix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DoSomething/phoenix/labels{/name}","releases_url":"https://api.github.com/repos/DoSomething/phoenix/releases{/id}","created_at":"2013-10-15T14:50:48Z","updated_at":"2015-07-23T19:32:25Z","pushed_at":"2015-09-29T20:56:34Z","git_url":"git://github.com/DoSomething/phoenix.git","ssh_url":"git@github.com:DoSomething/phoenix.git","clone_url":"https://github.com/DoSomething/phoenix.git","svn_url":"https://github.com/DoSomething/phoenix","homepage":"http://www.dosomething.org/","size":28007,"stargazers_count":25,"watchers_count":25,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":289,"forks":18,"open_issues":289,"watchers":25,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313"},"html":{"href":"https://github.com/DoSomething/phoenix/pull/5313"},"issue":{"href":"https://api.github.com/repos/DoSomething/phoenix/issues/5313"},"comments":{"href":"https://api.github.com/repos/DoSomething/phoenix/issues/5313/comments"},"review_comments":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313/comments"},"review_comment":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DoSomething/phoenix/pulls/5313/commits"},"statuses":{"href":"https://api.github.com/repos/DoSomething/phoenix/statuses/9f795838146b86e4d968c167f3b383d5e71934d9"}}}}