{"action":"created","comment":{"url":"https://api.github.com/repos/amitaibu/og/pulls/comments/47079487","id":47079487,"diff_hunk":"@@ -0,0 +1,163 @@\n+<?php\n+\n+/**\n+ * @file\n+ * Contains \\Drupal\\og_ui\\Controller\\SubscriptionController.\n+ */\n+\n+namespace Drupal\\og_ui\\Controller;\n+\n+use Drupal\\Core\\Controller\\ControllerBase;\n+use Drupal\\Core\\Field\\FieldStorageDefinitionInterface;\n+use Drupal\\Core\\Url;\n+use Drupal\\user\\Entity\\User;\n+use Drupal\\user\\EntityOwnerInterface;\n+use Symfony\\Component\\HttpFoundation\\RedirectResponse;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException;\n+use Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;\n+use Drupal\\og\\Og;\n+use Drupal\\og\\OgAccess;\n+\n+/**\n+ * Controller for OG subscription routes.\n+ */\n+class SubscriptionController extends ControllerBase {\n+\n+  /**\n+   * @param string $entity_type_id\n+   * @param string|int $entity_id\n+   *\n+   * @return mixed\n+   */\n+  public function subscribe(Request $request, $entity_type_id, $entity_id) {\n+    // @todo We don't need to re-validate the entity type and entity group here,\n+    // as it's already been done in the access check?\n+    $entity_storage = $this->entityTypeManager()->getStorage($entity_type_id);\n+    $entity_access = $this->entityTypeManager()->getAccessControlHandler($entity_type_id);\n+    $group = $entity_storage->load($entity_id);\n+\n+    $account = User::load($this->currentUser()->id());\n+    $field_name = $request->query->get('field_name');\n+\n+    if (empty($field_name)) {\n+      $field_name = og_get_best_group_audience_field('user', $account, $entity_type, $bundle);\n+      if (empty($field_name)) {\n+        throw new NotFoundHttpException();\n+      }\n+    }\n+\n+    // @todo Requires FieldableEntityInterface/ContentEntityInterface\n+    $field = $group->getFieldDefinition($field_name);\n+\n+    if (empty($instance) || !$entity_access->fieldAccess('view', $field, $account)) {\n+      // Field name given is incorrect, or user doesn't have access to the field.\n+      throw new NotFoundHttpException();\n+    }\n+\n+    if ($account->isAnonymous()) {\n+      // Anonymous user can't request membership.\n+      $destination = $this->getDestinationArray();\n+\n+      $user_login_url = Url::fromRoute('user.login', [], $destination);\n+\n+      // @todo I think this is correct? Other options are visitors or require\n+      // approval both of which apply to the else instead of here.\n+      if ($this->config('user.settings')->get('register') === USER_REGISTER_ADMINISTRATORS_ONLY) {\n+        drupal_set_message($this->t('In order to join any group, you must <a href=\":login\">login</a>. After you have successfully done so, you will need to request membership again.', [':login' => $user_login_url]));\n+      }\n+      else {\n+        $user_register_url = Url::fromRoute('user.register', [], $destination);\n+        drupal_set_message($this->t('In order to join any group, you must <a href=\":login\">login</a> or <a href=\":register\">register</a> a new account. After you have successfully done so, you will need to request membership again.', [':register' => $user_register_url, ':login' => $user_login_url]));\n+      }\n+\n+      return new RedirectResponse(Url::fromRoute('user.page')->setAbsolute(TRUE)->toString());\n+    }\n+\n+    $redirect = FALSE;\n+    $message = '';\n+    $params = [\n+      '@user' => $account->getDisplayName(),\n+    ];\n+\n+    // Show the group name only if user has access to it.\n+    $params['@group'] = $group->access('view', $account) ?  $group->label() : $this->t('Private group');\n+\n+    if (Og::isMember($group, $account, [OG_STATE_BLOCKED])) {\n+      // User is blocked, access denied.\n+      throw new AccessDeniedHttpException();\n+    }\n+\n+    if (Og::isMember($group, $account, [OG_STATE_PENDING])) {","path":"og_ui/src/Controller/SubscriptionController.php","position":91,"original_position":91,"commit_id":"216ede705306b374cad7bbb30bd6b8aeeee8b847","original_commit_id":"216ede705306b374cad7bbb30bd6b8aeeee8b847","user":{"login":"dawehner","id":29678,"avatar_url":"https://avatars.githubusercontent.com/u/29678?v=3","gravatar_id":"","url":"https://api.github.com/users/dawehner","html_url":"https://github.com/dawehner","followers_url":"https://api.github.com/users/dawehner/followers","following_url":"https://api.github.com/users/dawehner/following{/other_user}","gists_url":"https://api.github.com/users/dawehner/gists{/gist_id}","starred_url":"https://api.github.com/users/dawehner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dawehner/subscriptions","organizations_url":"https://api.github.com/users/dawehner/orgs","repos_url":"https://api.github.com/users/dawehner/repos","events_url":"https://api.github.com/users/dawehner/events{/privacy}","received_events_url":"https://api.github.com/users/dawehner/received_events","type":"User","site_admin":false},"body":"Any thoughts about splitting this up into methods to make it a bit easier to read?","created_at":"2015-12-09T11:31:06Z","updated_at":"2015-12-09T11:31:06Z","html_url":"https://github.com/amitaibu/og/pull/59#discussion_r47079487","pull_request_url":"https://api.github.com/repos/amitaibu/og/pulls/59","_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments/47079487"},"html":{"href":"https://github.com/amitaibu/og/pull/59#discussion_r47079487"},"pull_request":{"href":"https://api.github.com/repos/amitaibu/og/pulls/59"}}},"pull_request":{"url":"https://api.github.com/repos/amitaibu/og/pulls/59","id":52443148,"html_url":"https://github.com/amitaibu/og/pull/59","diff_url":"https://github.com/amitaibu/og/pull/59.diff","patch_url":"https://github.com/amitaibu/og/pull/59.patch","issue_url":"https://api.github.com/repos/amitaibu/og/issues/59","number":59,"state":"open","locked":false,"title":"[WIP] Subscribe/unsubscribe routes","user":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"body":"This is needed for https://github.com/amitaibu/og/pull/40. We need the subscribe and unsubscribe links.","created_at":"2015-12-02T19:36:23Z","updated_at":"2015-12-09T11:31:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2cfe4d8e32b0066b3478c9748709e3873d405a51","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amitaibu/og/pulls/59/commits","review_comments_url":"https://api.github.com/repos/amitaibu/og/pulls/59/comments","review_comment_url":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amitaibu/og/issues/59/comments","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/216ede705306b374cad7bbb30bd6b8aeeee8b847","head":{"label":"damiankloip:og-ui-subscribe-routes","ref":"og-ui-subscribe-routes","sha":"216ede705306b374cad7bbb30bd6b8aeeee8b847","user":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"repo":{"id":40903339,"name":"og","full_name":"damiankloip/og","owner":{"login":"damiankloip","id":1053891,"avatar_url":"https://avatars.githubusercontent.com/u/1053891?v=3","gravatar_id":"","url":"https://api.github.com/users/damiankloip","html_url":"https://github.com/damiankloip","followers_url":"https://api.github.com/users/damiankloip/followers","following_url":"https://api.github.com/users/damiankloip/following{/other_user}","gists_url":"https://api.github.com/users/damiankloip/gists{/gist_id}","starred_url":"https://api.github.com/users/damiankloip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiankloip/subscriptions","organizations_url":"https://api.github.com/users/damiankloip/orgs","repos_url":"https://api.github.com/users/damiankloip/repos","events_url":"https://api.github.com/users/damiankloip/events{/privacy}","received_events_url":"https://api.github.com/users/damiankloip/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/damiankloip/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/damiankloip/og","forks_url":"https://api.github.com/repos/damiankloip/og/forks","keys_url":"https://api.github.com/repos/damiankloip/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/damiankloip/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/damiankloip/og/teams","hooks_url":"https://api.github.com/repos/damiankloip/og/hooks","issue_events_url":"https://api.github.com/repos/damiankloip/og/issues/events{/number}","events_url":"https://api.github.com/repos/damiankloip/og/events","assignees_url":"https://api.github.com/repos/damiankloip/og/assignees{/user}","branches_url":"https://api.github.com/repos/damiankloip/og/branches{/branch}","tags_url":"https://api.github.com/repos/damiankloip/og/tags","blobs_url":"https://api.github.com/repos/damiankloip/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/damiankloip/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/damiankloip/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/damiankloip/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/damiankloip/og/statuses/{sha}","languages_url":"https://api.github.com/repos/damiankloip/og/languages","stargazers_url":"https://api.github.com/repos/damiankloip/og/stargazers","contributors_url":"https://api.github.com/repos/damiankloip/og/contributors","subscribers_url":"https://api.github.com/repos/damiankloip/og/subscribers","subscription_url":"https://api.github.com/repos/damiankloip/og/subscription","commits_url":"https://api.github.com/repos/damiankloip/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/damiankloip/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/damiankloip/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/damiankloip/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/damiankloip/og/contents/{+path}","compare_url":"https://api.github.com/repos/damiankloip/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/damiankloip/og/merges","archive_url":"https://api.github.com/repos/damiankloip/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/damiankloip/og/downloads","issues_url":"https://api.github.com/repos/damiankloip/og/issues{/number}","pulls_url":"https://api.github.com/repos/damiankloip/og/pulls{/number}","milestones_url":"https://api.github.com/repos/damiankloip/og/milestones{/number}","notifications_url":"https://api.github.com/repos/damiankloip/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/damiankloip/og/labels{/name}","releases_url":"https://api.github.com/repos/damiankloip/og/releases{/id}","created_at":"2015-08-17T14:54:27Z","updated_at":"2015-08-17T14:54:28Z","pushed_at":"2015-12-08T16:52:34Z","git_url":"git://github.com/damiankloip/og.git","ssh_url":"git@github.com:damiankloip/og.git","clone_url":"https://github.com/damiankloip/og.git","svn_url":"https://github.com/damiankloip/og","homepage":"","size":5250,"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":"7.x-2.x"}},"base":{"label":"amitaibu:8.x-1.x","ref":"8.x-1.x","sha":"91ac0e172c5b680c5c4f96fac1eef6a31c0fcbdd","user":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"repo":{"id":42034806,"name":"og","full_name":"amitaibu/og","owner":{"login":"amitaibu","id":125707,"avatar_url":"https://avatars.githubusercontent.com/u/125707?v=3","gravatar_id":"","url":"https://api.github.com/users/amitaibu","html_url":"https://github.com/amitaibu","followers_url":"https://api.github.com/users/amitaibu/followers","following_url":"https://api.github.com/users/amitaibu/following{/other_user}","gists_url":"https://api.github.com/users/amitaibu/gists{/gist_id}","starred_url":"https://api.github.com/users/amitaibu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amitaibu/subscriptions","organizations_url":"https://api.github.com/users/amitaibu/orgs","repos_url":"https://api.github.com/users/amitaibu/repos","events_url":"https://api.github.com/users/amitaibu/events{/privacy}","received_events_url":"https://api.github.com/users/amitaibu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amitaibu/og","description":"https://www.drupal.org/project/og","fork":true,"url":"https://api.github.com/repos/amitaibu/og","forks_url":"https://api.github.com/repos/amitaibu/og/forks","keys_url":"https://api.github.com/repos/amitaibu/og/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amitaibu/og/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amitaibu/og/teams","hooks_url":"https://api.github.com/repos/amitaibu/og/hooks","issue_events_url":"https://api.github.com/repos/amitaibu/og/issues/events{/number}","events_url":"https://api.github.com/repos/amitaibu/og/events","assignees_url":"https://api.github.com/repos/amitaibu/og/assignees{/user}","branches_url":"https://api.github.com/repos/amitaibu/og/branches{/branch}","tags_url":"https://api.github.com/repos/amitaibu/og/tags","blobs_url":"https://api.github.com/repos/amitaibu/og/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amitaibu/og/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amitaibu/og/git/refs{/sha}","trees_url":"https://api.github.com/repos/amitaibu/og/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/{sha}","languages_url":"https://api.github.com/repos/amitaibu/og/languages","stargazers_url":"https://api.github.com/repos/amitaibu/og/stargazers","contributors_url":"https://api.github.com/repos/amitaibu/og/contributors","subscribers_url":"https://api.github.com/repos/amitaibu/og/subscribers","subscription_url":"https://api.github.com/repos/amitaibu/og/subscription","commits_url":"https://api.github.com/repos/amitaibu/og/commits{/sha}","git_commits_url":"https://api.github.com/repos/amitaibu/og/git/commits{/sha}","comments_url":"https://api.github.com/repos/amitaibu/og/comments{/number}","issue_comment_url":"https://api.github.com/repos/amitaibu/og/issues/comments{/number}","contents_url":"https://api.github.com/repos/amitaibu/og/contents/{+path}","compare_url":"https://api.github.com/repos/amitaibu/og/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amitaibu/og/merges","archive_url":"https://api.github.com/repos/amitaibu/og/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amitaibu/og/downloads","issues_url":"https://api.github.com/repos/amitaibu/og/issues{/number}","pulls_url":"https://api.github.com/repos/amitaibu/og/pulls{/number}","milestones_url":"https://api.github.com/repos/amitaibu/og/milestones{/number}","notifications_url":"https://api.github.com/repos/amitaibu/og/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amitaibu/og/labels{/name}","releases_url":"https://api.github.com/repos/amitaibu/og/releases{/id}","created_at":"2015-09-07T06:16:12Z","updated_at":"2015-12-08T07:42:32Z","pushed_at":"2015-12-09T11:25:00Z","git_url":"git://github.com/amitaibu/og.git","ssh_url":"git@github.com:amitaibu/og.git","clone_url":"https://github.com/amitaibu/og.git","svn_url":"https://github.com/amitaibu/og","homepage":"","size":5507,"stargazers_count":9,"watchers_count":9,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":30,"forks":7,"open_issues":30,"watchers":9,"default_branch":"8.x-1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/59"},"html":{"href":"https://github.com/amitaibu/og/pull/59"},"issue":{"href":"https://api.github.com/repos/amitaibu/og/issues/59"},"comments":{"href":"https://api.github.com/repos/amitaibu/og/issues/59/comments"},"review_comments":{"href":"https://api.github.com/repos/amitaibu/og/pulls/59/comments"},"review_comment":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amitaibu/og/pulls/59/commits"},"statuses":{"href":"https://api.github.com/repos/amitaibu/og/statuses/216ede705306b374cad7bbb30bd6b8aeeee8b847"}}}}