{"action":"created","comment":{"url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/comments/87029981","pull_request_review_id":7658719,"id":87029981,"diff_hunk":"@@ -156,3 +173,118 @@ function c4m_search_filter_search_api_query_alter(SearchApiQueryInterface $query\n       break;\n   }\n }\n+\n+/**\n+ * Add filter to query, to present only the groups logged-in user can access.\n+ *\n+ * Since og_access module grants access to any node that got its\n+ * OG_ACCESS_FIELD set to 1, which is not per project access requirements,\n+ * we need to cancel this effect.\n+ * To do so, this filter is generated and added to query, with all grants,\n+ * besides the ones that are generated by og_access module.\n+ *\n+ * @param object $query\n+ *   The query that is used to select groups that will be presented.\n+ *   Passed by reference, as query is altered.\n+ */\n+function _c4m_search_filter_apply_view_access_filter(&$query) {\n+  // Filter by node access grants.\n+  $filter = $query->createFilter('OR');\n+  // Generate all grants for current user, besides the ones being generated\n+  // by og_access model.\n+  $grants = _c4m_search_filter_view_access_filter_grants();\n+  // Create query conditions, in similar way _search_api_query_add_node_access()\n+  // generates it's query conditions.\n+  foreach ($grants as $realm => $gids) {\n+    foreach ($gids as $gid) {\n+      $filter->condition('search_api_access_node', \"node_access_$realm:$gid\");\n+    }\n+  }\n+  $filter->condition('search_api_access_node', 'node_access__all');\n+  // Add filter.\n+  $query->filter($filter);\n+}\n+\n+/**\n+ * Returns a list of grants, besides the ones generated by og_access module.\n+ *\n+ * Operational is similar to node_access_grants() activated by\n+ * _search_api_query_add_node_access(), besides activation of 'node_grants'\n+ * implementation by og_access module.\n+ *\n+ * @param string $op\n+ *   Operation for which grants are generated. Defaults to 'view'.\n+ *\n+ * @returns array\n+ *   List of grants for logged in user.\n+ */\n+function _c4m_search_filter_view_access_filter_grants($op = 'view') {\n+  if (!isset($account)) {\n+    $account = $GLOBALS['user'];\n+  }\n+\n+  $args = array($account, $op);\n+  // Find all modules that implement hook_node_grants().\n+  $implementing_modules = module_implements('node_grants');\n+  // Remove og_access module from the list of implementing modules.\n+  if (($key = array_search('og_access', $implementing_modules)) !== FALSE) {\n+    unset($implementing_modules[$key]);\n+  }\n+\n+  // Activate the hook functions of all modules from the list.\n+  $grants = array();\n+  foreach ($implementing_modules as $module) {\n+    $function = $module . '_node_grants';\n+    if (function_exists($function)) {\n+      $result = call_user_func_array($function, $args);\n+      if (isset($result) && is_array($result)) {\n+        $grants = array_merge_recursive($grants, $result);\n+      }\n+      elseif (isset($result)) {\n+        $grants[] = $result;\n+      }\n+    }\n+  }\n+\n+  // Allow modules to alter the assigned grants.\n+  drupal_alter('node_grants', $grants, $account, $op);\n+\n+  return array_merge(array('all' => array(0)), $grants);\n+}\n+\n+/**\n+ * Returns the list of groups logged-in user belongs to, and can view.\n+ *\n+ * @param string $bundle\n+ *   Group bundle. By default, set to NULL.\n+ *\n+ * @returns array\n+ *   List of groups logged-in user belongs to, and can view.\n+ */\n+function _c4m_search_filter_get_member_accessible_groups($bundle = NULL) {\n+  $groups = c4m_user_og_get_groups(NULL, $bundle, NODE_PUBLISHED, FALSE);\n+\n+  // Removes groups where the logged in user has no access.\n+  $groups = array_filter($groups, 'c4m_search_filter_node_access_view_filter');\n+\n+  $filtered_groups = array();\n+\n+  foreach ($groups as $group) {\n+    $filtered_groups[$group->nid] = $group->nid;\n+  }\n+\n+  return $filtered_groups;\n+}\n+\n+/**\n+ * Callback for array_filter that checks if the user has access to the node.\n+ *\n+ * @param object $node\n+ *   Node object.\n+ *\n+ * @returns boolean\n+ *   Indicates if the user has access or not.\n+ */\n+function c4m_search_filter_node_access_view_filter($node) {","path":"project/profiles/capacity4more/modules/c4m/search/c4m_search_filter/c4m_search_filter.module","position":211,"original_position":211,"commit_id":"ca12d42c1e9dc8bcebed5357563b69c493fddf4c","original_commit_id":"ca12d42c1e9dc8bcebed5357563b69c493fddf4c","user":{"login":"ordavidil","id":5985683,"avatar_url":"https://avatars.githubusercontent.com/u/5985683?v=3","gravatar_id":"","url":"https://api.github.com/users/ordavidil","html_url":"https://github.com/ordavidil","followers_url":"https://api.github.com/users/ordavidil/followers","following_url":"https://api.github.com/users/ordavidil/following{/other_user}","gists_url":"https://api.github.com/users/ordavidil/gists{/gist_id}","starred_url":"https://api.github.com/users/ordavidil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ordavidil/subscriptions","organizations_url":"https://api.github.com/users/ordavidil/orgs","repos_url":"https://api.github.com/users/ordavidil/repos","events_url":"https://api.github.com/users/ordavidil/events{/privacy}","received_events_url":"https://api.github.com/users/ordavidil/received_events","type":"User","site_admin":false},"body":"seems duplicated of `c4m_user_profile_node_access_view_filter()`","created_at":"2016-11-08T16:40:51Z","updated_at":"2016-11-08T16:40:51Z","html_url":"https://github.com/capacity4dev/capacity4more/pull/1445#discussion_r87029981","pull_request_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445","_links":{"self":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/comments/87029981"},"html":{"href":"https://github.com/capacity4dev/capacity4more/pull/1445#discussion_r87029981"},"pull_request":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445"}}},"pull_request":{"url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445","id":90978180,"html_url":"https://github.com/capacity4dev/capacity4more/pull/1445","diff_url":"https://github.com/capacity4dev/capacity4more/pull/1445.diff","patch_url":"https://github.com/capacity4dev/capacity4more/pull/1445.patch","issue_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/1445","number":1445,"state":"open","locked":false,"title":"[CFM-861] Adjust permissions and align groups presentation.","user":{"login":"anvmn","id":17882245,"avatar_url":"https://avatars.githubusercontent.com/u/17882245?v=3","gravatar_id":"","url":"https://api.github.com/users/anvmn","html_url":"https://github.com/anvmn","followers_url":"https://api.github.com/users/anvmn/followers","following_url":"https://api.github.com/users/anvmn/following{/other_user}","gists_url":"https://api.github.com/users/anvmn/gists{/gist_id}","starred_url":"https://api.github.com/users/anvmn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anvmn/subscriptions","organizations_url":"https://api.github.com/users/anvmn/orgs","repos_url":"https://api.github.com/users/anvmn/repos","events_url":"https://api.github.com/users/anvmn/events{/privacy}","received_events_url":"https://api.github.com/users/anvmn/received_events","type":"User","site_admin":false},"body":"## Merge #1479 first\r\nhttps://issuetracker.amplexor.com/jira/browse/CFM-861\r\n","created_at":"2016-10-26T10:37:59Z","updated_at":"2016-11-08T16:40:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ed4dec96bece4a941fc3b088ed3703ed7e7909ad","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445/commits","review_comments_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445/comments","review_comment_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/comments{/number}","comments_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/1445/comments","statuses_url":"https://api.github.com/repos/capacity4dev/capacity4more/statuses/ca12d42c1e9dc8bcebed5357563b69c493fddf4c","head":{"label":"capacity4dev:feature/CFM-861-adjust-permissions","ref":"feature/CFM-861-adjust-permissions","sha":"ca12d42c1e9dc8bcebed5357563b69c493fddf4c","user":{"login":"capacity4dev","id":6919578,"avatar_url":"https://avatars.githubusercontent.com/u/6919578?v=3","gravatar_id":"","url":"https://api.github.com/users/capacity4dev","html_url":"https://github.com/capacity4dev","followers_url":"https://api.github.com/users/capacity4dev/followers","following_url":"https://api.github.com/users/capacity4dev/following{/other_user}","gists_url":"https://api.github.com/users/capacity4dev/gists{/gist_id}","starred_url":"https://api.github.com/users/capacity4dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/capacity4dev/subscriptions","organizations_url":"https://api.github.com/users/capacity4dev/orgs","repos_url":"https://api.github.com/users/capacity4dev/repos","events_url":"https://api.github.com/users/capacity4dev/events{/privacy}","received_events_url":"https://api.github.com/users/capacity4dev/received_events","type":"Organization","site_admin":false},"repo":{"id":18283391,"name":"capacity4more","full_name":"capacity4dev/capacity4more","owner":{"login":"capacity4dev","id":6919578,"avatar_url":"https://avatars.githubusercontent.com/u/6919578?v=3","gravatar_id":"","url":"https://api.github.com/users/capacity4dev","html_url":"https://github.com/capacity4dev","followers_url":"https://api.github.com/users/capacity4dev/followers","following_url":"https://api.github.com/users/capacity4dev/following{/other_user}","gists_url":"https://api.github.com/users/capacity4dev/gists{/gist_id}","starred_url":"https://api.github.com/users/capacity4dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/capacity4dev/subscriptions","organizations_url":"https://api.github.com/users/capacity4dev/orgs","repos_url":"https://api.github.com/users/capacity4dev/repos","events_url":"https://api.github.com/users/capacity4dev/events{/privacy}","received_events_url":"https://api.github.com/users/capacity4dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/capacity4dev/capacity4more","description":"A Drupal 7 powered distribution providing a community platform to share knowledge.","fork":false,"url":"https://api.github.com/repos/capacity4dev/capacity4more","forks_url":"https://api.github.com/repos/capacity4dev/capacity4more/forks","keys_url":"https://api.github.com/repos/capacity4dev/capacity4more/keys{/key_id}","collaborators_url":"https://api.github.com/repos/capacity4dev/capacity4more/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/capacity4dev/capacity4more/teams","hooks_url":"https://api.github.com/repos/capacity4dev/capacity4more/hooks","issue_events_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/events{/number}","events_url":"https://api.github.com/repos/capacity4dev/capacity4more/events","assignees_url":"https://api.github.com/repos/capacity4dev/capacity4more/assignees{/user}","branches_url":"https://api.github.com/repos/capacity4dev/capacity4more/branches{/branch}","tags_url":"https://api.github.com/repos/capacity4dev/capacity4more/tags","blobs_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/refs{/sha}","trees_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/trees{/sha}","statuses_url":"https://api.github.com/repos/capacity4dev/capacity4more/statuses/{sha}","languages_url":"https://api.github.com/repos/capacity4dev/capacity4more/languages","stargazers_url":"https://api.github.com/repos/capacity4dev/capacity4more/stargazers","contributors_url":"https://api.github.com/repos/capacity4dev/capacity4more/contributors","subscribers_url":"https://api.github.com/repos/capacity4dev/capacity4more/subscribers","subscription_url":"https://api.github.com/repos/capacity4dev/capacity4more/subscription","commits_url":"https://api.github.com/repos/capacity4dev/capacity4more/commits{/sha}","git_commits_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/commits{/sha}","comments_url":"https://api.github.com/repos/capacity4dev/capacity4more/comments{/number}","issue_comment_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/comments{/number}","contents_url":"https://api.github.com/repos/capacity4dev/capacity4more/contents/{+path}","compare_url":"https://api.github.com/repos/capacity4dev/capacity4more/compare/{base}...{head}","merges_url":"https://api.github.com/repos/capacity4dev/capacity4more/merges","archive_url":"https://api.github.com/repos/capacity4dev/capacity4more/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/capacity4dev/capacity4more/downloads","issues_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues{/number}","pulls_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls{/number}","milestones_url":"https://api.github.com/repos/capacity4dev/capacity4more/milestones{/number}","notifications_url":"https://api.github.com/repos/capacity4dev/capacity4more/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/capacity4dev/capacity4more/labels{/name}","releases_url":"https://api.github.com/repos/capacity4dev/capacity4more/releases{/id}","deployments_url":"https://api.github.com/repos/capacity4dev/capacity4more/deployments","created_at":"2014-03-31T06:03:43Z","updated_at":"2016-10-24T08:23:55Z","pushed_at":"2016-11-08T16:20:10Z","git_url":"git://github.com/capacity4dev/capacity4more.git","ssh_url":"git@github.com:capacity4dev/capacity4more.git","clone_url":"https://github.com/capacity4dev/capacity4more.git","svn_url":"https://github.com/capacity4dev/capacity4more","homepage":null,"size":102979,"stargazers_count":9,"watchers_count":9,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":24,"forks":5,"open_issues":24,"watchers":9,"default_branch":"develop"}},"base":{"label":"capacity4dev:develop","ref":"develop","sha":"2a841f09cf10d756bf12401b88ef79be2d50572b","user":{"login":"capacity4dev","id":6919578,"avatar_url":"https://avatars.githubusercontent.com/u/6919578?v=3","gravatar_id":"","url":"https://api.github.com/users/capacity4dev","html_url":"https://github.com/capacity4dev","followers_url":"https://api.github.com/users/capacity4dev/followers","following_url":"https://api.github.com/users/capacity4dev/following{/other_user}","gists_url":"https://api.github.com/users/capacity4dev/gists{/gist_id}","starred_url":"https://api.github.com/users/capacity4dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/capacity4dev/subscriptions","organizations_url":"https://api.github.com/users/capacity4dev/orgs","repos_url":"https://api.github.com/users/capacity4dev/repos","events_url":"https://api.github.com/users/capacity4dev/events{/privacy}","received_events_url":"https://api.github.com/users/capacity4dev/received_events","type":"Organization","site_admin":false},"repo":{"id":18283391,"name":"capacity4more","full_name":"capacity4dev/capacity4more","owner":{"login":"capacity4dev","id":6919578,"avatar_url":"https://avatars.githubusercontent.com/u/6919578?v=3","gravatar_id":"","url":"https://api.github.com/users/capacity4dev","html_url":"https://github.com/capacity4dev","followers_url":"https://api.github.com/users/capacity4dev/followers","following_url":"https://api.github.com/users/capacity4dev/following{/other_user}","gists_url":"https://api.github.com/users/capacity4dev/gists{/gist_id}","starred_url":"https://api.github.com/users/capacity4dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/capacity4dev/subscriptions","organizations_url":"https://api.github.com/users/capacity4dev/orgs","repos_url":"https://api.github.com/users/capacity4dev/repos","events_url":"https://api.github.com/users/capacity4dev/events{/privacy}","received_events_url":"https://api.github.com/users/capacity4dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/capacity4dev/capacity4more","description":"A Drupal 7 powered distribution providing a community platform to share knowledge.","fork":false,"url":"https://api.github.com/repos/capacity4dev/capacity4more","forks_url":"https://api.github.com/repos/capacity4dev/capacity4more/forks","keys_url":"https://api.github.com/repos/capacity4dev/capacity4more/keys{/key_id}","collaborators_url":"https://api.github.com/repos/capacity4dev/capacity4more/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/capacity4dev/capacity4more/teams","hooks_url":"https://api.github.com/repos/capacity4dev/capacity4more/hooks","issue_events_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/events{/number}","events_url":"https://api.github.com/repos/capacity4dev/capacity4more/events","assignees_url":"https://api.github.com/repos/capacity4dev/capacity4more/assignees{/user}","branches_url":"https://api.github.com/repos/capacity4dev/capacity4more/branches{/branch}","tags_url":"https://api.github.com/repos/capacity4dev/capacity4more/tags","blobs_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/refs{/sha}","trees_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/trees{/sha}","statuses_url":"https://api.github.com/repos/capacity4dev/capacity4more/statuses/{sha}","languages_url":"https://api.github.com/repos/capacity4dev/capacity4more/languages","stargazers_url":"https://api.github.com/repos/capacity4dev/capacity4more/stargazers","contributors_url":"https://api.github.com/repos/capacity4dev/capacity4more/contributors","subscribers_url":"https://api.github.com/repos/capacity4dev/capacity4more/subscribers","subscription_url":"https://api.github.com/repos/capacity4dev/capacity4more/subscription","commits_url":"https://api.github.com/repos/capacity4dev/capacity4more/commits{/sha}","git_commits_url":"https://api.github.com/repos/capacity4dev/capacity4more/git/commits{/sha}","comments_url":"https://api.github.com/repos/capacity4dev/capacity4more/comments{/number}","issue_comment_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues/comments{/number}","contents_url":"https://api.github.com/repos/capacity4dev/capacity4more/contents/{+path}","compare_url":"https://api.github.com/repos/capacity4dev/capacity4more/compare/{base}...{head}","merges_url":"https://api.github.com/repos/capacity4dev/capacity4more/merges","archive_url":"https://api.github.com/repos/capacity4dev/capacity4more/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/capacity4dev/capacity4more/downloads","issues_url":"https://api.github.com/repos/capacity4dev/capacity4more/issues{/number}","pulls_url":"https://api.github.com/repos/capacity4dev/capacity4more/pulls{/number}","milestones_url":"https://api.github.com/repos/capacity4dev/capacity4more/milestones{/number}","notifications_url":"https://api.github.com/repos/capacity4dev/capacity4more/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/capacity4dev/capacity4more/labels{/name}","releases_url":"https://api.github.com/repos/capacity4dev/capacity4more/releases{/id}","deployments_url":"https://api.github.com/repos/capacity4dev/capacity4more/deployments","created_at":"2014-03-31T06:03:43Z","updated_at":"2016-10-24T08:23:55Z","pushed_at":"2016-11-08T16:20:10Z","git_url":"git://github.com/capacity4dev/capacity4more.git","ssh_url":"git@github.com:capacity4dev/capacity4more.git","clone_url":"https://github.com/capacity4dev/capacity4more.git","svn_url":"https://github.com/capacity4dev/capacity4more","homepage":null,"size":102979,"stargazers_count":9,"watchers_count":9,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":24,"forks":5,"open_issues":24,"watchers":9,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445"},"html":{"href":"https://github.com/capacity4dev/capacity4more/pull/1445"},"issue":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/issues/1445"},"comments":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/issues/1445/comments"},"review_comments":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445/comments"},"review_comment":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/pulls/1445/commits"},"statuses":{"href":"https://api.github.com/repos/capacity4dev/capacity4more/statuses/ca12d42c1e9dc8bcebed5357563b69c493fddf4c"}}}}
{"actor":{"display_login":"ordavidil"}}