Commit 01cfcc8d authored by Mark Chao's avatar Mark Chao

Extract snippet related permission table

For reuse in other areas
parent d9613bc7
...@@ -21,6 +21,9 @@ describe Search::SnippetService do ...@@ -21,6 +21,9 @@ describe Search::SnippetService do
end end
context 'visibility' do context 'visibility' do
include_context 'ProjectPolicyTable context'
include ProjectHelpers
let(:search_term) { 'foobar' } let(:search_term) { 'foobar' }
context 'project snippet' do context 'project snippet' do
...@@ -50,148 +53,7 @@ describe Search::SnippetService do ...@@ -50,148 +53,7 @@ describe Search::SnippetService do
let(:user) { create_user_from_membership(project, membership) } let(:user) { create_user_from_membership(project, membership) }
where(:snippet_level, :project_level, :feature_access_level, :membership, :expected_count) do where(:snippet_level, :project_level, :feature_access_level, :membership, :expected_count) do
:public | :public | :enabled | :admin | 1 permission_table_for_project_snippet_access
:public | :public | :enabled | :reporter | 1
:public | :public | :enabled | :guest | 1
:public | :public | :enabled | :non_member | 1
:public | :public | :enabled | :anonymous | 1
:public | :public | :private | :admin | 1
:public | :public | :private | :reporter | 1
:public | :public | :private | :guest | 1
:public | :public | :private | :non_member | 0
:public | :public | :private | :anonymous | 0
:public | :public | :disabled | :admin | 1
:public | :public | :disabled | :reporter | 0
:public | :public | :disabled | :guest | 0
:public | :public | :disabled | :non_member | 0
:public | :public | :disabled | :anonymous | 0
:public | :internal | :enabled | :admin | 1
:public | :internal | :enabled | :reporter | 1
:public | :internal | :enabled | :guest | 1
:public | :internal | :enabled | :non_member | 1
:public | :internal | :enabled | :anonymous | 0
:public | :internal | :private | :admin | 1
:public | :internal | :private | :reporter | 1
:public | :internal | :private | :guest | 1
:public | :internal | :private | :non_member | 0
:public | :internal | :private | :anonymous | 0
:public | :internal | :disabled | :admin | 1
:public | :internal | :disabled | :reporter | 0
:public | :internal | :disabled | :guest | 0
:public | :internal | :disabled | :non_member | 0
:public | :internal | :disabled | :anonymous | 0
:public | :private | :private | :admin | 1
:public | :private | :private | :reporter | 1
:public | :private | :private | :guest | 1
:public | :private | :private | :non_member | 0
:public | :private | :private | :anonymous | 0
:public | :private | :disabled | :reporter | 0
:public | :private | :disabled | :guest | 0
:public | :private | :disabled | :non_member | 0
:public | :private | :disabled | :anonymous | 0
:internal | :public | :enabled | :admin | 1
:internal | :public | :enabled | :reporter | 1
:internal | :public | :enabled | :guest | 1
:internal | :public | :enabled | :non_member | 1
:internal | :public | :enabled | :anonymous | 0
:internal | :public | :private | :admin | 1
:internal | :public | :private | :reporter | 1
:internal | :public | :private | :guest | 1
:internal | :public | :private | :non_member | 0
:internal | :public | :private | :anonymous | 0
:internal | :public | :disabled | :admin | 1
:internal | :public | :disabled | :reporter | 0
:internal | :public | :disabled | :guest | 0
:internal | :public | :disabled | :non_member | 0
:internal | :public | :disabled | :anonymous | 0
:internal | :internal | :enabled | :admin | 1
:internal | :internal | :enabled | :reporter | 1
:internal | :internal | :enabled | :guest | 1
:internal | :internal | :enabled | :non_member | 1
:internal | :internal | :enabled | :anonymous | 0
:internal | :internal | :private | :admin | 1
:internal | :internal | :private | :reporter | 1
:internal | :internal | :private | :guest | 1
:internal | :internal | :private | :non_member | 0
:internal | :internal | :private | :anonymous | 0
:internal | :internal | :disabled | :admin | 1
:internal | :internal | :disabled | :reporter | 0
:internal | :internal | :disabled | :guest | 0
:internal | :internal | :disabled | :non_member | 0
:internal | :internal | :disabled | :anonymous | 0
:internal | :private | :private | :admin | 1
:internal | :private | :private | :reporter | 1
:internal | :private | :private | :guest | 1
:internal | :private | :private | :non_member | 0
:internal | :private | :private | :anonymous | 0
:internal | :private | :disabled | :admin | 1
:internal | :private | :disabled | :reporter | 0
:internal | :private | :disabled | :guest | 0
:internal | :private | :disabled | :non_member | 0
:internal | :private | :disabled | :anonymous | 0
:private | :public | :enabled | :admin | 1
:private | :public | :enabled | :reporter | 1
:private | :public | :enabled | :guest | 1
:private | :public | :enabled | :non_member | 0
:private | :public | :enabled | :anonymous | 0
:private | :public | :private | :admin | 1
:private | :public | :private | :reporter | 1
:private | :public | :private | :guest | 1
:private | :public | :private | :non_member | 0
:private | :public | :private | :anonymous | 0
:private | :public | :disabled | :admin | 1
:private | :public | :disabled | :reporter | 0
:private | :public | :disabled | :guest | 0
:private | :public | :disabled | :non_member | 0
:private | :public | :disabled | :anonymous | 0
:private | :internal | :enabled | :admin | 1
:private | :internal | :enabled | :reporter | 1
:private | :internal | :enabled | :guest | 1
:private | :internal | :enabled | :non_member | 0
:private | :internal | :enabled | :anonymous | 0
:private | :internal | :private | :admin | 1
:private | :internal | :private | :reporter | 1
:private | :internal | :private | :guest | 1
:private | :internal | :private | :non_member | 0
:private | :internal | :private | :anonymous | 0
:private | :internal | :disabled | :admin | 1
:private | :internal | :disabled | :reporter | 0
:private | :internal | :disabled | :guest | 0
:private | :internal | :disabled | :non_member | 0
:private | :internal | :disabled | :anonymous | 0
:private | :private | :private | :admin | 1
:private | :private | :private | :reporter | 1
:private | :private | :private | :guest | 1
:private | :private | :private | :non_member | 0
:private | :private | :private | :anonymous | 0
:private | :private | :disabled | :admin | 1
:private | :private | :disabled | :reporter | 0
:private | :private | :disabled | :guest | 0
:private | :private | :disabled | :non_member | 0
:private | :private | :disabled | :anonymous | 0
end end
with_them do with_them do
...@@ -223,20 +85,7 @@ describe Search::SnippetService do ...@@ -223,20 +85,7 @@ describe Search::SnippetService do
let!(:snippet) { create(:personal_snippet, snippet_level, title: search_term, content: search_term) } let!(:snippet) { create(:personal_snippet, snippet_level, title: search_term, content: search_term) }
where(:snippet_level, :membership, :expected_count) do where(:snippet_level, :membership, :expected_count) do
:public | :admin | 1 permission_table_for_personal_snippet_access
:public | :author | 1
:public | :non_member | 1
:public | :anonymous | 1
:internal | :admin | 1
:internal | :author | 1
:internal | :non_member | 1
:internal | :anonymous | 0
:private | :admin | 1
:private | :author | 1
:private | :non_member | 0
:private | :anonymous | 0
end end
with_them do with_them do
......
...@@ -318,5 +318,169 @@ RSpec.shared_context 'ProjectPolicyTable context' do ...@@ -318,5 +318,169 @@ RSpec.shared_context 'ProjectPolicyTable context' do
:private | :non_member | 0 :private | :non_member | 0
:private | :anonymous | 0 :private | :anonymous | 0
end end
# :snippet_level, :project_level, :feature_access_level, :membership, :expected_count
def permission_table_for_project_snippet_access
:public | :public | :enabled | :admin | 1
:public | :public | :enabled | :reporter | 1
:public | :public | :enabled | :guest | 1
:public | :public | :enabled | :non_member | 1
:public | :public | :enabled | :anonymous | 1
:public | :public | :private | :admin | 1
:public | :public | :private | :reporter | 1
:public | :public | :private | :guest | 1
:public | :public | :private | :non_member | 0
:public | :public | :private | :anonymous | 0
:public | :public | :disabled | :admin | 1
:public | :public | :disabled | :reporter | 0
:public | :public | :disabled | :guest | 0
:public | :public | :disabled | :non_member | 0
:public | :public | :disabled | :anonymous | 0
:public | :internal | :enabled | :admin | 1
:public | :internal | :enabled | :reporter | 1
:public | :internal | :enabled | :guest | 1
:public | :internal | :enabled | :non_member | 1
:public | :internal | :enabled | :anonymous | 0
:public | :internal | :private | :admin | 1
:public | :internal | :private | :reporter | 1
:public | :internal | :private | :guest | 1
:public | :internal | :private | :non_member | 0
:public | :internal | :private | :anonymous | 0
:public | :internal | :disabled | :admin | 1
:public | :internal | :disabled | :reporter | 0
:public | :internal | :disabled | :guest | 0
:public | :internal | :disabled | :non_member | 0
:public | :internal | :disabled | :anonymous | 0
:public | :private | :private | :admin | 1
:public | :private | :private | :reporter | 1
:public | :private | :private | :guest | 1
:public | :private | :private | :non_member | 0
:public | :private | :private | :anonymous | 0
:public | :private | :disabled | :reporter | 0
:public | :private | :disabled | :guest | 0
:public | :private | :disabled | :non_member | 0
:public | :private | :disabled | :anonymous | 0
:internal | :public | :enabled | :admin | 1
:internal | :public | :enabled | :reporter | 1
:internal | :public | :enabled | :guest | 1
:internal | :public | :enabled | :non_member | 1
:internal | :public | :enabled | :anonymous | 0
:internal | :public | :private | :admin | 1
:internal | :public | :private | :reporter | 1
:internal | :public | :private | :guest | 1
:internal | :public | :private | :non_member | 0
:internal | :public | :private | :anonymous | 0
:internal | :public | :disabled | :admin | 1
:internal | :public | :disabled | :reporter | 0
:internal | :public | :disabled | :guest | 0
:internal | :public | :disabled | :non_member | 0
:internal | :public | :disabled | :anonymous | 0
:internal | :internal | :enabled | :admin | 1
:internal | :internal | :enabled | :reporter | 1
:internal | :internal | :enabled | :guest | 1
:internal | :internal | :enabled | :non_member | 1
:internal | :internal | :enabled | :anonymous | 0
:internal | :internal | :private | :admin | 1
:internal | :internal | :private | :reporter | 1
:internal | :internal | :private | :guest | 1
:internal | :internal | :private | :non_member | 0
:internal | :internal | :private | :anonymous | 0
:internal | :internal | :disabled | :admin | 1
:internal | :internal | :disabled | :reporter | 0
:internal | :internal | :disabled | :guest | 0
:internal | :internal | :disabled | :non_member | 0
:internal | :internal | :disabled | :anonymous | 0
:internal | :private | :private | :admin | 1
:internal | :private | :private | :reporter | 1
:internal | :private | :private | :guest | 1
:internal | :private | :private | :non_member | 0
:internal | :private | :private | :anonymous | 0
:internal | :private | :disabled | :admin | 1
:internal | :private | :disabled | :reporter | 0
:internal | :private | :disabled | :guest | 0
:internal | :private | :disabled | :non_member | 0
:internal | :private | :disabled | :anonymous | 0
:private | :public | :enabled | :admin | 1
:private | :public | :enabled | :reporter | 1
:private | :public | :enabled | :guest | 1
:private | :public | :enabled | :non_member | 0
:private | :public | :enabled | :anonymous | 0
:private | :public | :private | :admin | 1
:private | :public | :private | :reporter | 1
:private | :public | :private | :guest | 1
:private | :public | :private | :non_member | 0
:private | :public | :private | :anonymous | 0
:private | :public | :disabled | :admin | 1
:private | :public | :disabled | :reporter | 0
:private | :public | :disabled | :guest | 0
:private | :public | :disabled | :non_member | 0
:private | :public | :disabled | :anonymous | 0
:private | :internal | :enabled | :admin | 1
:private | :internal | :enabled | :reporter | 1
:private | :internal | :enabled | :guest | 1
:private | :internal | :enabled | :non_member | 0
:private | :internal | :enabled | :anonymous | 0
:private | :internal | :private | :admin | 1
:private | :internal | :private | :reporter | 1
:private | :internal | :private | :guest | 1
:private | :internal | :private | :non_member | 0
:private | :internal | :private | :anonymous | 0
:private | :internal | :disabled | :admin | 1
:private | :internal | :disabled | :reporter | 0
:private | :internal | :disabled | :guest | 0
:private | :internal | :disabled | :non_member | 0
:private | :internal | :disabled | :anonymous | 0
:private | :private | :private | :admin | 1
:private | :private | :private | :reporter | 1
:private | :private | :private | :guest | 1
:private | :private | :private | :non_member | 0
:private | :private | :private | :anonymous | 0
:private | :private | :disabled | :admin | 1
:private | :private | :disabled | :reporter | 0
:private | :private | :disabled | :guest | 0
:private | :private | :disabled | :non_member | 0
:private | :private | :disabled | :anonymous | 0
end
# :snippet_level, :membership, :expected_count
def permission_table_for_personal_snippet_access
:public | :admin | 1
:public | :author | 1
:public | :non_member | 1
:public | :anonymous | 1
:internal | :admin | 1
:internal | :author | 1
:internal | :non_member | 1
:internal | :anonymous | 0
:private | :admin | 1
:private | :author | 1
:private | :non_member | 0
:private | :anonymous | 0
end
# rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/AbcSize
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment