{"action":"created","comment":{"url":"https://api.github.com/repos/amitaibu/og/pulls/comments/46064887","id":46064887,"diff_hunk":"@@ -0,0 +1,202 @@\n+<?php\n+\n+/**\n+ * @file\n+ * Contains \\Drupal\\og\\OgAccess.\n+ */\n+\n+namespace Drupal\\og;\n+\n+use Drupal\\Core\\Session\\AccountInterface;\n+use Drupal\\Core\\Entity\\EntityInterface;\n+use Drupal\\user\\EntityOwnerInterface;\n+\n+class OgAccess {\n+\n+  /**\n+   * Administer permission string.\n+   *\n+   * @var string\n+   */\n+  const ADMINISTER_GROUP_PERMISSION = 'administer group';\n+\n+  /**\n+   * Determines whether a user has a given privilege.\n+   *\n+   * All permission checks in OG should go through this function. This\n+   * way, we guarantee consistent behavior, and ensure that the superuser\n+   * and group administrators can perform all actions.\n+   *\n+   * @param $group_type\n+   *   The entity type of the group.\n+   * @param $group_id\n+   *   The entity ID of the group.\n+   * @param string $operation\n+   *   The entity operation being checked for.\n+   * @param $account\n+   *   (optional) The account to check. Defaults to the current user.\n+   * @param $skip_alter\n+   *   (optional) If TRUE then user access will not be sent to other modules\n+   *   using drupal_alter(). This can be used by modules implementing\n+   *   hook_og_user_access_alter() that still want to use og_user_access(), but\n+   *   without causing a recursion. Defaults to FALSE.\n+   * @param $ignore_admin\n+   *   (optional) When TRUE the specific permission is checked, ignoring the\n+   *   \"administer group\" permission if the user has it. When FALSE, a user\n+   *   with \"administer group\" will be granted all permissions.\n+   *   Defaults to FALSE.\n+   *\n+   * @return bool\n+   *   TRUE or FALSE if the current user has the requested permission.\n+   *   NULL, if the given group isn't a valid group.\n+   */\n+  public static function userAccess($group_type, $group_id, $operation, $account = NULL, $skip_alter = FALSE, $ignore_admin = FALSE) {\n+    $perm = &drupal_static(__FUNCTION__, []);\n+    // Mark the group ID and permissions that invoked an alter.\n+    $perm_alter = &drupal_static(__FUNCTION__ . '_alter', []);\n+\n+    if (!Og::isGroup($group_type, $group_id)) {\n+      // Not a group.\n+      return NULL;\n+    }\n+\n+\n+    if (empty($account)) {\n+      $account = clone \\Drupal::currentUser()->getAccount();\n+    }\n+\n+    $account_id = $account->id();\n+\n+    // User #1 has all privileges.\n+    if ($account_id == 1) {\n+      return TRUE;\n+    }\n+\n+    // Administer group permission.\n+    if (!$ignore_admin && $account->hasPermission(static::ADMINISTER_GROUP_PERMISSION)) {\n+      return TRUE;\n+    }\n+\n+    // Group manager has all privileges (if variable is TRUE).\n+    if (!empty($account_id) && \\Drupal::config('og.settings')->get('group_manager_full_access')) {\n+      $group = entity_load($group_type, $group_id);\n+\n+      if (($group instanceof EntityOwnerInterface) && ($group->getOwnerId() == $account_id)) {\n+        return TRUE;\n+      }\n+    }\n+\n+    $identifier = $group_type . ':' . $group_id;\n+\n+    // To reduce the number of SQL queries, we cache the user's permissions\n+    // in a static variable.\n+    if (!isset($perm[$identifier][$account_id])) {\n+      $perms = array();\n+\n+      if ($roles = og_get_user_roles($group_type, $group_id, $account_id)) {","path":"src/OgAccess.php","position":96,"original_position":96,"commit_id":"6a844f814bf0b9c8b17b6e333a181a4c9263a797","original_commit_id":"c47187cae22538bbfe83e0295b430613a686b1b4","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},"body":"A todo and an Issue would be great","created_at":"2015-11-27T18:12:03Z","updated_at":"2015-11-27T18:12:03Z","html_url":"https://github.com/amitaibu/og/pull/38#discussion_r46064887","pull_request_url":"https://api.github.com/repos/amitaibu/og/pulls/38","_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments/46064887"},"html":{"href":"https://github.com/amitaibu/og/pull/38#discussion_r46064887"},"pull_request":{"href":"https://api.github.com/repos/amitaibu/og/pulls/38"}}},"pull_request":{"url":"https://api.github.com/repos/amitaibu/og/pulls/38","id":51638900,"html_url":"https://github.com/amitaibu/og/pull/38","diff_url":"https://github.com/amitaibu/og/pull/38.diff","patch_url":"https://github.com/amitaibu/og/pull/38.patch","issue_url":"https://api.github.com/repos/amitaibu/og/issues/38","number":38,"state":"open","locked":false,"title":"[WIP] Start converting hook_node_access to hook_entity_access for 8.x","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":"Didn't get a chance to finish this atm, but pulled the thread that is hook_node_access > hook_entity_access :)","created_at":"2015-11-24T10:08:20Z","updated_at":"2015-11-27T18:12:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a434811b220d29303958713f85bda6e6df207f76","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amitaibu/og/pulls/38/commits","review_comments_url":"https://api.github.com/repos/amitaibu/og/pulls/38/comments","review_comment_url":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amitaibu/og/issues/38/comments","statuses_url":"https://api.github.com/repos/amitaibu/og/statuses/6a844f814bf0b9c8b17b6e333a181a4c9263a797","head":{"label":"damiankloip:entity-access","ref":"entity-access","sha":"6a844f814bf0b9c8b17b6e333a181a4c9263a797","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-11-26T16:27:22Z","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":5070,"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":"3920bbb3ffdfe2326b482772a9f16a8967a9c010","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-11-25T18:28:56Z","pushed_at":"2015-11-27T18:07:27Z","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":5281,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":11,"forks":4,"open_issues":11,"watchers":5,"default_branch":"8.x-1.x"}},"_links":{"self":{"href":"https://api.github.com/repos/amitaibu/og/pulls/38"},"html":{"href":"https://github.com/amitaibu/og/pull/38"},"issue":{"href":"https://api.github.com/repos/amitaibu/og/issues/38"},"comments":{"href":"https://api.github.com/repos/amitaibu/og/issues/38/comments"},"review_comments":{"href":"https://api.github.com/repos/amitaibu/og/pulls/38/comments"},"review_comment":{"href":"https://api.github.com/repos/amitaibu/og/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amitaibu/og/pulls/38/commits"},"statuses":{"href":"https://api.github.com/repos/amitaibu/og/statuses/6a844f814bf0b9c8b17b6e333a181a4c9263a797"}}}}