Skip to content

Commit

Permalink
Merge remote-tracking branch 'tess/master' into feature/simple_calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanVanVugt committed Aug 25, 2023
2 parents 2e7fe27 + 6358710 commit 420420b
Show file tree
Hide file tree
Showing 29 changed files with 460 additions and 171 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ gem 'icalendar', '~> 2.4.1'
gem 'rss'

gem 'bootstrap-datepicker-rails', '~> 1.6.4.1'
gem 'bootstrap-tab-history-rails'

gem 'rack-cors', require: 'rack/cors'

Expand Down Expand Up @@ -197,6 +198,7 @@ end

group :test do
gem 'minitest', '5.14.4'
gem 'minitest-reporters'
gem 'rails-controller-testing'
gem 'vcr', '~> 6.1.0'
gem 'webmock', '~> 3.18.1'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ GEM
device_detector
safely_block (>= 0.2.1)
amazing_print (1.4.0)
ansi (1.5.0)
ast (2.4.2)
attr_required (1.0.1)
auto_strip_attributes (2.6.0)
Expand All @@ -154,6 +155,8 @@ GEM
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
bootstrap-tab-history-rails (0.1.0)
railties (>= 3.1)
builder (3.2.4)
byebug (11.1.3)
case_transform (0.2)
Expand Down Expand Up @@ -367,6 +370,11 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.1)
minitest (5.14.4)
minitest-reporters (1.6.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
monetize (1.12.0)
money (~> 6.12)
money (6.16.0)
Expand Down Expand Up @@ -787,6 +795,7 @@ DEPENDENCIES
bootsnap (>= 1.4.4)
bootstrap-datepicker-rails (~> 1.6.4.1)
bootstrap-sass (>= 3.4.1)
bootstrap-tab-history-rails
by_star!
byebug
committee (~> 4.4)
Expand Down Expand Up @@ -816,6 +825,7 @@ DEPENDENCIES
listen
lunchy
minitest (= 5.14.4)
minitest-reporters
money-rails
omniauth-rails_csrf_protection
omniauth_openid_connect
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//= require jquery.turbolinks
//= require jquery_ujs
//= require bootstrap-sprockets
//= require bootstrap-tab-history
//= require cytoscape
//= require cytoscape-panzoom
//= require jscolor
Expand Down
17 changes: 6 additions & 11 deletions app/assets/javascripts/map_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ var MapSearch = {
var street_number = '';
var street_name = '';
var street_short = '';

//var message = 'place.name: ' + place.name;
//var newline = '\r\n';
var city = '';

for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
//message = message + newline + addressType + ': ' + place.address_components[i].long_name + ' (' +
// place.address_components[i].short_name + ')';
switch (addressType) {
case 'street_number':
street_number = place.address_components[i].short_name;
Expand All @@ -63,7 +59,8 @@ var MapSearch = {
street_short = place.address_components[i].short_name;
break;
case 'locality':
$('#event_city').val(place.address_components[i].long_name);
case 'postal_town':
city = place.address_components[i].long_name;
break;
case 'administrative_area_level_2':
$('#event_county').val(place.address_components[i].long_name);
Expand All @@ -79,17 +76,16 @@ var MapSearch = {

var street_address_short = street_number + ' ' + street_short;
var street_address_long = street_number + ' ' + street_name;
if (street_address_long.trim().length > 0 && venue != street_address_long) {
if (venue == street_address_short) {
if (street_address_long.trim().length > 0 && venue !== street_address_long) {
if (venue === street_address_short) {
venue = street_address_long;
} else {
venue = place.name + ', ' + street_address_long;
}
}

//window.alert(message);

$('#event_venue').val(venue);
$('#event_city').val(city);
$('#event_latitude').val(place.geometry.location.lat());
$('#event_longitude').val(place.geometry.location.lng());

Expand All @@ -106,7 +102,6 @@ var MapSearch = {
var venue = $('#event_venue').val();
var city = $('#event_city').val();
var country = $('#event_country').val();
var postcode = $('#event_postcode').val();
var lat = $('#event_latitude').val();
var lon = $('#event_longitude').val();

Expand Down
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def tab(text, icon, href, disabled: { check: false }, active: false, count: nil,
options['data-toggle'] = 'tooltip'
else
options['data-toggle'] = 'tab'
options['data-tab-history'] = true
options['data-tab-history-changer'] = 'replace'
options['data-tab-history-update-url'] = true
end

text << " (#{count})" if count
Expand Down
4 changes: 1 addition & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ def to_ical_event
end

def show_map?
Rails.application.secrets.google_maps_api_key.present? && # !self.online? &&
((latitude.present? && longitude.present?) ||
(suggested_latitude.present? && suggested_longitude.present?))
TeSS::Config.map_enabled && ((latitude.present? && longitude.present?) || (suggested_latitude.present? && suggested_longitude.present?))
end

def all_day?
Expand Down
34 changes: 10 additions & 24 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ class Profile < ApplicationRecord
auto_strip_attributes :firstname, :surname, :website, :orcid, squish: false
belongs_to :user, inverse_of: :profile

before_validation :check_orcid
before_validation :normalize_orcid
validates :firstname, :surname, :description, presence: true, if: :public?
validates :website, :orcid, url: true, http_url: true, allow_blank: true
validates :website, url: true, http_url: true, allow_blank: true
validates :orcid, orcid: true, allow_blank: true
after_validation :check_public
clean_array_fields(:expertise_academic, :expertise_technical, :fields,
:interest, :activity, :language, :social_media)
Expand Down Expand Up @@ -78,28 +79,13 @@ def merge(*others)

private

@@orcid_host = 'orcid.org'
@@orcid_scheme = 'https'
@@orcid_root_url = "#{@@orcid_scheme}://#{@@orcid_host}"

def check_orcid
if !orcid.nil? && !orcid.blank?
begin
uri = URI.parse(self.orcid)
raise if uri.path.blank? or uri.path == '/'
uri.path = '/' + uri.path unless uri.path.start_with? '/'
uri.host = @@orcid_host
uri.scheme = @@orcid_scheme
self.orcid = uri.to_s
rescue
errors.add(:orcid, "invalid id or URL")
end
end
end

def valid_orcid
if !orcid.nil? && !orcid.blank?
errors.add(:orcid, "invalid domain") unless self.orcid.to_s.start_with?(@@orcid_root_url)
def normalize_orcid
return if orcid.blank?
self.orcid = orcid.strip
if orcid =~ OrcidValidator::ORCID_ID_REGEX
self.orcid = "#{OrcidValidator::ORCID_PREFIX}#{orcid}"
elsif orcid.start_with?(OrcidValidator::ORCID_DOMAIN_REGEX)
self.orcid = orcid.sub(OrcidValidator::ORCID_DOMAIN_REGEX, OrcidValidator::ORCID_PREFIX)
end
end

Expand Down
26 changes: 14 additions & 12 deletions app/validators/http_url_validator.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
require 'net/http'

class HttpUrlValidator < ActiveModel::EachValidator

def self.blocked?(value)
blocked = (TeSS::Config.blocked_domains || []).any? do |regex|
(TeSS::Config.blocked_domains || []).any? do |regex|
value =~ regex
end
end

def self.accessible?(value)
begin
case Net::HTTP.get_response(URI.parse(value))
when Net::HTTPSuccess then true
else false
uri = URI.parse(value) rescue nil
if uri && (uri.scheme == 'http' || uri.scheme == 'https')
PrivateAddressCheck.only_public_connections do
res = HTTParty.get(value, { timeout: Rails.env.test? ? 1 : 5 })
res.code == 200
end
end
rescue
rescue PrivateAddressCheck::PrivateConnectionAttemptedError, Net::OpenTimeout, SocketError, Errno::ECONNREFUSED,
Errno::EHOSTUNREACH
false
end

end

def validate_each(record, attribute, value)
if value.present?
record.errors.add(attribute, "is blocked") if self.class.blocked?(value)
record.errors.add(attribute, "is not accessible") unless self.class.accessible?(value)
if self.class.blocked?(value)
record.errors.add(attribute, 'is blocked')
elsif !self.class.accessible?(value)
record.errors.add(attribute, 'is not accessible')
end
end
end

end
31 changes: 31 additions & 0 deletions app/validators/orcid_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class OrcidValidator < ActiveModel::EachValidator
ORCID_PREFIX = 'https://orcid.org/'.freeze
ORCID_DOMAIN_REGEX = /http(s)?\:\/\/orcid.org\//.freeze
ORCID_ID_REGEX = /\A[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9,X]{4}\Z/.freeze

def validate_each(record, attribute, value)
return if value.nil? || valid_orcid_id?(value.sub(ORCID_DOMAIN_REGEX, ''))
record.errors.add(attribute, options[:message] || "isn't a valid ORCID identifier")
end

private

# checks the structure of the id, and whether is conforms to ISO/IEC 7064:2003
def valid_orcid_id?(id)
if id =~ ORCID_ID_REGEX
id = id.delete('-')
id[15] == orcid_checksum(id)
else
false
end
end

# calculating the checksum according to ISO/IEC 7064:2003, MOD 11-2 ;
# see - https://support.orcid.org/hc/en-us/articles/360006897674-Structure-of-the-ORCID-Identifier
def orcid_checksum(id)
total = id.chars.first(15).inject(0) { |sum, value| (sum + value.to_i) * 2 }
remainder = total % 11
result = (12 - remainder) % 11
result == 10 ? 'X' : result.to_s
end
end
23 changes: 17 additions & 6 deletions app/views/about/_about_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@
<li class="about-page-category">
<%= link_to 'About Us', us_path %>
</li>
<li><%= about_nav_link('TeSS Club', us_path, 'tess-club') %></li>
<li><%= about_nav_link('Contact', us_path, 'contact') %></li>
<li><%= about_nav_link('The Team', us_path, 'team') %></li>
<li><%= about_nav_link('Funding', us_path, 'funding') %></li>
<li><%= about_nav_link('Acknowledgements', us_path, 'acknowledgments') %></li>
<li><%= about_nav_link('Cite Us', us_path, 'cite') %></li>
<%
about_us_tabs = [
{link: us_path , key:'tess_club'},
{link: us_path , key:'contact'},
{link: us_path , key:'team'},
{link: us_path , key:'funding'},
{link: us_path , key:'acknowledgements'},
{link: us_path , key:'cite'}
].select do |tab|
TeSS::Config.site['about_us_tab_order'].include?(tab[:key])
end.sort_by do |tab|
TeSS::Config.site['about_us_tab_order'].index(tab[:key]) || 99
end
%>
<% about_us_tabs.each do |tab| %>
<li><%= about_nav_link(t("us.keys.#{tab[:key]}"), tab[:link], tab[:key]) %></li>
<% end %>
</ul>
</nav>
75 changes: 31 additions & 44 deletions app/views/about/us.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,39 @@
<h2>About Us</h2>
<% @feature_count = 0 %>
<!-- TeSS Club-->
<div id="tess-club" class="<%= next_about_block(@feature_count += 1) %>">
<h3>TeSS Club</h3>
<%== t 'us.tess_club' %>
</div>

<!-- CONTACT-->
<div id="contact" class="<%= next_about_block(@feature_count += 1) %>">
<h3>Contact</h3>
<%== t 'us.contact' %>
</div>

<!-- FUNDING-->
<div id="funding" class="<%= next_about_block(@feature_count += 1) %>">
<h3>Funding</h3>
<%== t 'us.funding' %>
<% if TeSS::Config.funders.present? %>
<p>
<% TeSS::Config.funders.each do |funder| %>
<%= link_to(funder['url'], target: '_blank', rel: 'noopener') do -%>
<%= image_tag(funder['logo'], class: 'funding-logo') -%>
<% end %>
<% TeSS::Config.site['about_us_tab_order'].each do |key| %>
<% case key %>
<% when 'funding' %>
<%# FUNDING %>
<div id="funding" class="<%= next_about_block(@feature_count += 1) %>">
<h3><%== t "us.keys.#{key}" %></h3>
<%== t 'us.funding' %>
<% if TeSS::Config.funders.present? %>
<p>
<% TeSS::Config.funders.each do |funder| %>
<%= link_to(funder['url'], target: '_blank', rel: 'noopener') do -%>
<%= image_tag(funder['logo'], class: 'funding-logo') -%>
<% end %>
<% end %>
</p>
<% end %>
</p>
</div>
<% when 'cite' %>
<%# CITE %>
<div id=key class="<%= next_about_block(@feature_count += 1) %>">
<h3><%== t "us.keys.#{key}" %></h3>
<blockquote>
<%== t "us.#{key}" %>
<blockquote>
</div>
<% else %>
<%# OTHERS %>
<div id=key class="<%= next_about_block(@feature_count += 1) %>">
<h3><%== t "us.keys.#{key}" %></h3>
<%== t "us.#{key}" %>
</div>
<% end %>
</div>

<!-- THE TEAM-->
<div id="team" class="<%= next_about_block(@feature_count += 1) %>">
<h3>The Team</h3>
<%== t 'us.team' %>
</div>

<!-- ACKNOWLEDGEMENTS-->
<div id="acknowledgements" class="<%= next_about_block(@feature_count += 1) %>">
<h3>Acknowledgements</h3>
<%== t 'us.acknowledge' %>
</div>

<!-- Cite -->
<div id="cite" class="<%= next_about_block(@feature_count += 1) %>">
<h3>Cite Us</h3>
<blockquote>
<%== t 'us.cite' %>
</blockquote>
</div>
<% end %>
</div>

<hr/>
Expand Down
Loading

0 comments on commit 420420b

Please sign in to comment.