{"action":"created","comment":{"url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/comments/50571728","id":50571728,"diff_hunk":"@@ -0,0 +1,116 @@\n+import pprint\n+import sqlalchemy\n+\n+import ckan.new_authz as new_authz\n+import ckan.model as model\n+import ckan.logic.auth as auth\n+import ckan.lib.dictization.model_dictize as model_dictize\n+\n+import ckan.plugins as p\n+\n+import ckan.logic.auth.create as create_auth\n+\n+from ckan.common import _\n+\n+\n+import ckan.plugins.toolkit as toolkit\n+\n+\n+_check_access = toolkit.check_access\n+_or_ = sqlalchemy.or_\n+\n+\n+def group_list_authz(context, data_dict):\n+    '''Return the list of groups that the user is authorized to edit.\n+\n+    :param available_only: remove the existing groups in the package\n+      (optional, default: ``False``)\n+    :type available_only: boolean\n+\n+    :param am_member: if True return only the groups the logged-in user is a\n+      member of, otherwise return all groups that the user is authorized to\n+      edit (for example, sysadmin users are authorized to edit all grouimport ckan.lib.dictization.model_dictize as model_dictizeps)\n+      (optional, default: False)\n+    :type am-member: boolean\n+\n+    :returns: list of dictized groups that the user is authorized to edit\n+    :rtype: list of dicts\n+\n+    '''\n+    model = context['model']\n+    user = context['user']\n+    available_only = data_dict.get('available_only', False)\n+    am_member = data_dict.get('am_member', False)\n+    \n+    \n+    _check_access('group_list_authz',context, data_dict)\n+    \n+    sysadmin = new_authz.is_sysadmin(user)\n+    \n+    roles = new_authz.get_roles_with_permission('manage_group')\n+    if not roles:\n+        return []\n+    user_id = new_authz.get_user_id_for_username(user, allow_none=True)\n+    if not user_id:\n+        return []\n+    \n+    if not sysadmin or am_member:\n+        q = model.Session.query(model.Member) \\\n+            .filter(model.Member.table_name == 'user') \\\n+            .filter(model.Member.capacity.in_(roles)) \\\n+            .filter(model.Member.table_id == user_id)\n+        group_ids = []\n+        for row in q.all():\n+            group_ids.append(row.group_id)\n+\n+        if not group_ids:\n+            return []\n+    \n+    q = model.Session.query(model.Group) \\\n+        .filter(model.Group.is_organization == False) \\\n+        .filter(model.Group.state == 'active')\n+    \n+    if not sysadmin or am_member:\n+        q = q.filter(_or_(model.Group.id.in_(group_ids), model.Group.is_organization == False))\n+\n+    groups = q.all()\n+\n+    if available_only:\n+        package = context.get('package')\n+        if package:\n+            groups = set(groups) - set(package.get_groups())\n+\n+    group_list = model_dictize.group_list_dictize(groups, context)\n+    return group_list\n+\n+\n+def member_create(context, data_dict):","path":"ckanext/publicamundi/lib/actions/thematic_groups.py","position":87,"original_position":87,"commit_id":"f0da8a13f8f789e2964a025593cffdb0db01f940","original_commit_id":"f0da8a13f8f789e2964a025593cffdb0db01f940","user":{"login":"drmalex07","id":603737,"avatar_url":"https://avatars.githubusercontent.com/u/603737?v=3","gravatar_id":"","url":"https://api.github.com/users/drmalex07","html_url":"https://github.com/drmalex07","followers_url":"https://api.github.com/users/drmalex07/followers","following_url":"https://api.github.com/users/drmalex07/following{/other_user}","gists_url":"https://api.github.com/users/drmalex07/gists{/gist_id}","starred_url":"https://api.github.com/users/drmalex07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drmalex07/subscriptions","organizations_url":"https://api.github.com/users/drmalex07/orgs","repos_url":"https://api.github.com/users/drmalex07/repos","events_url":"https://api.github.com/users/drmalex07/events{/privacy}","received_events_url":"https://api.github.com/users/drmalex07/received_events","type":"User","site_admin":false},"body":"Rename to `member_create_check_authorized` to clarify that this is an authorization hook (and not an ovewrite of `member_create` action)","created_at":"2016-01-22T18:25:22Z","updated_at":"2016-01-22T18:25:22Z","html_url":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227#discussion_r50571728","pull_request_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227","_links":{"self":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/comments/50571728"},"html":{"href":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227#discussion_r50571728"},"pull_request":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227"}}},"pull_request":{"url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227","id":56773012,"html_url":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227","diff_url":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227.diff","patch_url":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227.patch","issue_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/227","number":227,"state":"open","locked":false,"title":"Enabling editors and admins, assign packages of their organizations t…","user":{"login":"stratiot","id":6067514,"avatar_url":"https://avatars.githubusercontent.com/u/6067514?v=3","gravatar_id":"","url":"https://api.github.com/users/stratiot","html_url":"https://github.com/stratiot","followers_url":"https://api.github.com/users/stratiot/followers","following_url":"https://api.github.com/users/stratiot/following{/other_user}","gists_url":"https://api.github.com/users/stratiot/gists{/gist_id}","starred_url":"https://api.github.com/users/stratiot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stratiot/subscriptions","organizations_url":"https://api.github.com/users/stratiot/orgs","repos_url":"https://api.github.com/users/stratiot/repos","events_url":"https://api.github.com/users/stratiot/events{/privacy}","received_events_url":"https://api.github.com/users/stratiot/received_events","type":"User","site_admin":false},"body":"…o thematic groups","created_at":"2016-01-21T16:26:36Z","updated_at":"2016-01-22T18:25:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"63fe1ca1bbaf47a1c25b73d6daeebbb73eefb1ff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227/commits","review_comments_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227/comments","review_comment_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/227/comments","statuses_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/statuses/f0da8a13f8f789e2964a025593cffdb0db01f940","head":{"label":"stratiot:master","ref":"master","sha":"f0da8a13f8f789e2964a025593cffdb0db01f940","user":{"login":"stratiot","id":6067514,"avatar_url":"https://avatars.githubusercontent.com/u/6067514?v=3","gravatar_id":"","url":"https://api.github.com/users/stratiot","html_url":"https://github.com/stratiot","followers_url":"https://api.github.com/users/stratiot/followers","following_url":"https://api.github.com/users/stratiot/following{/other_user}","gists_url":"https://api.github.com/users/stratiot/gists{/gist_id}","starred_url":"https://api.github.com/users/stratiot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stratiot/subscriptions","organizations_url":"https://api.github.com/users/stratiot/orgs","repos_url":"https://api.github.com/users/stratiot/repos","events_url":"https://api.github.com/users/stratiot/events{/privacy}","received_events_url":"https://api.github.com/users/stratiot/received_events","type":"User","site_admin":false},"repo":{"id":27234902,"name":"ckanext-publicamundi","full_name":"stratiot/ckanext-publicamundi","owner":{"login":"stratiot","id":6067514,"avatar_url":"https://avatars.githubusercontent.com/u/6067514?v=3","gravatar_id":"","url":"https://api.github.com/users/stratiot","html_url":"https://github.com/stratiot","followers_url":"https://api.github.com/users/stratiot/followers","following_url":"https://api.github.com/users/stratiot/following{/other_user}","gists_url":"https://api.github.com/users/stratiot/gists{/gist_id}","starred_url":"https://api.github.com/users/stratiot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stratiot/subscriptions","organizations_url":"https://api.github.com/users/stratiot/orgs","repos_url":"https://api.github.com/users/stratiot/repos","events_url":"https://api.github.com/users/stratiot/events{/privacy}","received_events_url":"https://api.github.com/users/stratiot/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stratiot/ckanext-publicamundi","description":"PublicaMundi main CKAN extension. http://www.publicamundi.eu","fork":true,"url":"https://api.github.com/repos/stratiot/ckanext-publicamundi","forks_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/forks","keys_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/teams","hooks_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/hooks","issue_events_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/issues/events{/number}","events_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/events","assignees_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/assignees{/user}","branches_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/branches{/branch}","tags_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/tags","blobs_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/git/refs{/sha}","trees_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/statuses/{sha}","languages_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/languages","stargazers_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/stargazers","contributors_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/contributors","subscribers_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/subscribers","subscription_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/subscription","commits_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/commits{/sha}","git_commits_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/git/commits{/sha}","comments_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/comments{/number}","issue_comment_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/issues/comments{/number}","contents_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/contents/{+path}","compare_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/merges","archive_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/downloads","issues_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/issues{/number}","pulls_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/pulls{/number}","milestones_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/milestones{/number}","notifications_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/labels{/name}","releases_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/releases{/id}","deployments_url":"https://api.github.com/repos/stratiot/ckanext-publicamundi/deployments","created_at":"2014-11-27T17:13:49Z","updated_at":"2016-01-15T16:33:08Z","pushed_at":"2016-01-21T14:50:37Z","git_url":"git://github.com/stratiot/ckanext-publicamundi.git","ssh_url":"git@github.com:stratiot/ckanext-publicamundi.git","clone_url":"https://github.com/stratiot/ckanext-publicamundi.git","svn_url":"https://github.com/stratiot/ckanext-publicamundi","homepage":"http://publicamundi.eu","size":18931,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"master"}},"base":{"label":"PublicaMundi:master","ref":"master","sha":"16b76b3128df023a7d3ff696084c769d1bf0f1a9","user":{"login":"PublicaMundi","id":5468095,"avatar_url":"https://avatars.githubusercontent.com/u/5468095?v=3","gravatar_id":"","url":"https://api.github.com/users/PublicaMundi","html_url":"https://github.com/PublicaMundi","followers_url":"https://api.github.com/users/PublicaMundi/followers","following_url":"https://api.github.com/users/PublicaMundi/following{/other_user}","gists_url":"https://api.github.com/users/PublicaMundi/gists{/gist_id}","starred_url":"https://api.github.com/users/PublicaMundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PublicaMundi/subscriptions","organizations_url":"https://api.github.com/users/PublicaMundi/orgs","repos_url":"https://api.github.com/users/PublicaMundi/repos","events_url":"https://api.github.com/users/PublicaMundi/events{/privacy}","received_events_url":"https://api.github.com/users/PublicaMundi/received_events","type":"Organization","site_admin":false},"repo":{"id":19206221,"name":"ckanext-publicamundi","full_name":"PublicaMundi/ckanext-publicamundi","owner":{"login":"PublicaMundi","id":5468095,"avatar_url":"https://avatars.githubusercontent.com/u/5468095?v=3","gravatar_id":"","url":"https://api.github.com/users/PublicaMundi","html_url":"https://github.com/PublicaMundi","followers_url":"https://api.github.com/users/PublicaMundi/followers","following_url":"https://api.github.com/users/PublicaMundi/following{/other_user}","gists_url":"https://api.github.com/users/PublicaMundi/gists{/gist_id}","starred_url":"https://api.github.com/users/PublicaMundi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PublicaMundi/subscriptions","organizations_url":"https://api.github.com/users/PublicaMundi/orgs","repos_url":"https://api.github.com/users/PublicaMundi/repos","events_url":"https://api.github.com/users/PublicaMundi/events{/privacy}","received_events_url":"https://api.github.com/users/PublicaMundi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PublicaMundi/ckanext-publicamundi","description":"PublicaMundi main CKAN extension","fork":false,"url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi","forks_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/forks","keys_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/teams","hooks_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/hooks","issue_events_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/events{/number}","events_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/events","assignees_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/assignees{/user}","branches_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/branches{/branch}","tags_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/tags","blobs_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/git/refs{/sha}","trees_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/statuses/{sha}","languages_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/languages","stargazers_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/stargazers","contributors_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/contributors","subscribers_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/subscribers","subscription_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/subscription","commits_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/commits{/sha}","git_commits_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/git/commits{/sha}","comments_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/comments{/number}","issue_comment_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/comments{/number}","contents_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/contents/{+path}","compare_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/merges","archive_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/downloads","issues_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues{/number}","pulls_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls{/number}","milestones_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/milestones{/number}","notifications_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/labels{/name}","releases_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/releases{/id}","deployments_url":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/deployments","created_at":"2014-04-27T14:20:23Z","updated_at":"2015-11-19T10:24:46Z","pushed_at":"2016-01-21T16:26:36Z","git_url":"git://github.com/PublicaMundi/ckanext-publicamundi.git","ssh_url":"git@github.com:PublicaMundi/ckanext-publicamundi.git","clone_url":"https://github.com/PublicaMundi/ckanext-publicamundi.git","svn_url":"https://github.com/PublicaMundi/ckanext-publicamundi","homepage":"http://publicamundi.eu","size":18994,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":47,"forks":6,"open_issues":47,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227"},"html":{"href":"https://github.com/PublicaMundi/ckanext-publicamundi/pull/227"},"issue":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/227"},"comments":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/issues/227/comments"},"review_comments":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227/comments"},"review_comment":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/pulls/227/commits"},"statuses":{"href":"https://api.github.com/repos/PublicaMundi/ckanext-publicamundi/statuses/f0da8a13f8f789e2964a025593cffdb0db01f940"}}}}