class ProjectsController < ApplicationController
- before_filter :set_share_links, if: -> { defined? @object }
+ before_filter :set_share_links, if: -> { defined? @object and @object}
skip_around_filter :require_thread_api_token, if: proc { |ctrl|
Rails.configuration.anonymous_user_token and
- %w(show tab_counts).include? ctrl.action_name
+ %w(show tab_counts public).include? ctrl.action_name
}
def model_class
end
objects_and_names
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'
+ end
+ end
end
</li>
<% end %>
<% else %>
+ <% if Rails.configuration.anonymous_user_token %>
+ <li><%= link_to raw('Browse public projects'), "/projects/public" %></li>
+ <% end %>
<li class="dropdown hover-dropdown login-menu">
<a href="<%= arvados_api_client.arvados_login_url(return_to: root_url) %>">Log in</a>
<ul class="dropdown-menu">
<span class="caret"></span>
</a>
<ul class="dropdown-menu" style="min-width: 20em" role="menu">
+ <% if Rails.configuration.anonymous_user_token %>
+ <li><%= link_to raw('Browse public projects'), "/projects/public", class: 'btn btn-xs btn-default pull-right' %></li>
+ <% end %>
<li>
<%= link_to projects_path(options: {ensure_unique_name: true}), method: :post, class: 'btn btn-xs btn-default pull-right' do %>
<i class="fa fa-plus"></i> Add a new project
--- /dev/null
+<table class="table arv-public-projects" style="width: 100%;">
+ <colgroup>
+ <col width="25%" />
+ <col width="75%" />
+ </colgroup>
+ <thead>
+ <tr class="contain-align-left">
+ <th>
+ Name
+ </th><th>
+ Description
+ </tr>
+ </thead>
+
+ <% @public_projects.each do |p| %>
+ <tr>
+ <td style="word-break:break-all;">
+ <%= link_to_if_arvados_object p, {friendly_name: true} %>
+ </div></td>
+ <td style="word-break:break-all;">
+ <%= render_attribute_as_textile(p, "description", p.description, true) %>
+ </div></td>
+ </tr>
+ <% end %>
+</table>
+
get 'choose', on: :collection
post 'share_with', on: :member
get 'tab_counts', on: :member
+ get 'public', on: :collection
end
+
resources :search do
get 'choose', :on => :collection
end
assert_text Rails.configuration.site_name.downcase
assert_no_selector 'a', text: Rails.configuration.site_name.downcase
assert_selector 'a', text: 'Log in'
+ assert_selector 'a', text: 'Browse public projects'
end
end
end
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