{"action":"created","comment":{"url":"https://api.github.com/repos/codevise/pageflow/pulls/comments/57153214","id":57153214,"diff_hunk":"@@ -0,0 +1,51 @@\n+require 'spec_helper'\n+\n+module Pageflow\n+  module Policies\n+    shared_examples 'a membership-based permission that' do |params|\n+      let(:user) { create(:user) }\n+      let(:subject) { params[:terms][:subject] }\n+      let(:entity) { params[:terms][:entity] }\n+      let(:policy) { params[:terms][:class].new(user, subject) }\n+\n+      it \"allows #{params[:entity_type]} #{params[:minimum_required_role]} \" \\\n+         \"to #{params[:permission_type]} respective #{params[:terms][:name]}\" do\n+        create(:membership, user: user, entity: entity, role: params[:minimum_required_role])\n+\n+        expect(policy).to permit_action(params[:permission_type])\n+      end\n+\n+      it \"does not allow #{params[:entity_type]} #{params[:minimum_required_role]} \" \\\n+         \"to #{params[:permission_type]} off-limits #{params[:terms][:name]}\" do\n+        other_entity = (params[:entity_type] == :entry ? create(:entry) : create(:account))\n+        create(:membership, user: user, entity: other_entity, role: params[:minimum_required_role])\n+\n+        expect(policy).not_to permit_action(params[:permission_type])\n+      end\n+\n+      if params[:maximum_forbidden_role].present?\n+        it \"does not allow #{params[:entity_type]} #{params[:maximum_forbidden_role]} \" \\\n+           \"to #{params[:permission_type]} respective #{params[:terms][:name]}\" do\n+          create(:membership, user: user, entity: entity, role: params[:maximum_forbidden_role])\n+\n+          expect(policy).not_to permit_action(params[:permission_type])\n+        end\n+      else\n+        it 'does not allow user without membership ' \\\n+           \"to #{params[:permission_type]} respective #{params[:terms][:name]}\" do\n+          expect(policy).not_to permit_action(params[:permission_type])\n+        end\n+      end\n+    end\n+\n+    shared_examples 'for entry and account' do |params|\n+      params_entry = params.merge(entity_type: :entry)\n+      params_entry[:terms].merge!(entity: params[:terms][:subject])\n+      it_behaves_like 'a membership-based permission that', params_entry\n+\n+      params_account = params.merge(entity_type: :account)\n+      params_account[:terms].merge!(entity: params[:terms][:subject].account)","path":"spec/pageflow/policies/membership_based_permission_shared_examples.rb","position":47,"original_position":47,"commit_id":"12387ccdd85f85d9c1358a089c2cdd6699fe7c82","original_commit_id":"12387ccdd85f85d9c1358a089c2cdd6699fe7c82","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Use `params_account[:terms][:entity] = params[:terms][:subject].account` instead of `params_account[:terms].merge!(entity: params[:terms][:subject].account)`.","created_at":"2016-03-23T12:50:29Z","updated_at":"2016-03-23T12:50:29Z","html_url":"https://github.com/codevise/pageflow/pull/504#discussion_r57153214","pull_request_url":"https://api.github.com/repos/codevise/pageflow/pulls/504","_links":{"self":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/comments/57153214"},"html":{"href":"https://github.com/codevise/pageflow/pull/504#discussion_r57153214"},"pull_request":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/504"}}},"pull_request":{"url":"https://api.github.com/repos/codevise/pageflow/pulls/504","id":62043107,"html_url":"https://github.com/codevise/pageflow/pull/504","diff_url":"https://github.com/codevise/pageflow/pull/504.diff","patch_url":"https://github.com/codevise/pageflow/pull/504.patch","issue_url":"https://api.github.com/repos/codevise/pageflow/issues/504","number":504,"state":"open","locked":false,"title":"[WIP] Extend permissions model","user":{"login":"aviav","id":7578262,"avatar_url":"https://avatars.githubusercontent.com/u/7578262?v=3","gravatar_id":"","url":"https://api.github.com/users/aviav","html_url":"https://github.com/aviav","followers_url":"https://api.github.com/users/aviav/followers","following_url":"https://api.github.com/users/aviav/following{/other_user}","gists_url":"https://api.github.com/users/aviav/gists{/gist_id}","starred_url":"https://api.github.com/users/aviav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviav/subscriptions","organizations_url":"https://api.github.com/users/aviav/orgs","repos_url":"https://api.github.com/users/aviav/repos","events_url":"https://api.github.com/users/aviav/events{/privacy}","received_events_url":"https://api.github.com/users/aviav/received_events","type":"User","site_admin":false},"body":"Make memberships' entity polymorphic, require role\r\n\r\nMemberships can now refer to accounts as well as entrys via the\r\npolymorphic entity attribute, which replaces the entry attribute.\r\n\r\nMemberships now also have a non-null role attribute which defaults to\r\n'editor'. This attribute will also hold the values 'admin', 'publisher'\r\nand 'reader' as soon as the permissions model is replaced.\r\n\r\nMemberships as of this commit cannot be created or deleted in the admin\r\ninterface via their user. Ways to facilitate a desired interaction\r\nbetween Formtastic, ActiveAdmin and the polymorphic entity attribute\r\nmight be found at\r\nhttps://github.com/activeadmin/activeadmin/wiki/Nested-forms-with-polymorphic-association-in-Active-Admin-Formtastic\r\n.","created_at":"2016-03-08T09:13:24Z","updated_at":"2016-03-23T12:50:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"534b83563df8d5491d85824ae13c0418bf58ef60","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codevise/pageflow/pulls/504/commits","review_comments_url":"https://api.github.com/repos/codevise/pageflow/pulls/504/comments","review_comment_url":"https://api.github.com/repos/codevise/pageflow/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codevise/pageflow/issues/504/comments","statuses_url":"https://api.github.com/repos/codevise/pageflow/statuses/12387ccdd85f85d9c1358a089c2cdd6699fe7c82","head":{"label":"aviav:roles-polymorphic","ref":"roles-polymorphic","sha":"12387ccdd85f85d9c1358a089c2cdd6699fe7c82","user":{"login":"aviav","id":7578262,"avatar_url":"https://avatars.githubusercontent.com/u/7578262?v=3","gravatar_id":"","url":"https://api.github.com/users/aviav","html_url":"https://github.com/aviav","followers_url":"https://api.github.com/users/aviav/followers","following_url":"https://api.github.com/users/aviav/following{/other_user}","gists_url":"https://api.github.com/users/aviav/gists{/gist_id}","starred_url":"https://api.github.com/users/aviav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviav/subscriptions","organizations_url":"https://api.github.com/users/aviav/orgs","repos_url":"https://api.github.com/users/aviav/repos","events_url":"https://api.github.com/users/aviav/events{/privacy}","received_events_url":"https://api.github.com/users/aviav/received_events","type":"User","site_admin":false},"repo":{"id":53050743,"name":"pageflow","full_name":"aviav/pageflow","owner":{"login":"aviav","id":7578262,"avatar_url":"https://avatars.githubusercontent.com/u/7578262?v=3","gravatar_id":"","url":"https://api.github.com/users/aviav","html_url":"https://github.com/aviav","followers_url":"https://api.github.com/users/aviav/followers","following_url":"https://api.github.com/users/aviav/following{/other_user}","gists_url":"https://api.github.com/users/aviav/gists{/gist_id}","starred_url":"https://api.github.com/users/aviav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aviav/subscriptions","organizations_url":"https://api.github.com/users/aviav/orgs","repos_url":"https://api.github.com/users/aviav/repos","events_url":"https://api.github.com/users/aviav/events{/privacy}","received_events_url":"https://api.github.com/users/aviav/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aviav/pageflow","description":"Multimedia story telling for the web.","fork":true,"url":"https://api.github.com/repos/aviav/pageflow","forks_url":"https://api.github.com/repos/aviav/pageflow/forks","keys_url":"https://api.github.com/repos/aviav/pageflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aviav/pageflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aviav/pageflow/teams","hooks_url":"https://api.github.com/repos/aviav/pageflow/hooks","issue_events_url":"https://api.github.com/repos/aviav/pageflow/issues/events{/number}","events_url":"https://api.github.com/repos/aviav/pageflow/events","assignees_url":"https://api.github.com/repos/aviav/pageflow/assignees{/user}","branches_url":"https://api.github.com/repos/aviav/pageflow/branches{/branch}","tags_url":"https://api.github.com/repos/aviav/pageflow/tags","blobs_url":"https://api.github.com/repos/aviav/pageflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aviav/pageflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aviav/pageflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/aviav/pageflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aviav/pageflow/statuses/{sha}","languages_url":"https://api.github.com/repos/aviav/pageflow/languages","stargazers_url":"https://api.github.com/repos/aviav/pageflow/stargazers","contributors_url":"https://api.github.com/repos/aviav/pageflow/contributors","subscribers_url":"https://api.github.com/repos/aviav/pageflow/subscribers","subscription_url":"https://api.github.com/repos/aviav/pageflow/subscription","commits_url":"https://api.github.com/repos/aviav/pageflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/aviav/pageflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/aviav/pageflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/aviav/pageflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/aviav/pageflow/contents/{+path}","compare_url":"https://api.github.com/repos/aviav/pageflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aviav/pageflow/merges","archive_url":"https://api.github.com/repos/aviav/pageflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aviav/pageflow/downloads","issues_url":"https://api.github.com/repos/aviav/pageflow/issues{/number}","pulls_url":"https://api.github.com/repos/aviav/pageflow/pulls{/number}","milestones_url":"https://api.github.com/repos/aviav/pageflow/milestones{/number}","notifications_url":"https://api.github.com/repos/aviav/pageflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aviav/pageflow/labels{/name}","releases_url":"https://api.github.com/repos/aviav/pageflow/releases{/id}","deployments_url":"https://api.github.com/repos/aviav/pageflow/deployments","created_at":"2016-03-03T13:04:03Z","updated_at":"2016-03-03T13:04:05Z","pushed_at":"2016-03-23T12:50:09Z","git_url":"git://github.com/aviav/pageflow.git","ssh_url":"git@github.com:aviav/pageflow.git","clone_url":"https://github.com/aviav/pageflow.git","svn_url":"https://github.com/aviav/pageflow","homepage":"http://pageflow.io","size":9883,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"codevise:master","ref":"master","sha":"7c3cf0917e64267a1b5ed4b8c8e300f07ddc7511","user":{"login":"codevise","id":537804,"avatar_url":"https://avatars.githubusercontent.com/u/537804?v=3","gravatar_id":"","url":"https://api.github.com/users/codevise","html_url":"https://github.com/codevise","followers_url":"https://api.github.com/users/codevise/followers","following_url":"https://api.github.com/users/codevise/following{/other_user}","gists_url":"https://api.github.com/users/codevise/gists{/gist_id}","starred_url":"https://api.github.com/users/codevise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codevise/subscriptions","organizations_url":"https://api.github.com/users/codevise/orgs","repos_url":"https://api.github.com/users/codevise/repos","events_url":"https://api.github.com/users/codevise/events{/privacy}","received_events_url":"https://api.github.com/users/codevise/received_events","type":"Organization","site_admin":false},"repo":{"id":19446839,"name":"pageflow","full_name":"codevise/pageflow","owner":{"login":"codevise","id":537804,"avatar_url":"https://avatars.githubusercontent.com/u/537804?v=3","gravatar_id":"","url":"https://api.github.com/users/codevise","html_url":"https://github.com/codevise","followers_url":"https://api.github.com/users/codevise/followers","following_url":"https://api.github.com/users/codevise/following{/other_user}","gists_url":"https://api.github.com/users/codevise/gists{/gist_id}","starred_url":"https://api.github.com/users/codevise/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codevise/subscriptions","organizations_url":"https://api.github.com/users/codevise/orgs","repos_url":"https://api.github.com/users/codevise/repos","events_url":"https://api.github.com/users/codevise/events{/privacy}","received_events_url":"https://api.github.com/users/codevise/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codevise/pageflow","description":"Multimedia story telling for the web.","fork":false,"url":"https://api.github.com/repos/codevise/pageflow","forks_url":"https://api.github.com/repos/codevise/pageflow/forks","keys_url":"https://api.github.com/repos/codevise/pageflow/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codevise/pageflow/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codevise/pageflow/teams","hooks_url":"https://api.github.com/repos/codevise/pageflow/hooks","issue_events_url":"https://api.github.com/repos/codevise/pageflow/issues/events{/number}","events_url":"https://api.github.com/repos/codevise/pageflow/events","assignees_url":"https://api.github.com/repos/codevise/pageflow/assignees{/user}","branches_url":"https://api.github.com/repos/codevise/pageflow/branches{/branch}","tags_url":"https://api.github.com/repos/codevise/pageflow/tags","blobs_url":"https://api.github.com/repos/codevise/pageflow/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codevise/pageflow/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codevise/pageflow/git/refs{/sha}","trees_url":"https://api.github.com/repos/codevise/pageflow/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codevise/pageflow/statuses/{sha}","languages_url":"https://api.github.com/repos/codevise/pageflow/languages","stargazers_url":"https://api.github.com/repos/codevise/pageflow/stargazers","contributors_url":"https://api.github.com/repos/codevise/pageflow/contributors","subscribers_url":"https://api.github.com/repos/codevise/pageflow/subscribers","subscription_url":"https://api.github.com/repos/codevise/pageflow/subscription","commits_url":"https://api.github.com/repos/codevise/pageflow/commits{/sha}","git_commits_url":"https://api.github.com/repos/codevise/pageflow/git/commits{/sha}","comments_url":"https://api.github.com/repos/codevise/pageflow/comments{/number}","issue_comment_url":"https://api.github.com/repos/codevise/pageflow/issues/comments{/number}","contents_url":"https://api.github.com/repos/codevise/pageflow/contents/{+path}","compare_url":"https://api.github.com/repos/codevise/pageflow/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codevise/pageflow/merges","archive_url":"https://api.github.com/repos/codevise/pageflow/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codevise/pageflow/downloads","issues_url":"https://api.github.com/repos/codevise/pageflow/issues{/number}","pulls_url":"https://api.github.com/repos/codevise/pageflow/pulls{/number}","milestones_url":"https://api.github.com/repos/codevise/pageflow/milestones{/number}","notifications_url":"https://api.github.com/repos/codevise/pageflow/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codevise/pageflow/labels{/name}","releases_url":"https://api.github.com/repos/codevise/pageflow/releases{/id}","deployments_url":"https://api.github.com/repos/codevise/pageflow/deployments","created_at":"2014-05-05T06:50:13Z","updated_at":"2016-03-21T22:44:46Z","pushed_at":"2016-03-23T12:50:10Z","git_url":"git://github.com/codevise/pageflow.git","ssh_url":"git@github.com:codevise/pageflow.git","clone_url":"https://github.com/codevise/pageflow.git","svn_url":"https://github.com/codevise/pageflow","homepage":"http://pageflow.io","size":10589,"stargazers_count":287,"watchers_count":287,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":71,"mirror_url":null,"open_issues_count":18,"forks":71,"open_issues":18,"watchers":287,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/504"},"html":{"href":"https://github.com/codevise/pageflow/pull/504"},"issue":{"href":"https://api.github.com/repos/codevise/pageflow/issues/504"},"comments":{"href":"https://api.github.com/repos/codevise/pageflow/issues/504/comments"},"review_comments":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/504/comments"},"review_comment":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codevise/pageflow/pulls/504/commits"},"statuses":{"href":"https://api.github.com/repos/codevise/pageflow/statuses/12387ccdd85f85d9c1358a089c2cdd6699fe7c82"}}}}