Skip to content

Commit

Permalink
Merge branch 'dev' into feature/feedback-button
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Mar 19, 2024
2 parents 5374cb2 + 469bb11 commit 4952d6e
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 137 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
//= require vertices
//= require watchlists
//= require turbolinks
//= require search_tags
19 changes: 19 additions & 0 deletions app/assets/javascripts/search_tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$(document).on("turbolinks:load", function () {
$("#search_all_tags").change(evt => toggleSearchAllTags(evt));
});

/**
* Dynamically enable/disable the OR/AND buttons in the media search form.
* If the user has decided to search for media regardless of the tags,
* i.e. they enable the "all" (tags) button, we disable the "OR/AND" buttons
* as it is pointless to search for media that references *all* available tags
* at once.
*/
function toggleSearchAllTags(evt) {
const searchAllTags = evt.target.checked;
if (searchAllTags) {
$("#search_tag_operator_or").prop("checked", true);
}
$("#search_tag_operator_or").prop("disabled", searchAllTags);
$("#search_tag_operator_and").prop("disabled", searchAllTags);
}
12 changes: 6 additions & 6 deletions app/controllers/erdbeere_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def current_ability
end

def show_example
response = Faraday.get(ENV.fetch("ERDBEERE_API", nil) + "/examples/#{params[:id]}")
response = Faraday.get(ENV.fetch("ERDBEERE_API") + "/examples/#{params[:id]}")
@content = if response.status == 200
JSON.parse(response.body)["embedded_html"]
else
Expand All @@ -17,7 +17,7 @@ def show_example
end

def show_property
response = Faraday.get(ENV.fetch("ERDBEERE_API", nil) + "/properties/#{params[:id]}")
response = Faraday.get(ENV.fetch("ERDBEERE_API") + "/properties/#{params[:id]}")

@content = if response.status == 200
JSON.parse(response.body)["embedded_html"]
Expand All @@ -28,7 +28,7 @@ def show_property

