end
def public # Yes 'public' is the name of the action for public projects
- if Rails.configuration.anonymous_user_token
- @public_projects = using_specific_api_token Rails.configuration.anonymous_user_token do
- Group.where(group_class: 'project').order("updated_at DESC")
- end
- render 'public_projects'
- else
- redirect_to '/projects'
+ return render_not_found if not Rails.configuration.anonymous_user_token
+ @objects = using_specific_api_token Rails.configuration.anonymous_user_token do
+ Group.where(group_class: 'project').order("updated_at DESC")
end
end
end
-<table class="table arv-public-projects" style="width: 100%;">
+<table class="table">
<colgroup>
<col width="25%" />
<col width="75%" />
<thead>
<tr class="contain-align-left">
<th>
- Name
- </th><th>
- Description
+ Name
+ </th>
+ <th>
+ Description
+ </th>
</tr>
</thead>
- <% @public_projects.each do |p| %>
+ <tbody>
+ <% @objects.each do |p| %>
<tr>
<td style="word-break:break-all;">
<%= link_to_if_arvados_object p, {friendly_name: true} %>
- </div></td>
+ </td>
<td style="word-break:break-all;">
<%= render_attribute_as_textile(p, "description", p.description, true) %>
- </div></td>
+ </td>
</tr>
<% end %>
+ </tbody>
</table>
-
assert_response :redirect
assert_match /\/users\/welcome/, @response.redirect_url
end
+
+ [
+ nil,
+ :active,
+ ].each do |user|
+ test "visit public projects page when anon config is enabled, as user #{user}, and expect page" do
+ Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
+
+ if user
+ get :public, {}, session_for(user)
+ else
+ get :public
+ end
+
+ assert_response :success
+ assert_not_nil assigns(:objects)
+ project_names = assigns(:objects).collect(&:name)
+ assert_operator 0, :<, project_names.length
+ assert project_names.include?('Unrestricted public data')
+ assert !project_names.include?('A Project')
+ end
+ end
+
+ [
+ nil,
+ :active,
+ ].each do |user|
+ test "visit public projects page when anon config is not enabled, as user #{user}, and expect no such page" do
+ if user
+ get :public, {}, session_for(user)
+ assert_response 404
+ else
+ get :public
+ assert_response :redirect
+ assert_match /\/users\/welcome/, @response.redirect_url
+ end
+ end
+ end
end
if user['is_active']
assert_text 'Unrestricted public data'
assert_selector 'a', text: 'Projects'
+ page.find("#projects-menu").click
+ assert_selector 'a', text: 'Add a new project'
+ assert_selector 'a', text: 'Browse public projects'
+ assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
else
assert_text 'indicate that you have read and accepted the user agreement'
end
else
assert page.has_link?("Projects"), 'Not found link - Projects'
page.find("#projects-menu").click
+ assert_selector 'a', text: 'Add a new project'
+ assert_no_selector 'a', text: 'Browse public projects' # anonymous config is not enabled by default
assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
end
elsif invited
assert_no_selector 'li.disabled', text: 'Copy selected'
end
end
-
- [
- [true, nil, true],
- [true, 'active', true],
- [false, nil, false],
- [false, 'active', false],
- ].each do |anon_config, user, expect_page|
- test "visit public_projects page when anon config enabled #{anon_config}, as user #{user}, and expect page #{expect_page}" do
- Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token'] if anon_config
-
- if user
- visit page_with_token user, '/projects/public'
- else
- visit '/public_projects'
- end
-
- # verify public projects are listed
- assert_selector 'a', 'Unrestricted public data'
-
- if user
- find("#projects-menu").click
- if anon_config
- assert_selector 'a', text: 'Browse public projects'
- else
- assert_no_selector 'a', text: 'Browse public projects'
- end
- else
- within('.navbar-fixed-top') do
- assert_selector 'a', text: 'Log in'
- if anon_config
- assert_selector 'a', text: 'Browse public projects'
- else
- assert_no_selector 'a', text: 'Browse public projects'
- end
- end
- end
- end
- end
end