Skip to content

Commit a6e8dd2

Browse files
committed
ELIXIR-specific changes
* Add keywords to event index. Use labels to display * Add CSV format for elearning index * Don't display website until user has signed in 10 times * Don't display unverified users in index * Honeypot field
1 parent 54d2b38 commit a6e8dd2

12 files changed

Lines changed: 100 additions & 13 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,8 @@ def configure_permitted_parameters
159159
def allow_embedding
160160
response.headers.delete 'X-Frame-Options'
161161
end
162+
163+
def disable_pagination
164+
params[:per_page] = 2 ** 10
165+
end
162166
end

app/controllers/materials_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class MaterialsController < ApplicationController
55
add_term reject_term add_data reject_data]
66
before_action :set_breadcrumbs
77
before_action :set_learning_path_navigation, only: :show
8+
before_action :disable_pagination, only: :index, if: lambda { |controller| controller.request.format.csv? }
89

910
include SearchableIndex
1011
include ActionView::Helpers::TextHelper
@@ -22,6 +23,7 @@ def index
2223
respond_to do |format|
2324
format.html { render elearning ? 'elearning_materials/index' : 'index' }
2425
format.json
26+
format.csv { render 'elearning_materials/index' } if elearning
2527
format.json_api { render({ json: @materials }.merge(api_collection_properties)) }
2628
end
2729
end

app/controllers/tess_devise/registrations_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def update_resource(resource, params)
2525

2626
# Pinched from https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
2727
def check_captcha
28-
if !Rails.application.config.secrets.recaptcha[:sitekey].blank? && !verify_recaptcha
28+
if (Rails.application.config.secrets.recaptcha[:sitekey].present? && !verify_recaptcha) ||
29+
params.dig('user', 'website').present?
2930
self.resource = resource_class.new sign_up_params
3031
respond_with_navigational(resource) { render :new }
3132
end

app/controllers/users_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ class UsersController < ApplicationController
1414
# GET /users.json
1515
def index
1616
@users = User.visible
17-
@users = @users.with_query(params[:q].chomp('*')) if params[:q].present?
17+
if params[:q].present?
18+
@users = @users.with_query(params[:q].chomp('*'))
19+
elsif !(current_user&.is_admin? || current_user&.is_curator?)
20+
@users = @users.verified
21+
end
1822
@users = @users.paginate(page: params[:page], per_page: 50)
1923

2024
respond_to do |format|
@@ -26,7 +30,7 @@ def index
2630

2731
# GET/invitees
2832
def invitees
29-
if current_user.is_admin? || current_user.is_curator?
33+
if current_user&.is_admin? || current_user&.is_curator?
3034
@users = User.invited
3135
respond_to do |format|
3236
format.html

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ def registrations
392392
n_events + n_materials
393393
end
394394

395+
def show_website?
396+
sign_in_count > 10
397+
end
398+
395399
protected
396400

397401
def reassign_resources(new_owner = User.get_default_user)

app/views/devise/registrations/new.html.erb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@
2929

3030
<%= f.input :email, required: true %>
3131

32+
<div style="opacity: 0; height: 0; overflow: hidden">
33+
<div class="form-group website required user_website">
34+
<label class="control-label website" for="user_website"><abbr title="required">*</abbr> Website</label>
35+
<input class="form-control string website required" type="text" value="" name="user[website]" id="user_website">
36+
</div>
37+
</div>
38+
3239
<%= f.input :publicize_email, as: :boolean, label: 'Make my email publicly visible' %>
3340

3441
<%= f.input :password, required: true, input_html: { autocomplete: 'off' },
35-
hint: "(#{@minimum_password_length} characters minimum)" if @minimum_password_length %>
42+
hint: @minimum_password_length ? "(#{@minimum_password_length} characters minimum)" : nil %>
3643

3744
<%= f.input :password_confirmation, required: true, input_html: { autocomplete: 'off' } %>
3845

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<%
2+
fields = [:id, :title, :url, :description, :keywords, :resource_type, :other_types, :scientific_topics, :operations, :fields, :external_resources, :doi, :licence, :version, :status, :contact, :contributors, :authors, :difficulty_level, :target_audience, :prerequisites, :syllabus, :learning_objectives, :subsets, :date_created, :date_modified, :date_published, :created_at, :updated_at].freeze
3+
%>
4+
<%= (['TeSS URL'] + fields.map { |f| Material.human_attribute_name(f) }).to_csv(row_sep: nil) %>
5+
<% @index_resources.each do |material| %>
6+
<%= ([material_url(material)] + fields.map do |f|
7+
value = material.send(f)
8+
value = value.map do |v|
9+
case v
10+
when OntologyTerm
11+
v.label
12+
when ExternalResource
13+
v.url
14+
else
15+
v
16+
end
17+
end.join(', ') if value.respond_to?(:each)
18+
value
19+
end).to_csv(row_sep: nil).html_safe %>
20+
<% end %>

app/views/events/_event.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<i class="icon icon-md <%= event.presence %>-event-icon"></i>
4747
<span class="muted"><%= t("activerecord.attributes.event.presence.#{event.presence}") %></span>
4848
</p>
49+
50+
<%= keywords_and_topics(event) %>
4951
</div>
5052
<% if TeSS::Config.site.fetch('show_provider_logo_in_event', false) && event.content_provider&.image&.url.present? %>
5153
<div>

app/views/users/show.html.erb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@
3535
<% end %>
3636
</p>
3737

38-
<p>
39-
<strong><%= model_class.human_attribute_name(:website) %></strong><br/>
40-
<% if @user.profile.website.blank? %>
41-
<span class="empty">None specified</span>
42-
<% else %>
43-
<%= link_to @user.profile.website, @user.profile.website, rel: 'nofollow', target: '_blank' %>
44-
<% end %>
45-
</p>
38+
<% if @user.show_website? || (current_user&.is_admin? || current_user&.is_curator?) %>
39+
<p>
40+
<strong><%= model_class.human_attribute_name(:website) %></strong><br/>
41+
<% if @user.profile.website.blank? %>
42+
<span class="empty">None specified</span>
43+
<% else %>
44+
<%= link_to @user.profile.website, @user.profile.website, rel: 'nofollow', target: '_blank' %>
45+
<% end %>
46+
</p>
47+
<% end %>
4648

4749
<p>
4850
<strong>ORCID</strong><br/>

test/controllers/materials_controller_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,4 +1698,18 @@ class MaterialsControllerTest < ActionController::TestCase
16981698
assert_select 'p.scientific_topics a[href="http://edamontology.org/topic_0622"]', text: 'Genomics'
16991699
assert_select 'p.operations a[href="http://edamontology.org/operation_0292"]', text: 'Sequence alignment'
17001700
end
1701+
1702+
test 'should get e-learning index as csv' do
1703+
with_settings(solr_enabled: true, feature: { elearning_materials: true }) do
1704+
Material.stub(:search_and_filter, MockSearch.new(Material.all)) do
1705+
get :index, params: { resource_type: 'e-learning', format: :csv }
1706+
1707+
assert_response :success
1708+
end
1709+
end
1710+
1711+
csv = CSV.parse(@response.body, headers: true)
1712+
assert_equal Material.count, csv.length
1713+
assert csv.any? { |row| row[0] == material_url(@material) }
1714+
end
17011715
end

0 commit comments

Comments
 (0)