def show_structure
params[:id]
response = Faraday.get(ENV.fetch("ERDBEERE_API", nil) + "/structures/#{params[:id]}")
response = Faraday.get(ENV.fetch("ERDBEERE_API") + "/structures/#{params[:id]}")
@content = if response.status == 200
JSON.parse(response.body)["embedded_html"]
else
Expand All @@ -51,7 +51,7 @@ def cancel_edit_tags
def display_info
@id = params[:id]
@sort = params[:sort]
response = Faraday.get(ENV.fetch("ERDBEERE_API", nil) +
response = Faraday.get(ENV.fetch("ERDBEERE_API") +
"/#{@sort.downcase.pluralize}/#{@id}/view_info")
@content = JSON.parse(response.body)
if response.status != 200
Expand Down Expand Up @@ -87,7 +87,7 @@ def update_tags
end

def fill_realizations_select
response = Faraday.get("#{ENV.fetch("ERDBEERE_API", nil)}/structures/")
response = Faraday.get("#{ENV.fetch("ERDBEERE_API")}/structures/")
@tag = Tag.find_by(id: params[:id])
hash = JSON.parse(response.body)
@structures = hash["data"].map do |d|
Expand All @@ -102,7 +102,7 @@ def fill_realizations_select
end

def find_example
response = Faraday.get("#{ENV.fetch("ERDBEERE_API", nil)}/find?#{find_params.to_query}")
response = Faraday.get("#{ENV.fetch("ERDBEERE_API")}/find?#{find_params.to_query}")
@content = if response.status == 200
JSON.parse(response.body)["embedded_html"]
else
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/lectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def edit_structures

def search_examples
if @lecture.structure_ids.any?
response = Faraday.get("#{ENV.fetch("ERDBEERE_API", nil)}/search")
response = Faraday.get("#{ENV.fetch("ERDBEERE_API")}/search")
@form = JSON.parse(response.body)["embedded_html"]
# rubocop:disable Style/StringConcatenation
@form.gsub!("token_placeholder",
Expand Down Expand Up @@ -402,7 +402,7 @@ def eager_load_stuff

def set_erdbeere_data
@structure_ids = @lecture.structure_ids
response = Faraday.get("#{ENV.fetch("ERDBEERE_API", nil)}/structures")
response = Faraday.get("#{ENV.fetch("ERDBEERE_API")}/structures")
response_hash = if response.status == 200
JSON.parse(response.body)
else
Expand Down
15 changes: 0 additions & 15 deletions app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,6 @@ def search
results = search.results
@total = search.total

# in the case of a search with tag_operator 'or', we
# execute two searches and merge the results, where media
# with the selected tags are now shown at the front of the list
if (search_params[:tag_operator] == "or") \
&& (search_params[:all_tags] == "0") \
&& (search_params[:fulltext].size >= 2)
params["search"]["all_tags"] = "1"
search_no_tags = Medium.search_by(search_params, params[:page])
search_no_tags.execute
results_no_tags = search_no_tags.results
results = (results + results_no_tags).uniq
@total = results.size
params["search"]["all_tags"] = "0"
end

if filter_media
search_arel = Medium.where(id: results.pluck(:id))
visible_search_results = current_user.filter_visible_media(search_arel)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def verify_captcha
return true unless ENV["USE_CAPTCHA_SERVICE"]

begin
uri = URI.parse(ENV.fetch("CAPTCHA_VERIFY_URL", nil))
uri = URI.parse(ENV.fetch("CAPTCHA_VERIFY_URL"))
data = { message: params["frc-captcha-solution"],
application_token: ENV.fetch("CAPTCHA_APPLICATION_TOKEN", nil) }
application_token: ENV.fetch("CAPTCHA_APPLICATION_TOKEN") }
header = { "Content-Type": "text/json" }
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if ENV["CAPTCHA_VERIFY_URL"].include?("https")
http.use_ssl = true if ENV.fetch("CAPTCHA_VERIFY_URL").include?("https")
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = data.to_json

Expand Down Expand Up @@ -70,9 +70,9 @@ def after_sign_up_path_for(_resource)
private

def check_registration_limit
timeframe = ((ENV["MAMPF_REGISTRATION_TIMEFRAME"] || 15).to_i.minutes.ago..)
timeframe = (ENV.fetch("MAMPF_REGISTRATION_TIMEFRAME", 15).to_i.minutes.ago..)
num_new_registrations = User.where(confirmed_at: nil, created_at: timeframe).count
max_registrations = (ENV["MAMPF_MAX_REGISTRATION_PER_TIMEFRAME"] || 40).to_i
max_registrations = ENV.fetch("MAMPF_MAX_REGISTRATION_PER_TIMEFRAME", 40).to_i
return if num_new_registrations <= max_registrations

# Current number of new registrations is too high
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def current_lecture
def host
if Rails.env.production?
# rubocop:disable Style/StringConcatenation
ENV.fetch("MEDIA_SERVER", nil) + "/" + ENV.fetch("INSTANCE_NAME", nil)
ENV.fetch("MEDIA_SERVER") + "/" + ENV.fetch("INSTANCE_NAME")
# rubocop:enable Style/StringConcatenation
else
""
Expand All @@ -29,7 +29,7 @@ def host
# the actual media server.
# This is used for the download buttons for videos and manuscripts.
def download_host
Rails.env.production? ? ENV.fetch("DOWNLOAD_LOCATION", nil) : ""
Rails.env.production? ? ENV.fetch("DOWNLOAD_LOCATION") : ""
end

# Returns the full title on a per-page basis.
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/exception_handler/exception_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ExceptionMailer < ApplicationMailer

# Defaults
default subject: I18n.t("exception.exception",
host: ENV.fetch("URL_HOST", nil))
host: ENV.fetch("URL_HOST"))
default from: ExceptionHandler.config.email
default template_path: "exception_handler/mailers"
# => http://stackoverflow.com/a/18579046/1143732
Expand Down
16 changes: 5 additions & 11 deletions app/models/medium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ def self.search_by(search_params, _page)
search_params[:all_terms] = "1" if search_params[:all_terms].blank?
search_params[:all_teachers] = "1" if search_params[:all_teachers].blank?
search_params[:term_ids].push("0") if search_params[:term_ids].present?
if search_params[:all_tags] == "1" && search_params[:tag_operator] == "and"
search_params[:tag_ids] = Tag.pluck(:id)
end
user = User.find_by(id: search_params[:user_id])
search = Sunspot.new_search(Medium)
search.build do
Expand Down Expand Up @@ -336,15 +333,12 @@ def self.search_by(search_params, _page)
with(:release_state, search_params[:access])
end
end
if !search_params[:all_tags] == "1" &&
!search_params[:tag_operator] == "or" && (search_params[:tag_ids])
if search_params[:tag_operator] == "or" || search_params[:all_tags] == "1"
search.build do
with(:tag_ids).any_of(search_params[:tag_ids])
end
else
search.build do
if search_params[:all_tags] == "0" && search_params[:tag_ids].any?
search.build do
if search_params[:tag_operator] == "and"
with(:tag_ids).all_of(search_params[:tag_ids])
else
with(:tag_ids).any_of(search_params[:tag_ids])
end
end
end
Expand Down
39 changes: 20 additions & 19 deletions app/models/user_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ class UserCleaner
attr_accessor :imap, :email_dict, :hash_dict

