Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fix[Op#52098]: Invalidate form validity when direct upload is too large

Kabiru Mwenja43dd5e599492
diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
index 6c64972e775..a9c3718d056 100644
--- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
+++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
@@ -65,6 +65,12 @@ module Bim
end
def set_direct_upload_file_name
+ if params[:filesize].to_i > Setting.attachment_max_size.to_i.kilobytes
+ render json: { error: I18n.t("activerecord.errors.messages.file_too_large", count: Setting.attachment_max_size) },
+ status: :unprocessable_entity
+ return
+ end
+
session[:pending_ifc_model_title] = params[:title]
session[:pending_ifc_model_is_default] = params[:isDefault]
end
diff --git a/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb b/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
index 62d8e3464db..20ee195c383 100644
--- a/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
+++ b/modules/bim/app/views/bim/ifc_models/ifc_models/_form.html.erb
@@ -62,6 +62,10 @@ See COPYRIGHT and LICENSE files for more details.
fileName = fileNameField[0].files[0].name;
}
+ <%# Reset the form validity %>
+ <%# See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity %>
+ fileNameField[0].setCustomValidity('');
+
var titleField = jQuery("#bim_ifc_models_ifc_model_title");
<%# When creating a new model, there is no titleField. %>
@@ -86,12 +90,20 @@ See COPYRIGHT and LICENSE files for more details.
},
data: {
title: title,
- isDefault: jQuery("#bim_ifc_models_ifc_model_is_default").is(":checked") ? 1 : 0
+ isDefault: jQuery("#bim_ifc_models_ifc_model_is_default").is(":checked") ? 1 : 0,
+ filesize: fileNameField[0].files[0].size
},
statusCode: {
401: function(resp, status, error) {
document.location.reload(); // reload to make user login again
}
+ },
+ error: function(jqXHR, ajaxOptions, errorThrown) {
+ if (jqXHR.status == 422) {
+ var errorMessage = jqXHR.responseJSON.error;
+ fileNameField[0].setCustomValidity(errorMessage);
+ fileNameField[0].reportValidity();
+ }
}
});
};