Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update assertion-pdf-validation with master #485

Merged
merged 16 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "bundler" # See documentation for possible values
directory: "/" # Location of package manifests
target-branch: "bugfixes"
schedule:
interval: "weekly"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ This project was initiated by professors Leonardo Murta and Vanessa Braganholo a
* Luis Antônio Vieira Junior (joined in August 2013)
* Daniel Prett (joined in August 2014)
* Carlos Eduardo Cabral da Cunha (joined in August 2016)
* Caio Henrique Velloso Paranhos (joined in March 2024)
* Igor de Paula Siqueira Monárdez (joined in May 2024)

# Additional contributors

Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/custom/admissions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@

.advanced-config-item {
display: none;
}

.reupload-notice {
color: purple;
}
15 changes: 15 additions & 0 deletions app/controllers/admissions/apply_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,25 @@ def update(creating: false)
id: @admission_application.token
), notice: notice
else
# Temporary log to understand the reason of why submission is failing
ExceptionNotifier.notify_exception(
Exception.new("Validação javascript de seleção falhou e form com erro chegou no servidor"),
data: {
params:,
full_messages: @admission_application.errors.full_messages,
errors: @admission_application.errors
}
)
if !was_filled
@admission_application.submission_time = nil
end
@admission_application.filled_form.is_filled = was_filled
prepare_admission_application_fields
@show_reupload_files_notice = @admission_application
.filled_form.form_template.has_file_fields?
if @show_reupload_files_notice
@admission_application.filled_form.erase_non_filled_file_fields
end
render :edit
end
end
Expand Down Expand Up @@ -126,6 +140,7 @@ def prepare_edit_update_application(creating: false)
if !creating
@show_name = false
@show_email = false
@show_reupload_files_notice = false
@submission_url = admission_apply_path(
admission_id: @admission_process.simple_id,
id: @admission_application.token
Expand Down
3 changes: 3 additions & 0 deletions app/mailers/devise_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def headers_for(action, opts)
headers[:body] = render_to_string(
inline: @template.body
) unless @template.body.nil?
headers[:reply_to] = render_to_string(
inline: CustomVariable.reply_to
)
@template.update_mailer_headers(headers)
headers
end
Expand Down
12 changes: 12 additions & 0 deletions app/models/admissions/filled_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,16 @@ def find_cpf_field
end
nil
end

def erase_non_filled_file_fields
self.fields.each do |field|
if field.form_field.is_file_field?
if field.persisted?
field.reload
else
field.file = nil
end
end
end
end
end
9 changes: 9 additions & 0 deletions app/models/admissions/form_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ def get_values_map(option)
result
end

def is_file_field?
return true if self.field_type == FILE
if self.field_type == STUDENT_FIELD
config = self.config_hash
return true if config["field"] == "photo"
end
false
end

def self.search_name(field: nil, substring: false)
field = "%#{field}%" if field.present? && substring
Admissions::FormField.where(
Expand Down
4 changes: 4 additions & 0 deletions app/models/admissions/form_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ def initialize_dup(other)
super
self.fields = other.fields.map(&:dup)
end

def has_file_fields?
fields.any? { |f| f.is_file_field? }
end
end
9 changes: 9 additions & 0 deletions app/models/custom_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
class CustomVariable < ApplicationRecord
has_paper_trail

SAPOS_MAIL = "[email protected]"

VARIABLES = {
"single_advisor_points" => :text,
"multiple_advisor_points" => :text,
"program_level" => :text,
"identity_issuing_country" => :text,
"class_schedule_text" => :text,
"redirect_email" => :text,
"reply_to" => :text,
"notification_footer" => :text,
"minimum_grade_for_approval" => :text,
"grade_of_disapproval_for_absence" => :text,
Expand Down Expand Up @@ -59,6 +62,12 @@ def self.redirect_email
config.blank? ? nil : (config.value || "")
end

def self.reply_to
default = ActionMailer::Base.default[:from]
config = CustomVariable.find_by_variable(:reply_to)
config.blank? ? default : (config.value || default)
end

def self.notification_footer
config = CustomVariable.find_by_variable(:notification_footer)
config.blank? ? "" : config.value
Expand Down
1 change: 1 addition & 0 deletions app/models/email_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def update_mailer_headers(headers)
headers[:to] = CustomVariable.redirect_email
headers[:skip_redirect] = true
end
headers[:reply_to] = CustomVariable.reply_to
headers[:skip_message] = ! self.enabled
headers[:skip_footer] = true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%
@override = false if @override.blank?
if @override
return "Acesso inválido" if !controller.override_authorized?(record)
else
Expand Down Expand Up @@ -63,12 +64,14 @@
<% end %>
</ol>
<input type="hidden" name="can_edit_override" value="<%= 1 if can_edit_override %>"/>
<input type="hidden" name="override" value="<%= 1 if @override %>"/>

<%= fields_for :record, record, multipart: true do |form| %>
<div id="<%= subid %>">
<%= render partial: "admissions/filled_form/candidate_forms", locals: {
subid:,
form: form,
may_show_reupload_notice: true,
admission_process: admission_process,
admission_application: record,
show_name: show_name,
Expand Down
6 changes: 6 additions & 0 deletions app/views/admissions/apply/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@
<%= error.full_message %></li>
<% end %>
</li>
<% if @show_reupload_files_notice %>
<li>
<%= t "admissions.apply.edit.upload_notice" %>
</li>
<% end %>
<% end %>
</ul>
</div>
<% end %>
</div>
<%= render partial: "admissions/filled_form/candidate_forms", locals: {
form: form,
may_show_reupload_notice: false,
admission_process: @admission_process,
admission_application: @admission_application,
show_name: @show_name,
Expand Down
7 changes: 7 additions & 0 deletions app/views/admissions/filled_form/_candidate_forms.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<% if can_edit_main %>
<%= render partial: "admissions/filled_form/edit/form_with_letters", locals: {
form: form,
may_show_reupload_notice:,
admission_process: admission_process,
admission_application: admission_application,
show_name: show_name,
Expand All @@ -27,6 +28,8 @@
<% letter_request.filled_form.sync_fields_before(letter_request) %>
<%= render partial: "admissions/filled_form/show_or_edit_filled_form", locals: {
form: form,
may_show_reupload_notice:,
admission_application:,
name: "Carta de #{letter_request.name}",
id: "#{subid}-letter-#{letter_request.id}",
visible: main_visible,
Expand Down Expand Up @@ -56,6 +59,8 @@
<% app_forms[:phase_forms].each do |phase_form| %>
<%= render partial: "admissions/filled_form/show_or_edit_filled_form", locals: {
form: form,
may_show_reupload_notice:,
admission_application:,
name: "#{phase.name} (#{phase_form[:name]})",
id: "#{phase_subid}-#{phase_form[:name]}",
visible: phase_visible,
Expand All @@ -78,6 +83,8 @@
<% ranking.filled_form.prepare_missing_fields %>
<%= render partial: "admissions/filled_form/show_or_edit_filled_form", locals: {
form: form,
may_show_reupload_notice:,
admission_application:,
name: ranking.ranking_config.name,
id: "ranking-#{ranking.id}",
visible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<% filled_form_hidden.each do |hidden| %>
<%= filled_form.hidden_field hidden %>
<% end %>
<% if may_show_reupload_notice && !admission_application.valid? && object.filled_form.form_template.has_file_fields? %>
<% object.filled_form.erase_non_filled_file_fields %>
<li class="reupload-notice">
<%= t "admissions.apply.edit.upload_notice" %>
</li>
<% end %>
<%= render partial: "admissions/filled_form/edit/filled_form_template", locals: {
form: form,
form_template: object.filled_form.form_template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
options = active_scaffold_input_options(column, scope, :object => field.object)
options[:required] = configuration["required"] ? true : false
basename = options[:name][..-("file".size + 3)]
data_url = field.object.file.file.present? ? download_url(field.object.file.medium_hash) : ""
data_url = ""
if field.object.file.file.present? && field.object.file.file.file.respond_to?(:medium_hash)
data_url = download_url(field.object.file.medium_hash)
end
file_id = "file_#{SecureRandom.random_number(1_000_000)}"
options[:class] = filled_class
%>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<ol class="form filled-form">
<% if may_show_reupload_notice && !admission_application.valid? && admission_application.filled_form.form_template.has_file_fields? %>
<% admission_application.filled_form.erase_non_filled_file_fields %>
<li class="reupload-notice">
<%= t "admissions.apply.edit.upload_notice" %>
</li>
<% end %>
<% if show_name %>
<li class="form-element required">
<dl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
configuration: configuration,
values: form_field.get_values("values"),
statuses: form_field.get_values("statuses"),
filled_class: filled_class
filled_class: filled_class,
run_js: false
}
%>
<div id="<%= sid %>-links" class="<%= filled_class %>-link">
<div id="<%= sid %>">
<%= field.fields_for :scholarities do |scholarity| %>
<%= render partial: "admissions/filled_form/edit/scholarity_item",
locals: local_options.merge({ f: scholarity }) %>
locals: local_options.merge({ f: scholarity, run_js: true }) %>
<% end %>
</div>
<div class="links">
Expand All @@ -28,12 +29,26 @@
<script>
$(`#<%= sid %> > input[type=hidden]`).addClass("<%= filled_class %>");
$(document).ready(function() {
let scholarity_stack = [];
let check_disabled = function(event) {
if ($("#<%= sid %>-links").hasClass("disabled-links")) {
event.preventDefault();
return false;
}
return true;
};
$("#<%= sid %>-links").on("cocoon:before-insert", check_disabled);
$("#<%= sid %>-links").on("cocoon:before-insert", function(event, inserted_item, original_event) {
if (check_disabled(event)) {
let random_number = parseInt(Math.random() * 1000000);
let new_id = `scholarity-item-${random_number}`;
inserted_item.closest('.scholarity').attr("id", new_id);
scholarity_stack.push(new_id);
}
});
$("#<%= sid %>-links").on("cocoon:after-insert", function() {
let new_id = scholarity_stack.pop();
scholarity_item_activate_js(new_id);
});
$("#<%= sid %>-links").on("cocoon:before-remove", check_disabled);
})
</script>
Loading
Loading