def login
@imap = Net::IMAP.new(ENV.fetch("IMAPSERVER", nil), port: 993, ssl: true)
@imap.authenticate("LOGIN", ENV.fetch("PROJECT_EMAIL_USERNAME", nil),
ENV.fetch("PROJECT_EMAIL_PASSWORD", nil))
@imap = Net::IMAP.new(ENV.fetch("IMAPSERVER"), port: 993, ssl: true)
@imap.authenticate("LOGIN", ENV.fetch("PROJECT_EMAIL_USERNAME"),
ENV.fetch("PROJECT_EMAIL_PASSWORD"))
end

def logout
Expand All @@ -15,7 +15,7 @@ def logout
def search_emails_and_hashes
@email_dict = {}
@hash_dict = {}
@imap.examine(ENV.fetch("PROJECT_EMAIL_MAILBOX", nil))
@imap.examine(ENV.fetch("PROJECT_EMAIL_MAILBOX"))
# Mails containing multiple email addresses (Subject: "Undelivered Mail Returned to Sender")
@imap.search(["SUBJECT",
"Undelivered Mail Returned to Sender"]).each do |message_id|
Expand Down Expand Up @@ -89,11 +89,11 @@ def send_hashes
end

def delete_ghosts
@hash_dict.each do |mail, hash|
u = User.find_by(email: mail, ghost_hash: hash)
move_mail(@email_dict[mail]) if u.present? && @email_dict.present?
u.destroy! if u&.generic?
end
# @hash_dict.each do |mail, hash|
# u = User.find_by(email: mail, ghost_hash: hash)
# move_mail(@email_dict[mail]) if u.present? && @email_dict.present?
# u.destroy! if u&.generic?
# end
end

def move_mail(message_ids, attempt = 0)
Expand All @@ -103,22 +103,23 @@ def move_mail(message_ids, attempt = 0)
return if attempt > 3

begin
@imap.examine(ENV.fetch("PROJECT_EMAIL_MAILBOX", nil))
@imap.examine(ENV.fetch("PROJECT_EMAIL_MAILBOX"))
@imap.move(message_ids, "Other Users/mampf/handled_bounces")
rescue Net::IMAP::BadResponseError
move_mail(message_ids, attempt + 1)
end
end

def clean!
login
search_emails_and_hashes
return if @email_dict.blank?

send_hashes
sleep(10)
search_emails_and_hashes
delete_ghosts
logout
# TODO: Implement new user cleaner logic
# login
# search_emails_and_hashes
# return if @email_dict.blank?

# send_hashes
# sleep(10)
# search_emails_and_hashes
# delete_ghosts
# logout
end
end
6 changes: 3 additions & 3 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
target: :_blank)), class: "d-inline", for: "dsgvo-consent" %>
</div>
<%= f.hidden_field :locale, value: I18n.locale %>
<% if ENV['USE_CAPTCHA_SERVICE']%>
<% if ENV["USE_CAPTCHA_SERVICE"]%>
<p>
<div id="captcha-widget" data-sitekey="YOUR_SITE_KEY" data-start="auto" data-captcha-url="<%=ENV['CAPTCHA_PUZZLE_URL']%>" data-lang="<%=I18n.locale %>"></div>
<div id="captcha-widget" data-sitekey="YOUR_SITE_KEY" data-start="auto" data-captcha-url="<%=ENV.fetch('CAPTCHA_PUZZLE_URL') %>" data-lang="<%=I18n.locale %>"></div>
</p>
<%end %>
<div class="mb-3">
<%= f.submit t('.sign_up'), class: 'btn btn-primary', id: 'register-user', disabled:ENV['USE_CAPTCHA_SERVICE'] %>
<%= f.submit t('.sign_up'), class: 'btn btn-primary', id: 'register-user', disabled:ENV.fetch("USE_CAPTCHA_SERVICE") %>
</div>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/exception_handler/mailers/new_exception.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= t('exception.exception_report',
host: ENV['URL_HOST']) %>
host: ENV.fetch("URL_HOST")) %>
<strong>
<%= @exception.response %> (<%= @exception.status %>)
</strong>
Expand Down
6 changes: 4 additions & 2 deletions app/views/main/start/_media_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
<%= f.radio_button :tag_operator,
'or',
checked: true,
class: 'form-check-input' %>
class: 'form-check-input',
disabled: true %>
<%= f.label :tag_operator,
t('basics.OR'),
value: 'or',
Expand All @@ -71,7 +72,8 @@
<div class="form-check form-check-inline">
<%= f.radio_button :tag_operator,
'and',
class: 'form-check-input' %>
class: 'form-check-input',
disabled: true %>
<%= f.label :tag_operator,
t('basics.AND'),
value: 'and',
Expand Down
6 changes: 4 additions & 2 deletions app/views/media/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
<%= f.radio_button :tag_operator,
'or',
checked: true,
class: 'form-check-input' %>
class: 'form-check-input',
disabled: true %>
<%= f.label :tag_operator,
t('basics.OR'),
value: 'or',
Expand All @@ -114,7 +115,8 @@
<div class="form-check form-check-inline">
<%= f.radio_button :tag_operator,
'and',
class: 'form-check-input' %>
class: 'form-check-input',
disabled: true %>
<%= f.label :tag_operator,
t('basics.AND'),
value: 'and',
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions app/workers/interaction_saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class InteractionSaver
include Sidekiq::Worker

def perform(session_id, full_path, referrer, study_participant)
referrer_url = if referrer.to_s.include?(ENV["URL_HOST"])
referrer.to_s.remove(ENV["URL_HOST"])
referrer_url = if referrer.to_s.include?(ENV.fetch("URL_HOST"))
referrer.to_s.remove(ENV.fetch("URL_HOST"))
.remove("https://").remove("http://")
end
Interaction.create(session_id: Digest::SHA2.hexdigest(session_id).first(10),
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Application < Rails::Application
# the framework and any gems in your application.
config.exception_handler = {
# sends exception emails to a listed email (string // "[email protected]")
email: ENV.fetch("ERROR_EMAIL", nil),
email: ENV.fetch("ERROR_EMAIL"),

# All keys interpolated as strings, so you can use
# symbols, strings or integers where necessary
Expand Down
9 changes: 5 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,24 @@
config.log_tags = [:request_id]

# Use a different cache store in production.
config.cache_store = :mem_cache_store, ENV.fetch("MEMCACHED_SERVER", nil)
config.cache_store = :mem_cache_store, ENV.fetch("MEMCACHED_SERVER")

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "mampf_#{Rails.env}"
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { protocol: "https", host: ENV.fetch("URL_HOST", nil) }
config.action_mailer.default_url_options = { protocol: "https", host: ENV.fetch("URL_HOST") }

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default(charset: "utf-8")

config.action_mailer.smtp_settings = {
address: ENV.fetch("MAILSERVER", nil),
address: ENV.fetch("MAILSERVER"),
port: 25,
domain: ENV.fetch("MAILSERVER", nil)
user_name: ENV.fetch("MAMPF_EMAIL_USERNAME"),
password: ENV.fetch("MAMPF_EMAIL_PASSWORD")
}

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
Loading

0 comments on commit 4952d6e

Please sign in to comment.